fasta 0.8.0.2 → 0.9.0.0
raw patch · 6 files changed
+351/−55 lines, 6 filesdep +attoparsecdep +pipes-attoparsecPVP ok
version bump matches the API change (PVP)
Dependencies added: attoparsec, pipes-attoparsec
API changes (from Hackage documentation)
- Data.Fasta.ByteString.Lazy.Parse: parseCLIPFasta :: ByteString -> CloneMap
- Data.Fasta.ByteString.Lazy.Parse: parseFasta :: ByteString -> [FastaSequence]
- Data.Fasta.ByteString.Lazy.Types: fastaHeader :: FastaSequence -> ByteString
- Data.Fasta.ByteString.Lazy.Types: fastaSeq :: FastaSequence -> ByteString
- Data.Fasta.ByteString.Lazy.Types: instance Eq FastaSequence
- Data.Fasta.ByteString.Lazy.Types: instance Ord FastaSequence
- Data.Fasta.ByteString.Lazy.Types: instance Show FastaSequence
- Data.Fasta.ByteString.Lazy.Types: instance ShowFasta FastaSequence
- Data.Fasta.ByteString.Parse: parseCLIPFasta :: ByteString -> CloneMap
- Data.Fasta.ByteString.Parse: parseFasta :: ByteString -> [FastaSequence]
- Data.Fasta.ByteString.Types: fastaHeader :: FastaSequence -> ByteString
- Data.Fasta.ByteString.Types: fastaSeq :: FastaSequence -> ByteString
- Data.Fasta.ByteString.Types: instance Eq FastaSequence
- Data.Fasta.ByteString.Types: instance Ord FastaSequence
- Data.Fasta.ByteString.Types: instance Show FastaSequence
- Data.Fasta.ByteString.Types: instance ShowFasta FastaSequence
- Data.Fasta.String.Types: fastaHeader :: FastaSequence -> String
- Data.Fasta.String.Types: fastaSeq :: FastaSequence -> String
- Data.Fasta.String.Types: instance Eq FastaSequence
- Data.Fasta.String.Types: instance Ord FastaSequence
- Data.Fasta.String.Types: instance Show FastaSequence
- Data.Fasta.String.Types: instance ShowFasta FastaSequence
- Data.Fasta.Text.Lazy.Parse: parseCLIPFasta :: Text -> CloneMap
- Data.Fasta.Text.Lazy.Parse: parseFasta :: Text -> [FastaSequence]
- Data.Fasta.Text.Lazy.Types: fastaHeader :: FastaSequence -> Text
- Data.Fasta.Text.Lazy.Types: fastaSeq :: FastaSequence -> Text
- Data.Fasta.Text.Lazy.Types: instance Eq FastaSequence
- Data.Fasta.Text.Lazy.Types: instance Ord FastaSequence
- Data.Fasta.Text.Lazy.Types: instance Show FastaSequence
- Data.Fasta.Text.Lazy.Types: instance ShowFasta FastaSequence
- Data.Fasta.Text.Parse: parseCLIPFasta :: Text -> CloneMap
- Data.Fasta.Text.Parse: parseFasta :: Text -> [FastaSequence]
- Data.Fasta.Text.Types: fastaHeader :: FastaSequence -> Text
- Data.Fasta.Text.Types: fastaSeq :: FastaSequence -> Text
- Data.Fasta.Text.Types: instance Eq FastaSequence
- Data.Fasta.Text.Types: instance Ord FastaSequence
- Data.Fasta.Text.Types: instance Show FastaSequence
- Data.Fasta.Text.Types: instance ShowFasta FastaSequence
+ Data.Fasta.ByteString.Lazy.Parse: attoCLIPFasta :: ByteString -> [(Germline, [FastaSequence])]
+ Data.Fasta.ByteString.Lazy.Parse: attoFasta :: ByteString -> [FastaSequence]
+ Data.Fasta.ByteString.Lazy.Parse: parsecCLIPFasta :: ByteString -> CloneMap
+ Data.Fasta.ByteString.Lazy.Parse: parsecFasta :: ByteString -> [FastaSequence]
+ Data.Fasta.ByteString.Lazy.Parse: pipesCLIPFasta :: (MonadIO m) => Producer ByteString m () -> Producer (Germline, [FastaSequence]) m (Either (ParsingError, Producer ByteString m ()) ())
+ Data.Fasta.ByteString.Lazy.Types: [fastaHeader] :: FastaSequence -> ByteString
+ Data.Fasta.ByteString.Lazy.Types: [fastaSeq] :: FastaSequence -> ByteString
+ Data.Fasta.ByteString.Lazy.Types: instance Data.Fasta.ByteString.Lazy.Types.ShowFasta Data.Fasta.ByteString.Lazy.Types.FastaSequence
+ Data.Fasta.ByteString.Lazy.Types: instance GHC.Classes.Eq Data.Fasta.ByteString.Lazy.Types.FastaSequence
+ Data.Fasta.ByteString.Lazy.Types: instance GHC.Classes.Ord Data.Fasta.ByteString.Lazy.Types.FastaSequence
+ Data.Fasta.ByteString.Lazy.Types: instance GHC.Show.Show Data.Fasta.ByteString.Lazy.Types.FastaSequence
+ Data.Fasta.ByteString.Parse: attoCLIPFasta :: ByteString -> [(Germline, [FastaSequence])]
+ Data.Fasta.ByteString.Parse: attoFasta :: ByteString -> [FastaSequence]
+ Data.Fasta.ByteString.Parse: parsecCLIPFasta :: ByteString -> CloneMap
+ Data.Fasta.ByteString.Parse: parsecFasta :: ByteString -> [FastaSequence]
+ Data.Fasta.ByteString.Parse: pipesCLIPFasta :: (MonadIO m) => Producer ByteString m () -> Producer (Germline, [FastaSequence]) m (Either (ParsingError, Producer ByteString m ()) ())
+ Data.Fasta.ByteString.Types: [fastaHeader] :: FastaSequence -> ByteString
+ Data.Fasta.ByteString.Types: [fastaSeq] :: FastaSequence -> ByteString
+ Data.Fasta.ByteString.Types: instance Data.Fasta.ByteString.Types.ShowFasta Data.Fasta.ByteString.Types.FastaSequence
+ Data.Fasta.ByteString.Types: instance GHC.Classes.Eq Data.Fasta.ByteString.Types.FastaSequence
+ Data.Fasta.ByteString.Types: instance GHC.Classes.Ord Data.Fasta.ByteString.Types.FastaSequence
+ Data.Fasta.ByteString.Types: instance GHC.Show.Show Data.Fasta.ByteString.Types.FastaSequence
+ Data.Fasta.String.Types: [fastaHeader] :: FastaSequence -> String
+ Data.Fasta.String.Types: [fastaSeq] :: FastaSequence -> String
+ Data.Fasta.String.Types: instance Data.Fasta.String.Types.ShowFasta Data.Fasta.String.Types.FastaSequence
+ Data.Fasta.String.Types: instance GHC.Classes.Eq Data.Fasta.String.Types.FastaSequence
+ Data.Fasta.String.Types: instance GHC.Classes.Ord Data.Fasta.String.Types.FastaSequence
+ Data.Fasta.String.Types: instance GHC.Show.Show Data.Fasta.String.Types.FastaSequence
+ Data.Fasta.Text.Lazy.Parse: attoCLIPFasta :: Text -> [(Germline, [FastaSequence])]
+ Data.Fasta.Text.Lazy.Parse: attoFasta :: Text -> [FastaSequence]
+ Data.Fasta.Text.Lazy.Parse: parsecCLIPFasta :: Text -> CloneMap
+ Data.Fasta.Text.Lazy.Parse: parsecFasta :: Text -> [FastaSequence]
+ Data.Fasta.Text.Lazy.Parse: pipesCLIPFasta :: (MonadIO m) => Producer Text m () -> Producer (Germline, [FastaSequence]) m (Either (ParsingError, Producer Text m ()) ())
+ Data.Fasta.Text.Lazy.Types: [fastaHeader] :: FastaSequence -> Text
+ Data.Fasta.Text.Lazy.Types: [fastaSeq] :: FastaSequence -> Text
+ Data.Fasta.Text.Lazy.Types: instance Data.Fasta.Text.Lazy.Types.ShowFasta Data.Fasta.Text.Lazy.Types.FastaSequence
+ Data.Fasta.Text.Lazy.Types: instance GHC.Classes.Eq Data.Fasta.Text.Lazy.Types.FastaSequence
+ Data.Fasta.Text.Lazy.Types: instance GHC.Classes.Ord Data.Fasta.Text.Lazy.Types.FastaSequence
+ Data.Fasta.Text.Lazy.Types: instance GHC.Show.Show Data.Fasta.Text.Lazy.Types.FastaSequence
+ Data.Fasta.Text.Parse: attoCLIPFasta :: Text -> [(Germline, [FastaSequence])]
+ Data.Fasta.Text.Parse: attoFasta :: Text -> [FastaSequence]
+ Data.Fasta.Text.Parse: parsecCLIPFasta :: Text -> CloneMap
+ Data.Fasta.Text.Parse: parsecFasta :: Text -> [FastaSequence]
+ Data.Fasta.Text.Parse: pipesCLIPFasta :: (MonadIO m) => Producer Text m () -> Producer (Germline, [FastaSequence]) m (Either (ParsingError, Producer Text m ()) ())
+ Data.Fasta.Text.Types: [fastaHeader] :: FastaSequence -> Text
+ Data.Fasta.Text.Types: [fastaSeq] :: FastaSequence -> Text
+ Data.Fasta.Text.Types: instance Data.Fasta.Text.Types.ShowFasta Data.Fasta.Text.Types.FastaSequence
+ Data.Fasta.Text.Types: instance GHC.Classes.Eq Data.Fasta.Text.Types.FastaSequence
+ Data.Fasta.Text.Types: instance GHC.Classes.Ord Data.Fasta.Text.Types.FastaSequence
+ Data.Fasta.Text.Types: instance GHC.Show.Show Data.Fasta.Text.Types.FastaSequence
- Data.Fasta.ByteString.Lazy.Parse: pipesFasta :: MonadIO m => Producer ByteString m () -> Producer FastaSequence m ()
+ Data.Fasta.ByteString.Lazy.Parse: pipesFasta :: (MonadIO m) => Producer ByteString m () -> Producer FastaSequence m ()
- Data.Fasta.ByteString.Parse: pipesFasta :: MonadIO m => Producer ByteString m () -> Producer FastaSequence m ()
+ Data.Fasta.ByteString.Parse: pipesFasta :: (MonadIO m) => Producer ByteString m () -> Producer FastaSequence m ()
- Data.Fasta.String.Parse: pipesFasta :: MonadIO m => Handle -> Pipe String FastaSequence m ()
+ Data.Fasta.String.Parse: pipesFasta :: (MonadIO m) => Handle -> Pipe String FastaSequence m ()
- Data.Fasta.Text.Lazy.Parse: pipesFasta :: MonadIO m => Producer Text m () -> Producer FastaSequence m ()
+ Data.Fasta.Text.Lazy.Parse: pipesFasta :: (MonadIO m) => Producer Text m () -> Producer FastaSequence m ()
- Data.Fasta.Text.Parse: pipesFasta :: MonadIO m => Producer Text m () -> Producer FastaSequence m ()
+ Data.Fasta.Text.Parse: pipesFasta :: (MonadIO m) => Producer Text m () -> Producer FastaSequence m ()
Files
- fasta.cabal +3/−1
- src/Data/Fasta/ByteString/Lazy/Parse.hs +90/−16
- src/Data/Fasta/ByteString/Parse.hs +87/−10
- src/Data/Fasta/Text/Lazy/Parse.hs +83/−12
- src/Data/Fasta/Text/Parse.hs +87/−15
- src/Data/Fasta/Text/Types.hs +1/−1
fasta.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.8.0.2+version: 0.9.0.0 -- A short (one-line) description of the package. synopsis: A simple, mindless parser for fasta files.@@ -82,6 +82,8 @@ , pipes-group >= 1.0 , pipes-text >= 0.0 , pipes-bytestring >= 2.1+ , attoparsec+ , pipes-attoparsec , lens >= 4.9 , foldl >= 1.0
src/Data/Fasta/ByteString/Lazy/Parse.hs view
@@ -8,27 +8,34 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} -module Data.Fasta.ByteString.Lazy.Parse ( parseFasta- , parseCLIPFasta+module Data.Fasta.ByteString.Lazy.Parse ( parsecFasta+ , parsecCLIPFasta+ , attoFasta+ , attoCLIPFasta , pipesFasta+ , pipesCLIPFasta , removeNs , removeN , removeCLIPNs ) where -- Built-in import Data.Char-import Control.Monad (void) import Text.Parsec import Text.Parsec.ByteString.Lazy import qualified Data.Map.Strict as Map+import qualified Data.ByteString as BW import qualified Data.ByteString.Char8 as SB import qualified Data.ByteString.Lazy.Char8 as B+import qualified Control.Applicative as CA+import Control.Monad (void) -- Cabal+import qualified Data.Attoparsec.ByteString.Char8 as A import Pipes import qualified Pipes.Prelude as P import qualified Pipes.ByteString as PB import qualified Pipes.Group as PG+import qualified Pipes.Attoparsec as PA import Control.Lens (view) import qualified Control.Foldl as FL @@ -71,27 +78,86 @@ spaces many fastaCLIP --- | Parse a standard fasta file into lazy text sequences-parseFasta :: B.ByteString -> [FastaSequence]-parseFasta = eToV . parse fastaFile "error"+-- | Parse a standard fasta file into+parsecFasta :: B.ByteString -> [FastaSequence]+parsecFasta = eToV . parse fastaFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) --- | Parse a CLIP fasta file into lazy text sequences-parseCLIPFasta :: B.ByteString -> CloneMap-parseCLIPFasta = Map.fromList- . map (\(!x, (!y, !z)) -> ((x, y), z))- . zip [0..]- . eToV- . parse fastaCLIPFile "error"+-- | Parse a CLIP fasta file into+parsecCLIPFasta :: B.ByteString -> CloneMap+parsecCLIPFasta = Map.fromList+ . map (\(!x, (!y, !z)) -> ((x, y), z))+ . zip [0..]+ . eToV+ . parse fastaCLIPFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) --- | Parse a standard fasta file into strict text sequences for pipes. This is--- the highly recommeded way of parsing, as it is computationally fast and--- uses memory based on line length+-- | attopares any char but space+anyButSpace :: A.Parser Char+anyButSpace = do+ A.skipSpace+ x <- A.letter_ascii+ A.skipSpace+ return x++-- | attoparsec parser for a fasta type+fasta' :: A.Parser FastaSequence+fasta' = do+ header <- A.takeWhile (\x -> x /= '\n' && x /= '\r')+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = B.fromStrict header+ , fastaSeq = B.pack fseq }++-- | attoparsec parser for a fasta file+fastaFile' :: A.Parser [FastaSequence]+fastaFile' = do+ A.skipSpace+ A.char '>'+ A.many' fasta'++-- | attoparsec parser for a CLIP fasta sequence+fastaCLIP' :: A.Parser FastaSequence+fastaCLIP' = do+ header <- A.takeWhile (\x -> x /= '\n' && x /= '\r')+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = B.fromStrict header+ , fastaSeq = B.pack fseq }++clone' :: A.Parser (Germline, [FastaSequence])+clone' = do+ A.skipSpace+ germline <- fastaCLIP'+ fseqs <- A.manyTill fasta' (void (A.char '>') CA.<|> A.endOfInput)+ return (germline, fseqs)++-- | attoparsec parser for a fasta file+fastaCLIPFile' :: A.Parser [(Germline, [FastaSequence])]+fastaCLIPFile' = do+ A.skipSpace+ A.string ">>"+ A.many' clone'++-- | Parse a standard fasta file+attoFasta :: BW.ByteString -> [FastaSequence]+attoFasta = eToV . A.parseOnly fastaFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a CLIP fasta file into text sequences+attoCLIPFasta :: BW.ByteString -> [(Germline, [FastaSequence])]+attoCLIPFasta = eToV . A.parseOnly fastaCLIPFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a standard fasta file into a pipe pipesFasta :: (MonadIO m) => Producer SB.ByteString m () -> Producer FastaSequence m ()@@ -111,6 +177,14 @@ . tail . SB.lines $ x }++-- | Parse a CLIP fasta file into strict text sequences for pipes.+pipesCLIPFasta :: (MonadIO m)+ => Producer BW.ByteString m ()+ -> Producer (Germline, [FastaSequence]) m (Either (PA.ParsingError, Producer BW.ByteString m ()) ())+pipesCLIPFasta = PA.parsed clone'+ . PB.drop 2+ . PB.dropWhile (`BW.elem` "\n\r\t ") -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence]
src/Data/Fasta/ByteString/Parse.hs view
@@ -8,9 +8,12 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} -module Data.Fasta.ByteString.Parse ( parseFasta- , parseCLIPFasta+module Data.Fasta.ByteString.Parse ( parsecFasta+ , parsecCLIPFasta+ , attoFasta+ , attoCLIPFasta , pipesFasta+ , pipesCLIPFasta , removeNs , removeN , removeCLIPNs ) where@@ -20,13 +23,18 @@ import Text.Parsec import Text.Parsec.ByteString import qualified Data.Map.Strict as Map+import qualified Data.ByteString as BW import qualified Data.ByteString.Char8 as B+import qualified Control.Applicative as CA+import Control.Monad (void) -- Cabal+import qualified Data.Attoparsec.ByteString.Char8 as A import Pipes import qualified Pipes.Prelude as P import qualified Pipes.ByteString as PB import qualified Pipes.Group as PG+import qualified Pipes.Attoparsec as PA import Control.Lens (view) import qualified Control.Foldl as FL @@ -69,23 +77,84 @@ many fastaCLIP -- | Parse a standard fasta file into text sequences-parseFasta :: B.ByteString -> [FastaSequence]-parseFasta = eToV . parse fastaFile "error"+parsecFasta :: B.ByteString -> [FastaSequence]+parsecFasta = eToV . parse fastaFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) -- | Parse a CLIP fasta file into text sequences-parseCLIPFasta :: B.ByteString -> CloneMap-parseCLIPFasta = Map.fromList- . map (\(!x, (!y, !z)) -> ((x, y), z))- . zip [0..]- . eToV- . parse fastaCLIPFile "error"+parsecCLIPFasta :: B.ByteString -> CloneMap+parsecCLIPFasta = Map.fromList+ . map (\(!x, (!y, !z)) -> ((x, y), z))+ . zip [0..]+ . eToV+ . parse fastaCLIPFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) +-- | attopares any char but space+anyButSpace :: A.Parser Char+anyButSpace = do+ A.skipSpace+ x <- A.letter_ascii+ A.skipSpace+ return x++-- | attoparsec parser for a fasta type+fasta' :: A.Parser FastaSequence+fasta' = do+ header <- A.takeWhile (\x -> x /= '\n' && x /= '\r')+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = header+ , fastaSeq = B.pack fseq }++-- | attoparsec parser for a fasta file+fastaFile' :: A.Parser [FastaSequence]+fastaFile' = do+ A.skipSpace+ A.char '>'+ A.many' fasta'++-- | attoparsec parser for a CLIP fasta sequence+fastaCLIP' :: A.Parser FastaSequence+fastaCLIP' = do+ header <- A.takeWhile (\x -> x /= '\n' && x /= '\r')+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = header+ , fastaSeq = B.pack fseq }++clone' :: A.Parser (Germline, [FastaSequence])+clone' = do+ A.skipSpace+ germline <- fastaCLIP'+ fseqs <- A.manyTill fasta' (void (A.char '>') CA.<|> A.endOfInput)+ return (germline, fseqs)++-- | attoparsec parser for a fasta file+fastaCLIPFile' :: A.Parser [(Germline, [FastaSequence])]+fastaCLIPFile' = do+ A.skipSpace+ A.string ">>"+ A.many' clone'++-- | Parse a standard fasta file+attoFasta :: B.ByteString -> [FastaSequence]+attoFasta = eToV . A.parseOnly fastaFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a CLIP fasta file into text sequences+attoCLIPFasta :: B.ByteString -> [(Germline, [FastaSequence])]+attoCLIPFasta = eToV . A.parseOnly fastaCLIPFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)+ -- | Parse a standard fasta file into strict text sequences for pipes. This is -- the highly recommeded way of parsing, as it is computationally fast and -- uses memory based on line length@@ -101,6 +170,14 @@ where toFasta x = FastaSequence { fastaHeader = head . B.lines $ x , fastaSeq = B.concat . tail . B.lines $ x }++-- | Parse a CLIP fasta file into strict text sequences for pipes.+pipesCLIPFasta :: (MonadIO m)+ => Producer B.ByteString m ()+ -> Producer (Germline, [FastaSequence]) m (Either (PA.ParsingError, Producer B.ByteString m ()) ())+pipesCLIPFasta = PA.parsed clone'+ . PB.drop 2+ . PB.dropWhile (`BW.elem` "\n\r\t ") -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence]
src/Data/Fasta/Text/Lazy/Parse.hs view
@@ -1,5 +1,5 @@ -- Parse module.--- By G.W. Schwartz+-- By Gregory W. Schwartz -- {- | Collection of functions for the parsing of a fasta file. Uses the lazy Text type.@@ -8,9 +8,12 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} -module Data.Fasta.Text.Lazy.Parse ( parseFasta- , parseCLIPFasta+module Data.Fasta.Text.Lazy.Parse ( parsecFasta+ , parsecCLIPFasta+ , attoFasta+ , attoCLIPFasta , pipesFasta+ , pipesCLIPFasta , removeNs , removeN , removeCLIPNs ) where@@ -23,12 +26,15 @@ import qualified Data.Map.Strict as Map import qualified Data.Text as ST import qualified Data.Text.Lazy as T+import qualified Control.Applicative as CA -- Cabal+import qualified Data.Attoparsec.Text as A import Pipes import qualified Pipes.Prelude as P import qualified Pipes.Text as PT import qualified Pipes.Group as PG+import qualified Pipes.Attoparsec as PA import Control.Lens (view) import qualified Control.Foldl as FL @@ -71,16 +77,16 @@ spaces many fastaCLIP --- | Parse a standard fasta file into lazy text sequences-parseFasta :: T.Text -> [FastaSequence]-parseFasta = eToV . parse fastaFile "error"+-- | Parse a standard fasta file+parsecFasta :: T.Text -> [FastaSequence]+parsecFasta = eToV . parse fastaFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) --- | Parse a CLIP fasta file into lazy text sequences-parseCLIPFasta :: T.Text -> CloneMap-parseCLIPFasta = Map.fromList+-- | Parse a CLIP fasta file+parsecCLIPFasta :: T.Text -> CloneMap+parsecCLIPFasta = Map.fromList . map (\(!x, (!y, !z)) -> ((x, y), z)) . zip [0..] . eToV@@ -89,9 +95,68 @@ eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) --- | Parse a standard fasta file into strict text sequences for pipes. This is--- the highly recommeded way of parsing, as it is computationally fast and--- uses memory based on line length+-- | attopares any char but space+anyButSpace :: A.Parser Char+anyButSpace = do+ A.skipSpace+ x <- A.letter+ A.skipSpace+ return x++-- | attoparsec parser for a fasta type+fasta' :: A.Parser FastaSequence+fasta' = do+ header <- A.takeWhile (not . A.isEndOfLine)+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = T.fromStrict header+ , fastaSeq = T.pack fseq }++-- | attoparsec parser for a fasta file+fastaFile' :: A.Parser [FastaSequence]+fastaFile' = do+ A.skipSpace+ A.char '>'+ A.many' fasta'++-- | attoparsec parser for a CLIP fasta sequence+fastaCLIP' :: A.Parser FastaSequence+fastaCLIP' = do+ header <- A.takeWhile (not . A.isEndOfLine)+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = T.fromStrict header+ , fastaSeq = T.pack fseq }++clone' :: A.Parser (Germline, [FastaSequence])+clone' = do+ A.skipSpace+ germline <- fastaCLIP'+ fseqs <- A.manyTill fasta' (void (A.char '>') CA.<|> A.endOfInput)+ return (germline, fseqs)++-- | attoparsec parser for a fasta file+fastaCLIPFile' :: A.Parser [(Germline, [FastaSequence])]+fastaCLIPFile' = do+ A.skipSpace+ A.string ">>"+ A.many' clone'++-- | Parse a standard fasta file+attoFasta :: ST.Text -> [FastaSequence]+attoFasta = eToV . A.parseOnly fastaFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a CLIP fasta file+attoCLIPFasta :: ST.Text -> [(Germline, [FastaSequence])]+attoCLIPFasta = eToV . A.parseOnly fastaCLIPFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a standard fasta file into a pipe pipesFasta :: (MonadIO m) => Producer ST.Text m () -> Producer FastaSequence m ()@@ -108,6 +173,12 @@ . tail . ST.lines $ x }++-- | Parse a CLIP fasta file into a pipe+pipesCLIPFasta :: (MonadIO m)+ => Producer ST.Text m ()+ -> Producer (Germline, [FastaSequence]) m (Either (PA.ParsingError, Producer ST.Text m ()) ())+pipesCLIPFasta = PA.parsed clone' . PT.drop 2 . (>-> PT.stripStart) -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence]
src/Data/Fasta/Text/Parse.hs view
@@ -8,9 +8,12 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} -module Data.Fasta.Text.Parse ( parseFasta- , parseCLIPFasta+module Data.Fasta.Text.Parse ( parsecFasta+ , parsecCLIPFasta+ , attoFasta+ , attoCLIPFasta , pipesFasta+ , pipesCLIPFasta , removeNs , removeN , removeCLIPNs ) where@@ -21,12 +24,16 @@ import Text.Parsec.Text import qualified Data.Map.Strict as Map import qualified Data.Text as T+import qualified Control.Applicative as CA+import Control.Monad (void) -- Cabal+import qualified Data.Attoparsec.Text as A import Pipes import qualified Pipes.Prelude as P import qualified Pipes.Text as PT import qualified Pipes.Group as PG+import qualified Pipes.Attoparsec as PA import Control.Lens (view) import qualified Control.Foldl as FL @@ -68,27 +75,86 @@ spaces many fastaCLIP --- | Parse a standard fasta file into text sequences-parseFasta :: T.Text -> [FastaSequence]-parseFasta = eToV . parse fastaFile "error"+-- | Parse a standard fasta file+parsecFasta :: T.Text -> [FastaSequence]+parsecFasta = eToV . parse fastaFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) --- | Parse a CLIP fasta file into text sequences-parseCLIPFasta :: T.Text -> CloneMap-parseCLIPFasta = Map.fromList- . map (\(!x, (!y, !z)) -> ((x, y), z))- . zip [0..]- . eToV- . parse fastaCLIPFile "error"+-- | Parse a CLIP fasta file+parsecCLIPFasta :: T.Text -> CloneMap+parsecCLIPFasta = Map.fromList+ . map (\(!x, (!y, !z)) -> ((x, y), z))+ . zip [0..]+ . eToV+ . parse fastaCLIPFile "error" where eToV (Right x) = x eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x) --- | Parse a standard fasta file into strict text sequences for pipes. This is--- the highly recommeded way of parsing, as it is computationally fast and--- uses memory based on line length+-- | attopares any char but space+anyButSpace :: A.Parser Char+anyButSpace = do+ A.skipSpace+ x <- A.letter+ A.skipSpace+ return x++-- | attoparsec parser for a fasta type+fasta' :: A.Parser FastaSequence+fasta' = do+ header <- A.takeWhile (not . A.isEndOfLine)+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = header+ , fastaSeq = T.pack fseq }++-- | attoparsec parser for a fasta file+fastaFile' :: A.Parser [FastaSequence]+fastaFile' = do+ A.skipSpace+ A.char '>'+ A.many' fasta'++-- | attoparsec parser for a CLIP fasta sequence+fastaCLIP' :: A.Parser FastaSequence+fastaCLIP' = do+ header <- A.takeWhile (not . A.isEndOfLine)+ A.endOfLine+ fseq <- A.manyTill anyButSpace (void (A.char '>') CA.<|> A.endOfInput)+ return FastaSequence { fastaHeader = header+ , fastaSeq = T.pack fseq }++clone' :: A.Parser (Germline, [FastaSequence])+clone' = do+ A.skipSpace+ germline <- fastaCLIP'+ fseqs <- A.manyTill fasta' (void (A.char '>') CA.<|> A.endOfInput)+ return (germline, fseqs)++-- | attoparsec parser for a fasta file+fastaCLIPFile' :: A.Parser [(Germline, [FastaSequence])]+fastaCLIPFile' = do+ A.skipSpace+ A.string ">>"+ A.many' clone'++-- | Parse a standard fasta file+attoFasta :: T.Text -> [FastaSequence]+attoFasta = eToV . A.parseOnly fastaFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a CLIP fasta file+attoCLIPFasta :: T.Text -> [(Germline, [FastaSequence])]+attoCLIPFasta = eToV . A.parseOnly fastaCLIPFile'+ where+ eToV (Right x) = x+ eToV (Left x) = error ("Unable to parse fasta file\n" ++ show x)++-- | Parse a standard fasta file into a pipe pipesFasta :: (MonadIO m) => Producer T.Text m () -> Producer FastaSequence m () pipesFasta p = FL.purely PG.folds FL.mconcat ( view (PT.splits '>') . PT.drop (1 :: Int)@@ -97,6 +163,12 @@ where toFasta x = FastaSequence { fastaHeader = head . T.lines $ x , fastaSeq = T.concat . tail . T.lines $ x }++-- | Parse a CLIP fasta file into a pipe+pipesCLIPFasta :: (MonadIO m)+ => Producer T.Text m ()+ -> Producer (Germline, [FastaSequence]) m (Either (PA.ParsingError, Producer T.Text m ()) ())+pipesCLIPFasta = PA.parsed clone' . PT.drop 2 . (>-> PT.stripStart) -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence]
src/Data/Fasta/Text/Types.hs view
@@ -1,5 +1,5 @@ -- Types module.--- By G.W. Schwartz+-- By Gregory W. Schwartz -- {- | Collects all application specific types. Used here for Text. -}