Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created January 29, 2014 13:28
Show Gist options
  • Save snoyberg/8687941 to your computer and use it in GitHub Desktop.
Save snoyberg/8687941 to your computer and use it in GitHub Desktop.
import Data.List
import System.Environment (getArgs)
import Data.Maybe (fromMaybe)
import qualified Data.Judy as J
import qualified Data.ByteString as S
import Data.ByteString (ByteString)
import Control.Exception (evaluate)
import Data.Word
toWord = S.foldl' (\accum w -> accum * 4 + go w) 0
where
go 65 = 0
go 67 = 1
go 71 = 2
go 84 = 3
update_freqM freq_delta j elem =
do old <- J.lookup elem j
J.insert elem ((fromMaybe (0::Int) old) + freq_delta) j
addTimesM freq_delta j l = mapM_ (update_freqM freq_delta j) l
timesM l = do j <- J.new
addTimesM (1::Int) j l
return j
kmers k l = map toWord . filter ((== k) . S.length) . map (S.take k) . S.tails $ l
main :: IO ()
main = do
text <- S.getLine
_l <- timesM . kmers 9 $ text
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment