From Ample Goose, 6 Years ago, written in Plain Text.
Embed
  1. import Text.Regex(subRegex, mkRegex)
  2. import Text.Regex.Posix
  3.  
  4. -- convert the motif into a proper regex string
  5. motifToRegex :: String -> String
  6. motifToRegex motif = subRegex (mkRegex "\\{([A-Z])\\}") motif "[^\\1]"
  7.  
  8. -- search for a motify (as a regex string) in the sequence and return all matches
  9. -- as a list of strings
  10. searchMotif :: String -> String -> [[String]]
  11. searchMotif motif sequence = sequence =~ (motifToRegex motif) :: [[String]]
  12.  
  13. main = do
  14.     putStrLn("Enter a motif: ")
  15.     motif <- getLine
  16.     putStrLn("Enter a sequence to search: ")
  17.     sequence <- getLine
  18.     putStrLn("Converted motif: " ++ motifToRegex motif)
  19.     putStrLn("Results: ")
  20.     print(searchMotif motif sequence)