Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created June 18, 2015 04:03
Show Gist options
  • Save amonshiz/d42de8a6cf08e1394a60 to your computer and use it in GitHub Desktop.
Save amonshiz/d42de8a6cf08e1394a60 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
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 ">"
import qualified Bioinformatics.DNANucleotide as D
import qualified Bioinformatics.RNANucleotide as R
import qualified Bioinformatics.Utilities as U
import qualified Bioinformatics.Protein as P
import qualified Bioinformatics.FASTA as F
import Data.List.Split (splitOn)
getLines :: String -> IO String
getLines contents = do
line <- getLine
if null line
then return contents
else getLines $ contents ++ line ++ "\n"
getRNA :: String -> [R.RNANucleotide]
getRNA = map (U.dnaToRNA . D.charToDNANucleotide)
getProtein :: String -> P.Protein
getProtein = P.rnaToAminoAcids . getRNA
removeSubstrings :: String -> [String] -> String
removeSubstrings s xs = foldr (\x a -> concat $ splitOn x a) s xs
generateCodingRegion :: String -> [String] -> P.Protein
generateCodingRegion dna introns = init . getProtein $ removeSubstrings dna introns
main :: IO ()
main = do
input <- getLines ""
let fastas = tail $ F.buildFASTALinesWith id input
contents = map F.content fastas
dna = head contents
introns = tail contents
putStrLn . concatMap show $ generateCodingRegion dna introns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment