cobot-io 0.1.3.13 → 0.1.3.14
raw patch · 8 files changed
+372/−41 lines, 8 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Bio.FASTA: class WritableFastaToken a
+ Bio.FASTA: tokenToString :: WritableFastaToken a => a -> String
+ Bio.FASTA.Parser: instance Bio.FASTA.Type.ParsableFastaToken Bio.FASTA.Type.ModItem
+ Bio.FASTA.Parser: instance Bio.FASTA.Type.ParsableFastaToken GHC.Types.Char
+ Bio.FASTA.Type: Letter :: Char -> ModItem
+ Bio.FASTA.Type: Mod :: Modification -> ModItem
+ Bio.FASTA.Type: Mod_36FAM :: Modification
+ Bio.FASTA.Type: Mod_3BHQ1 :: Modification
+ Bio.FASTA.Type: Mod_3BHQ2 :: Modification
+ Bio.FASTA.Type: Mod_3BioTEG :: Modification
+ Bio.FASTA.Type: Mod_3CholTEG :: Modification
+ Bio.FASTA.Type: Mod_3NH2 :: Modification
+ Bio.FASTA.Type: Mod_3PO4 :: Modification
+ Bio.FASTA.Type: Mod_3alkine :: Modification
+ Bio.FASTA.Type: Mod_3azide :: Modification
+ Bio.FASTA.Type: Mod_3thio :: Modification
+ Bio.FASTA.Type: Mod_56FAM :: Modification
+ Bio.FASTA.Type: Mod_5Alk :: Modification
+ Bio.FASTA.Type: Mod_5Bio :: Modification
+ Bio.FASTA.Type: Mod_5C10 :: Modification
+ Bio.FASTA.Type: Mod_5CholTEG :: Modification
+ Bio.FASTA.Type: Mod_5HEX :: Modification
+ Bio.FASTA.Type: Mod_5Mal :: Modification
+ Bio.FASTA.Type: Mod_5NH2 :: Modification
+ Bio.FASTA.Type: Mod_5PO4 :: Modification
+ Bio.FASTA.Type: Mod_5TMR :: Modification
+ Bio.FASTA.Type: Mod_5thio :: Modification
+ Bio.FASTA.Type: Mod_AA :: Modification
+ Bio.FASTA.Type: Mod_AAA :: Modification
+ Bio.FASTA.Type: Mod_AAC :: Modification
+ Bio.FASTA.Type: Mod_AC :: Modification
+ Bio.FASTA.Type: Mod_ACT :: Modification
+ Bio.FASTA.Type: Mod_AG :: Modification
+ Bio.FASTA.Type: Mod_AGA :: Modification
+ Bio.FASTA.Type: Mod_AT :: Modification
+ Bio.FASTA.Type: Mod_ATC :: Modification
+ Bio.FASTA.Type: Mod_ATG :: Modification
+ Bio.FASTA.Type: Mod_A_Star :: Modification
+ Bio.FASTA.Type: Mod_C12 :: Modification
+ Bio.FASTA.Type: Mod_CA :: Modification
+ Bio.FASTA.Type: Mod_CAG :: Modification
+ Bio.FASTA.Type: Mod_CAT :: Modification
+ Bio.FASTA.Type: Mod_CC :: Modification
+ Bio.FASTA.Type: Mod_CCG :: Modification
+ Bio.FASTA.Type: Mod_CG :: Modification
+ Bio.FASTA.Type: Mod_CGT :: Modification
+ Bio.FASTA.Type: Mod_CT :: Modification
+ Bio.FASTA.Type: Mod_CTG :: Modification
+ Bio.FASTA.Type: Mod_C_Star :: Modification
+ Bio.FASTA.Type: Mod_GA :: Modification
+ Bio.FASTA.Type: Mod_GAA :: Modification
+ Bio.FASTA.Type: Mod_GAC :: Modification
+ Bio.FASTA.Type: Mod_GC :: Modification
+ Bio.FASTA.Type: Mod_GCT :: Modification
+ Bio.FASTA.Type: Mod_GG :: Modification
+ Bio.FASTA.Type: Mod_GGT :: Modification
+ Bio.FASTA.Type: Mod_GT :: Modification
+ Bio.FASTA.Type: Mod_GTT :: Modification
+ Bio.FASTA.Type: Mod_G_Star :: Modification
+ Bio.FASTA.Type: Mod_NHSdT :: Modification
+ Bio.FASTA.Type: Mod_Plus_A :: Modification
+ Bio.FASTA.Type: Mod_Plus_C :: Modification
+ Bio.FASTA.Type: Mod_Plus_G :: Modification
+ Bio.FASTA.Type: Mod_Plus_T :: Modification
+ Bio.FASTA.Type: Mod_TA :: Modification
+ Bio.FASTA.Type: Mod_TAC :: Modification
+ Bio.FASTA.Type: Mod_TC :: Modification
+ Bio.FASTA.Type: Mod_TCT :: Modification
+ Bio.FASTA.Type: Mod_TG :: Modification
+ Bio.FASTA.Type: Mod_TGC :: Modification
+ Bio.FASTA.Type: Mod_TGG :: Modification
+ Bio.FASTA.Type: Mod_TT :: Modification
+ Bio.FASTA.Type: Mod_TTC :: Modification
+ Bio.FASTA.Type: Mod_TTT :: Modification
+ Bio.FASTA.Type: Mod_T_Star :: Modification
+ Bio.FASTA.Type: Mod_dU :: Modification
+ Bio.FASTA.Type: Mod_iBio :: Modification
+ Bio.FASTA.Type: Mod_mA :: Modification
+ Bio.FASTA.Type: Mod_mA_Star :: Modification
+ Bio.FASTA.Type: Mod_mC :: Modification
+ Bio.FASTA.Type: Mod_mC_Star :: Modification
+ Bio.FASTA.Type: Mod_mG :: Modification
+ Bio.FASTA.Type: Mod_mG_Star :: Modification
+ Bio.FASTA.Type: Mod_mU :: Modification
+ Bio.FASTA.Type: Mod_mU_Star :: Modification
+ Bio.FASTA.Type: Mod_rA :: Modification
+ Bio.FASTA.Type: Mod_rAf :: Modification
+ Bio.FASTA.Type: Mod_rC :: Modification
+ Bio.FASTA.Type: Mod_rCf :: Modification
+ Bio.FASTA.Type: Mod_rG :: Modification
+ Bio.FASTA.Type: Mod_rGf :: Modification
+ Bio.FASTA.Type: Mod_rU :: Modification
+ Bio.FASTA.Type: Mod_rUf :: Modification
+ Bio.FASTA.Type: Unknown :: String -> Modification
+ Bio.FASTA.Type: class ParsableFastaToken a
+ Bio.FASTA.Type: data ModItem
+ Bio.FASTA.Type: data Modification
+ Bio.FASTA.Type: instance GHC.Classes.Eq Bio.FASTA.Type.ModItem
+ Bio.FASTA.Type: instance GHC.Classes.Eq Bio.FASTA.Type.Modification
+ Bio.FASTA.Type: instance GHC.Show.Show Bio.FASTA.Type.ModItem
+ Bio.FASTA.Type: instance GHC.Show.Show Bio.FASTA.Type.Modification
+ Bio.FASTA.Type: modificationToString :: Modification -> String
+ Bio.FASTA.Type: parseToken :: ParsableFastaToken a => (Char -> Bool) -> Parser a
+ Bio.FASTA.Writer: class WritableFastaToken a
+ Bio.FASTA.Writer: instance Bio.FASTA.Writer.WritableFastaToken Bio.FASTA.Type.ModItem
+ Bio.FASTA.Writer: instance Bio.FASTA.Writer.WritableFastaToken GHC.Types.Char
+ Bio.FASTA.Writer: tokenToString :: WritableFastaToken a => a -> String
- Bio.FASTA: fastaP :: Parser (Fasta Char)
+ Bio.FASTA: fastaP :: ParsableFastaToken a => Parser (Fasta a)
- Bio.FASTA: fastaPGeneric :: (Char -> Bool) -> Parser (Fasta Char)
+ Bio.FASTA: fastaPGeneric :: ParsableFastaToken a => (Char -> Bool) -> Parser (Fasta a)
- Bio.FASTA.Parser: fastaP :: Parser (Fasta Char)
+ Bio.FASTA.Parser: fastaP :: ParsableFastaToken a => Parser (Fasta a)
- Bio.FASTA.Parser: fastaPGeneric :: (Char -> Bool) -> Parser (Fasta Char)
+ Bio.FASTA.Parser: fastaPGeneric :: ParsableFastaToken a => (Char -> Bool) -> Parser (Fasta a)
- Bio.FASTA.Writer: fastaToText :: Fasta Char -> Text
+ Bio.FASTA.Writer: fastaToText :: WritableFastaToken a => Fasta a -> Text
Files
- ChangeLog.md +4/−0
- cobot-io.cabal +2/−2
- src/Bio/FASTA.hs +11/−9
- src/Bio/FASTA/Parser.hs +118/−9
- src/Bio/FASTA/Type.hs +203/−5
- src/Bio/FASTA/Writer.hs +23/−12
- test/FastaParserSpec.hs +10/−3
- test/FastaWriterSpec.hs +1/−1
ChangeLog.md view
@@ -2,6 +2,10 @@ ## [Unreleased] +## [0.1.3.14] - 2021-02-10+### Changed+- Added ability to parse modifications in Fasta.+ ## [0.1.3.13] - 2021-01-02 ### Changed - Allow `QuickCheck-2.14`.
cobot-io.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 9dde2f0490e3c7f6e31e47e18e9de44a3d87d607b09a62b6d723471fffc2f0a5+-- hash: b4805dfc259e39022dd3313837d29888036016ead10be1b3b52215e16a76f7a7 name: cobot-io-version: 0.1.3.13+version: 0.1.3.14 synopsis: Biological data file formats and IO description: Please see the README on GitHub at <https://github.com/biocad/cobot-io#readme> category: Bio
src/Bio/FASTA.hs view
@@ -2,24 +2,26 @@ module Bio.FASTA ( module T+ , WritableFastaToken (..) , fromFile , toFile , fastaP , fastaPGeneric ) where -import Bio.FASTA.Parser-import Bio.FASTA.Type as T-import Bio.FASTA.Writer (fastaToText)-import Control.Monad.IO.Class (MonadIO, liftIO)-import Data.Attoparsec.Text (parseOnly)-import Data.Text.IO (readFile, writeFile)+import Control.Monad.IO.Class (MonadIO, liftIO)+import Data.Attoparsec.Text (parseOnly)+import Data.Text.IO (readFile, writeFile) #if !MIN_VERSION_base(4,13,0)-import Control.Monad.Fail (MonadFail (..))-import Prelude hiding (fail, readFile, writeFile)+import Control.Monad.Fail (MonadFail (..))+import Prelude hiding (fail, readFile, writeFile) #else-import Prelude hiding (readFile, writeFile)+import Prelude hiding (readFile, writeFile) #endif++import Bio.FASTA.Parser+import Bio.FASTA.Type as T+import Bio.FASTA.Writer (WritableFastaToken (..), fastaToText) -- | Reads 'FastaSequence' from given file. --
src/Bio/FASTA/Parser.hs view
@@ -1,35 +1,46 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+ module Bio.FASTA.Parser ( fastaP , fastaPGeneric ) where -import Bio.FASTA.Type (Fasta, FastaItem (..))+import Bio.FASTA.Type (Fasta, FastaItem (..), ModItem (..), Modification (..),+ ParsableFastaToken (..)) import Bio.Sequence (BareSequence, bareSequence)+import Control.Applicative ((<|>)) import Data.Attoparsec.Text (Parser, char, choice, endOfInput, endOfLine, many', many1', satisfy,- skipWhile, takeWhile)-import Data.Char (isLetter, isSpace)+ skipWhile, string, takeWhile, try)+import Data.Char (isAlphaNum, isLetter, isSpace) import Data.Text (Text, strip) import Prelude hiding (takeWhile) +instance ParsableFastaToken Char where+ parseToken = satisfy++instance ParsableFastaToken ModItem where+ parseToken predicate = (Mod <$> modificationP) <|> (Letter <$> satisfy predicate)++ -- | Parser of .fasta file. ---fastaP :: Parser (Fasta Char)+fastaP :: ParsableFastaToken a => Parser (Fasta a) fastaP = fastaPGeneric isLetter -fastaPGeneric :: (Char -> Bool) -> Parser (Fasta Char)+fastaPGeneric :: ParsableFastaToken a => (Char -> Bool) -> Parser (Fasta a) fastaPGeneric = many' . item -item :: (Char -> Bool) -> Parser (FastaItem Char)+item :: ParsableFastaToken a => (Char -> Bool) -> Parser (FastaItem a) item predicate = (FastaItem <$> seqName <*> fastaSeq predicate) <* skipWhile isSpace seqName :: Parser Text seqName = strip <$> (char '>' *> tabs *> takeWhile (`notElem` ['\n', '\r']) <* tabs <* eol) -fastaSeq :: (Char -> Bool) -> Parser (BareSequence Char)+fastaSeq :: ParsableFastaToken a => (Char -> Bool) -> Parser (BareSequence a) fastaSeq predicate = bareSequence . mconcat <$> many' (line predicate) -line :: (Char -> Bool) -> Parser String-line predicate = concat <$> many1' (many1' (satisfy predicate) <* many' (char ' ')) <* eol+line :: ParsableFastaToken a => (Char -> Bool) -> Parser [a]+line predicate = concat <$> many1' (many1' (parseToken predicate) <* many' (char ' ')) <* eol eol :: Parser () eol = tabs *> choice [slashN, endOfInput]@@ -39,3 +50,101 @@ tabs :: Parser () tabs = () <$ many' (char '\t')++modificationP :: Parser Modification+modificationP + = string "[A*]" *> pure Mod_A_Star+ <|> string "[C*]" *> pure Mod_C_Star+ <|> string "[G*]" *> pure Mod_G_Star+ <|> string "[T*]" *> pure Mod_T_Star+ <|> string "[rA]" *> pure Mod_rA+ <|> string "[rC]" *> pure Mod_rC+ <|> string "[rG]" *> pure Mod_rG+ <|> string "[rU]" *> pure Mod_rU+ <|> string "[+A]" *> pure Mod_Plus_A+ <|> string "[+C]" *> pure Mod_Plus_C+ <|> string "[+G]" *> pure Mod_Plus_G+ <|> string "[+T]" *> pure Mod_Plus_T+ <|> string "[rAf]" *> pure Mod_rAf+ <|> string "[rCf]" *> pure Mod_rCf+ <|> string "[rGf]" *> pure Mod_rGf+ <|> string "[rUf]" *> pure Mod_rUf+ <|> string "[mA]" *> pure Mod_mA+ <|> string "[mC]" *> pure Mod_mC+ <|> string "[mG]" *> pure Mod_mG+ <|> string "[mU]" *> pure Mod_mU+ <|> string "[mA*]" *> pure Mod_mA_Star+ <|> string "[mC*]" *> pure Mod_mC_Star+ <|> string "[mG*]" *> pure Mod_mG_Star+ <|> string "[mU*]" *> pure Mod_mU_Star+ <|> string "[dU]" *> pure Mod_dU+ <|> string "[5Bio]" *> pure Mod_5Bio+ <|> string "[iBio]" *> pure Mod_iBio+ <|> string "[56FAM]" *> pure Mod_56FAM+ <|> string "[36FAM]" *> pure Mod_36FAM+ <|> string "[5HEX]" *> pure Mod_5HEX+ <|> string "[5TMR]" *> pure Mod_5TMR+ <|> string "[3BHQ1]" *> pure Mod_3BHQ1+ <|> string "[3BHQ2]" *> pure Mod_3BHQ2+ <|> string "[5NH2]" *> pure Mod_5NH2+ <|> string "[3NH2]" *> pure Mod_3NH2+ <|> string "[5PO4]" *> pure Mod_5PO4+ <|> string "[3PO4]" *> pure Mod_3PO4+ <|> string "[3BioTEG]" *> pure Mod_3BioTEG+ <|> string "[C12]" *> pure Mod_C12+ <|> string "[NHSdT]" *> pure Mod_NHSdT+ <|> string "[5Mal]" *> pure Mod_5Mal+ <|> string "[5thio]" *> pure Mod_5thio+ <|> string "[3thio]" *> pure Mod_3thio+ <|> string "[3azide]" *> pure Mod_3azide+ <|> string "[3alkine]" *> pure Mod_3alkine+ <|> string "[5CholTEG]" *> pure Mod_5CholTEG+ <|> string "[3CholTEG]" *> pure Mod_3CholTEG+ <|> string "[5C10]" *> pure Mod_5C10+ <|> string "[5Alk]" *> pure Mod_5Alk+ <|> string "[GC]" *> pure Mod_GC+ <|> string "[GT]" *> pure Mod_GT+ <|> string "[AT]" *> pure Mod_AT+ <|> string "[TG]" *> pure Mod_TG+ <|> string "[AC]" *> pure Mod_AC+ <|> string "[CC]" *> pure Mod_CC+ <|> string "[AA]" *> pure Mod_AA+ <|> string "[TC]" *> pure Mod_TC+ <|> string "[TT]" *> pure Mod_TT+ <|> string "[CG]" *> pure Mod_CG+ <|> string "[GG]" *> pure Mod_GG+ <|> string "[AG]" *> pure Mod_AG+ <|> string "[GA]" *> pure Mod_GA+ <|> string "[CA]" *> pure Mod_CA+ <|> string "[CT]" *> pure Mod_CT+ <|> string "[TA]" *> pure Mod_TA+ <|> string "[AAA]" *> pure Mod_AAA+ <|> string "[AAC]" *> pure Mod_AAC+ <|> string "[ACT]" *> pure Mod_ACT+ <|> string "[ATC]" *> pure Mod_ATC+ <|> string "[ATG]" *> pure Mod_ATG+ <|> string "[CAG]" *> pure Mod_CAG+ <|> string "[AGA]" *> pure Mod_AGA+ <|> string "[CAT]" *> pure Mod_CAT+ <|> string "[CCG]" *> pure Mod_CCG+ <|> string "[CGT]" *> pure Mod_CGT+ <|> string "[CTG]" *> pure Mod_CTG+ <|> string "[GAA]" *> pure Mod_GAA+ <|> string "[GAC]" *> pure Mod_GAC+ <|> string "[GCT]" *> pure Mod_GCT+ <|> string "[GGT]" *> pure Mod_GGT+ <|> string "[GTT]" *> pure Mod_GTT+ <|> string "[TAC]" *> pure Mod_TAC+ <|> string "[TCT]" *> pure Mod_TCT+ <|> string "[TGC]" *> pure Mod_TGC+ <|> string "[TGG]" *> pure Mod_TGG+ <|> string "[TTC]" *> pure Mod_TTC+ <|> string "[TTT]" *> pure Mod_TTT+ <|> unknownP++unknownP :: Parser Modification+unknownP = try $ do+ _ <- char '[' + m <- many1' $ satisfy (\c -> isAlphaNum c || c `elem` ['+', '-', '*', '_'])+ _ <- char ']'+ pure $ Unknown ("[" <> m <> "]")
src/Bio/FASTA/Type.hs view
@@ -1,10 +1,15 @@ module Bio.FASTA.Type ( Fasta , FastaItem (..)+ , ParsableFastaToken (..)+ , Modification (..)+ , ModItem (..)+ , modificationToString ) where -import Bio.Sequence (BareSequence)-import Data.Text (Text)+import Bio.Sequence (BareSequence)+import Data.Attoparsec.Text (Parser)+import Data.Text (Text) -- | Type alias for FASTA file. -- satisfies the following format : >(\s|\t)*[^\n\r]+(\s|\t)*(\n|\r)*((\w|\s)(\n|\r)*)*@@ -14,7 +19,200 @@ -- | One record in FASTA file. -- data FastaItem a- = FastaItem { name :: Text -- ^ name of the sequence- , sequ :: BareSequence a -- ^ bare sequence- }+ = FastaItem+ { name :: Text+ -- ^ name of the sequence+ , sequ :: BareSequence a+ -- ^ bare sequence+ } deriving (Eq, Show, Functor)++class ParsableFastaToken a where+ parseToken :: (Char -> Bool) -> Parser a++data ModItem+ = Mod Modification+ | Letter Char+ deriving (Eq, Show)++data Modification+ = Mod_A_Star+ | Mod_C_Star+ | Mod_G_Star+ | Mod_T_Star+ | Mod_rA+ | Mod_rC+ | Mod_rG+ | Mod_rU+ | Mod_Plus_A+ | Mod_Plus_C+ | Mod_Plus_G+ | Mod_Plus_T+ | Mod_rAf+ | Mod_rCf+ | Mod_rGf+ | Mod_rUf+ | Mod_mA+ | Mod_mC+ | Mod_mG+ | Mod_mU+ | Mod_mA_Star+ | Mod_mC_Star+ | Mod_mG_Star+ | Mod_mU_Star+ | Mod_dU+ | Mod_5Bio+ | Mod_iBio+ | Mod_56FAM+ | Mod_36FAM+ | Mod_5HEX+ | Mod_5TMR+ | Mod_3BHQ1+ | Mod_3BHQ2+ | Mod_5NH2+ | Mod_3NH2+ | Mod_5PO4+ | Mod_3PO4+ | Mod_3BioTEG+ | Mod_C12+ | Mod_NHSdT+ | Mod_5Mal+ | Mod_5thio+ | Mod_3thio+ | Mod_3azide+ | Mod_3alkine+ | Mod_5CholTEG+ | Mod_3CholTEG+ | Mod_5C10+ | Mod_5Alk+ | Mod_GC+ | Mod_GT+ | Mod_AT+ | Mod_TG+ | Mod_AC+ | Mod_CC+ | Mod_AA+ | Mod_TC+ | Mod_TT+ | Mod_CG+ | Mod_GG+ | Mod_AG+ | Mod_GA+ | Mod_CA+ | Mod_CT+ | Mod_TA+ | Mod_AAA+ | Mod_AAC+ | Mod_ACT+ | Mod_ATC+ | Mod_ATG+ | Mod_CAG+ | Mod_AGA+ | Mod_CAT+ | Mod_CCG+ | Mod_CGT+ | Mod_CTG+ | Mod_GAA+ | Mod_GAC+ | Mod_GCT+ | Mod_GGT+ | Mod_GTT+ | Mod_TAC+ | Mod_TCT+ | Mod_TGC+ | Mod_TGG+ | Mod_TTC+ | Mod_TTT+ | Unknown String+ deriving (Eq, Show)++modificationToString :: Modification -> String+modificationToString Mod_A_Star = "[A*]"+modificationToString Mod_C_Star = "[C*]"+modificationToString Mod_G_Star = "[G*]"+modificationToString Mod_T_Star = "[T*]"+modificationToString Mod_rA = "[rA]"+modificationToString Mod_rC = "[rC]"+modificationToString Mod_rG = "[rG]"+modificationToString Mod_rU = "[rU]"+modificationToString Mod_Plus_A = "[+A]"+modificationToString Mod_Plus_C = "[+C]"+modificationToString Mod_Plus_G = "[+G]"+modificationToString Mod_Plus_T = "[+T]"+modificationToString Mod_rAf = "[rAf]"+modificationToString Mod_rCf = "[rCf]"+modificationToString Mod_rGf = "[rGf]"+modificationToString Mod_rUf = "[rUf]"+modificationToString Mod_mA = "[mA]"+modificationToString Mod_mC = "[mC]"+modificationToString Mod_mG = "[mG]"+modificationToString Mod_mU = "[mU]"+modificationToString Mod_mA_Star = "[mA*]"+modificationToString Mod_mC_Star = "[mC*]"+modificationToString Mod_mG_Star = "[mG*]"+modificationToString Mod_mU_Star = "[mU*]"+modificationToString Mod_dU = "[dU]"+modificationToString Mod_5Bio = "[5Bio]"+modificationToString Mod_iBio = "[iBio]"+modificationToString Mod_56FAM = "[56FAM]"+modificationToString Mod_36FAM = "[36FAM]"+modificationToString Mod_5HEX = "[5HEX]"+modificationToString Mod_5TMR = "[5TMR]"+modificationToString Mod_3BHQ1 = "[3BHQ1]"+modificationToString Mod_3BHQ2 = "[3BHQ2]"+modificationToString Mod_5NH2 = "[5NH2]"+modificationToString Mod_3NH2 = "[3NH2]"+modificationToString Mod_5PO4 = "[5PO4]"+modificationToString Mod_3PO4 = "[3PO4]"+modificationToString Mod_3BioTEG = "[3BioTEG]"+modificationToString Mod_C12 = "[C12]"+modificationToString Mod_NHSdT = "[NHSdT]"+modificationToString Mod_5Mal = "[5Mal]"+modificationToString Mod_5thio = "[5thio]"+modificationToString Mod_3thio = "[3thio]"+modificationToString Mod_3azide = "[3azide]"+modificationToString Mod_3alkine = "[3alkine]"+modificationToString Mod_5CholTEG = "[5CholTEG]"+modificationToString Mod_3CholTEG = "[3CholTEG]"+modificationToString Mod_5C10 = "[5C10]"+modificationToString Mod_5Alk = "[5Alk]"+modificationToString Mod_GC = "[GC]"+modificationToString Mod_GT = "[GT]"+modificationToString Mod_AT = "[AT]"+modificationToString Mod_TG = "[TG]"+modificationToString Mod_AC = "[AC]"+modificationToString Mod_CC = "[CC]"+modificationToString Mod_AA = "[AA]"+modificationToString Mod_TC = "[TC]"+modificationToString Mod_TT = "[TT]"+modificationToString Mod_CG = "[CG]"+modificationToString Mod_GG = "[GG]"+modificationToString Mod_AG = "[AG]"+modificationToString Mod_GA = "[GA]"+modificationToString Mod_CA = "[CA]"+modificationToString Mod_CT = "[CT]"+modificationToString Mod_TA = "[TA]"+modificationToString Mod_AAA = "[AAA]"+modificationToString Mod_AAC = "[AAC]"+modificationToString Mod_ACT = "[ACT]"+modificationToString Mod_ATC = "[ATC]"+modificationToString Mod_ATG = "[ATG]"+modificationToString Mod_CAG = "[CAG]"+modificationToString Mod_AGA = "[AGA]"+modificationToString Mod_CAT = "[CAT]"+modificationToString Mod_CCG = "[CCG]"+modificationToString Mod_CGT = "[CGT]"+modificationToString Mod_CTG = "[CTG]"+modificationToString Mod_GAA = "[GAA]"+modificationToString Mod_GAC = "[GAC]"+modificationToString Mod_GCT = "[GCT]"+modificationToString Mod_GGT = "[GGT]"+modificationToString Mod_GTT = "[GTT]"+modificationToString Mod_TAC = "[TAC]"+modificationToString Mod_TCT = "[TCT]"+modificationToString Mod_TGC = "[TGC]"+modificationToString Mod_TGG = "[TGG]"+modificationToString Mod_TTC = "[TTC]"+modificationToString Mod_TTT = "[TTT]"+modificationToString (Unknown s) = s+
src/Bio/FASTA/Writer.hs view
@@ -1,23 +1,34 @@ module Bio.FASTA.Writer ( fastaToText+ , WritableFastaToken (..) ) where -import Bio.FASTA.Type (Fasta, FastaItem(..))-import Bio.Sequence (BareSequence, sequ)-import Control.Lens ((^.))-import Data.Text (Text, pack)-import Data.List.Split (chunksOf)-import Data.Vector (Vector, toList)-import Prelude hiding (drop)+import Bio.FASTA.Type (Fasta, FastaItem (..), ModItem (..), modificationToString)+import Bio.Sequence (BareSequence, sequ)+import Control.Lens ((^.))+import Data.List.Split (chunksOf)+import Data.Text (Text, pack)+import Data.Vector (Vector, toList)+import Prelude hiding (drop) -fastaToText :: Fasta Char -> Text+class WritableFastaToken a where+ tokenToString :: a -> String++instance WritableFastaToken Char where+ tokenToString = pure++instance WritableFastaToken ModItem where+ tokenToString (Letter l) = [l]+ tokenToString (Mod m) = modificationToString m++fastaToText :: WritableFastaToken a => Fasta a -> Text fastaToText f = mconcat $ map writeItem f -writeItem :: FastaItem Char -> Text+writeItem :: WritableFastaToken a => FastaItem a -> Text writeItem (FastaItem name s) = ">" <> name <> "\n" <> seq2Text s -seq2Text :: BareSequence Char -> Text+seq2Text :: WritableFastaToken a => BareSequence a -> Text seq2Text s = pack $ vector2Text $ s ^. Bio.Sequence.sequ -vector2Text :: Vector Char -> String-vector2Text v = concatMap (++ "\n") $ chunksOf 80 $ toList v+vector2Text :: WritableFastaToken a => Vector a -> String+vector2Text v = concatMap (++ "\n") $ chunksOf 80 $ concatMap tokenToString $ toList v
test/FastaParserSpec.hs view
@@ -3,7 +3,7 @@ module FastaParserSpec where import Bio.FASTA.Parser (fastaP)-import Bio.FASTA.Type (Fasta, FastaItem (..))+import Bio.FASTA.Type (Fasta, FastaItem (..), ModItem (..), Modification (..)) import Bio.Sequence (bareSequence) import Data.Attoparsec.Text (endOfInput, parseOnly) import Data.Text (Text)@@ -23,13 +23,14 @@ sequenceWithSeveralEndOfLineInSequence sequenceWithTabsInName sequenceWithTabsInSequence+ sequenceWithModifications toughParserTests emptyFasta :: Spec emptyFasta = describe "emptyFasta" $ do it "correctly parses empty fasta" $ do let res = parseOnly fastaP ""- res `shouldBe` Right []+ res `shouldBe` Right ([] :: Fasta Char) onlyName :: Spec onlyName = describe "onlyName" $ do@@ -59,7 +60,7 @@ sequenceWithWrongName = describe "sequenceWithWrongName" $ do it "correctly parses incorrect sequence with wrong name" $ do let res = parseOnly fastaP "123\nIWELKKDVYVVELDWYPDAPGEMVVLTCDTPEEGITWTLDQSSE"- res `shouldBe` Right []+ res `shouldBe` Right ([] :: Fasta Char) sequenceWithSpacesInName :: Spec sequenceWithSpacesInName = describe "sequenceWithSpacesInName" $ do@@ -90,6 +91,12 @@ it "correctly parses sequence with tabs between sequence parts" $ do let res = parseOnly fastaP ">this is my sequence\nIWELKKDVYVVELDWYPDAPGEMVVLTCDTPEEGITWTLDQSSE\t\t\nYYYYYYYYYYYYYYYYYYYYYYYY\t\n" res `shouldBe` Right [FastaItem "this is my sequence" (bareSequence "IWELKKDVYVVELDWYPDAPGEMVVLTCDTPEEGITWTLDQSSEYYYYYYYYYYYYYYYYYYYYYYYY")]++sequenceWithModifications :: Spec+sequenceWithModifications = describe "sequenceWithModifications" $ do+ it "correctly parses sequence with modifications" $ do+ let res = parseOnly fastaP ">this is my sequence\nIWEL[mU*]KKDVYV\t\t\nYY[56FAM]YY[Trololo]YY\t\n"+ res `shouldBe` Right [FastaItem "this is my sequence" (bareSequence [Letter 'I', Letter 'W', Letter 'E', Letter 'L', Mod Mod_mU_Star, Letter 'K', Letter 'K', Letter 'D', Letter 'V', Letter 'Y', Letter 'V', Letter 'Y', Letter 'Y', Mod Mod_56FAM, Letter 'Y', Letter 'Y', Mod (Unknown "[Trololo]"), Letter 'Y', Letter 'Y'])] toughParserTests :: Spec toughParserTests = describe "various parser tests" $ do
test/FastaWriterSpec.hs view
@@ -15,7 +15,7 @@ emptyFasta :: Spec emptyFasta = describe "emptyFasta" $ do it "correctly write empty fasta" $ do- let res = fastaToText []+ let res = fastaToText ([] :: [FastaItem Char]) res `shouldBe` "" oneShortSequence :: Spec