Created
June 2, 2015 04:28
-
-
Save amonshiz/a0cb14ab61ac1b9880c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Bioinformatics.DNANucleotide as D | |
import qualified Bioinformatics.FASTA as F | |
import qualified Data.List as L | |
getLines contents = do | |
line <- getLine | |
if null line | |
then return contents | |
else getLines $ contents ++ line ++ "\n" | |
convertToProfile :: [[D.DNANucleotide]] -> String | |
convertToProfile dnaStrings = | |
unlines $ map buildString [D.A, D.C, D.G, D.T] | |
where columns = L.transpose dnaStrings | |
lengths nucleotide = map (length . filter (== nucleotide)) | |
buildString n = show n ++ ": " ++ (unwords . map show $ lengths n columns) | |
determineConcensus :: [[D.DNANucleotide]] -> String | |
determineConcensus = | |
concat . map show . mostCommon . L.transpose | |
where mostCommon = map (head . L.maximumBy (\a1 a2 -> length a1 `compare` length a2) . L.group . L.sort) | |
main = do | |
lines <- getLines "" | |
let fastas = F.buildFASTALines lines | |
let dnaStrings = tail $ map F.content fastas | |
putStrLn $ determineConcensus dnaStrings | |
putStrLn $ convertToProfile dnaStrings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment