Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created March 22, 2015 15:13
Show Gist options
  • Save amonshiz/18a142a4c023d842a38f to your computer and use it in GitHub Desktop.
Save amonshiz/18a142a4c023d842a38f to your computer and use it in GitHub Desktop.
module Bioinformatics.FASTA (
FASTAFormatLine(..),
buildFASTALines,
buildFASTALinesWith
) where
import qualified Bioinformatics.DNANucleotide as D
import qualified Data.List.Split as S
-- type FASTAFormatLine = (String, [D.DNANucleotide])
data FASTAFormatLine a = FASTAFormatLine { name :: String,
content :: [a]
} deriving (Show)
stringToFASTAFormat :: String -> FASTAFormatLine D.DNANucleotide
stringToFASTAFormat [] = FASTAFormatLine { name = "", content = [] }
stringToFASTAFormat xs =
let comps = lines xs
in FASTAFormatLine { name = head comps, content = map D.charToDNANucleotide . concat $ tail comps }
buildFASTALines :: String -> [FASTAFormatLine D.DNANucleotide]
buildFASTALines = map stringToFASTAFormat . S.splitOn ">"
stringToFASTAFormatWith :: (Char -> a) -> String -> FASTAFormatLine a
stringToFASTAFormatWith _ [] = FASTAFormatLine {name = "", content = [] }
stringToFASTAFormatWith with xs =
let comps = lines xs
in FASTAFormatLine { name = head comps, content = map with . concat $ tail comps }
buildFASTALinesWith :: (Char -> a) -> String -> [FASTAFormatLine a]
buildFASTALinesWith with = map (stringToFASTAFormatWith with) . S.splitOn ">"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment