Skip to content

Instantly share code, notes, and snippets.

@michaelbarton
Created July 29, 2014 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaelbarton/67830e95bcd6002c648f to your computer and use it in GitHub Desktop.
Save michaelbarton/67830e95bcd6002c648f to your computer and use it in GitHub Desktop.
import System.Environment
import Data.List.Split
import Data.List
import qualified Data.Map.Strict as Map
main = do
[f] <- getArgs
contents <- readFile f
putStr . unlines . map unwords . map (kmers 6) . getSequences $ contents
getSequences :: String -> [String]
getSequences = map (\x -> x !! 1) . splitEvery 4 . lines
kmers :: Int -> String -> [String]
kmers k seq = (unfoldr f seq) ++ (unfoldr f $ map revcomp $ seq)
where
f xs
| length xs >= k = Just ((take k xs), (tail xs))
| otherwise = Nothing
revcomp 'A' = 'T'
revcomp 'T' = 'A'
revcomp 'G' = 'C'
revcomp 'C' = 'G'
revcomp _ = 'N'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment