- import Text.Regex(subRegex, mkRegex)
- import Text.Regex.Posix
- -- convert the motif into a proper regex string
- motifToRegex :: String -> String
- motifToRegex motif = subRegex (mkRegex "\\{([A-Z])\\}") motif "[^\\1]"
- -- search for a motify (as a regex string) in the sequence and return all matches
- -- as a list of strings
- searchMotif :: String -> String -> [[String]]
- searchMotif motif sequence = sequence =~ (motifToRegex motif) :: [[String]]
- main = do
- putStrLn("Enter a motif: ")
- motif <- getLine
- putStrLn("Enter a sequence to search: ")
- sequence <- getLine
- putStrLn("Converted motif: " ++ motifToRegex motif)
- putStrLn("Results: ")
- print(searchMotif motif sequence)