packages feed

fasta 0.5.3.0 → 0.5.4.0

raw patch · 4 files changed

+106/−11 lines, 4 filesdep +pipesPVP ok

version bump matches the API change (PVP)

Dependencies added: pipes

API changes (from Hackage documentation)

+ Data.Fasta.String.Parse: pipesFasta :: MonadIO m => Handle -> Pipe String FastaSequence m ()
+ Data.Fasta.Text.Lazy.Parse: pipesFasta :: MonadIO m => Handle -> Pipe Text FastaSequence m ()
+ Data.Fasta.Text.Parse: pipesFasta :: MonadIO m => Handle -> Pipe Text FastaSequence m ()

Files

fasta.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.5.3.0+version:             0.5.4.0  -- A short (one-line) description of the package. synopsis:            A simple, mindless parser for fasta files.@@ -68,7 +68,8 @@                        parsec >=3.1 && <4.0,                        text >=1.1.0 && <1.4,                        containers >= 0.5 && <0.6,-                       split >= 0.2 && <0.3+                       split >= 0.2 && <0.3,+                       pipes >= 4.1 && < 4.2      -- Directories containing source files.   hs-source-dirs:      src
src/Data/Fasta/String/Parse.hs view
@@ -6,19 +6,25 @@ -}  {-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE BangPatterns #-}  module Data.Fasta.String.Parse ( parseFasta                                , parseCLIPFasta+                               , pipesFasta                                , removeNs                                , removeN                                , removeCLIPNs ) where  -- Built-in-import qualified Data.Map as M import Data.Char import Text.Parsec import Control.Monad (void)+import qualified Data.Map as Map+import qualified System.IO as IO +-- Cabal+import Pipes+ -- Local import Data.Fasta.String.Types @@ -68,7 +74,7 @@  -- | Parse a CLIP fasta file into string sequences parseCLIPFasta :: String -> CloneMap-parseCLIPFasta = M.fromList+parseCLIPFasta = Map.fromList                . map (\(x, (y, z)) -> ((x, y), z))                . zip [0..]                . eToV@@ -77,6 +83,32 @@     eToV (Right x) = x     eToV (Left x)  = error ("Unable to parse fasta file\n" ++ show x) +-- | Parse a standard fasta file into string sequences for pipes. This is+-- the highly recommeded way of parsing, as it is computationally fast and+-- uses constant file memory+pipesFasta :: (MonadIO m) => IO.Handle -> Pipe String FastaSequence m ()+pipesFasta h = do+    first <- await+    getRest first ""+  where+    getRest x !acc = do+        eof <- liftIO $ IO.hIsEOF h+        if eof+            then yield FastaSequence { fastaHeader = tail x+                                     , fastaSeq    = filter+                                                     (`notElem` "\n\r ")+                                                     acc }+            else do+                y <- await+                if take 1 y == ">"+                    then do+                        yield FastaSequence { fastaHeader = tail x+                                            , fastaSeq    = filter+                                                            (`notElem` "\n\r ")+                                                            acc }+                        getRest y ""+                    else getRest x (acc ++ y)+ -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence] removeNs = map (\x -> x { fastaSeq = noN . fastaSeq $ x })@@ -91,7 +123,7 @@  -- | Remove Ns from a collection of CLIP fasta sequences removeCLIPNs :: CloneMap -> CloneMap-removeCLIPNs = M.fromList . map remove . M.toList+removeCLIPNs = Map.fromList . map remove . Map.toList   where     remove   ((x, y), z)    = ((x, newSeq y), map newSeq z)     newSeq x = x { fastaSeq = noN . fastaSeq $ x }
src/Data/Fasta/Text/Lazy/Parse.hs view
@@ -10,6 +10,7 @@  module Data.Fasta.Text.Lazy.Parse ( parseFasta                                   , parseCLIPFasta+                                  , pipesFasta                                   , removeNs                                   , removeN                                   , removeCLIPNs ) where@@ -17,11 +18,15 @@ -- Built-in import Data.Char import Control.Monad (void)-import qualified Data.Map.Strict as M import Text.Parsec import Text.Parsec.Text.Lazy+import qualified Data.Map.Strict as Map import qualified Data.Text.Lazy as T+import qualified System.IO as IO +-- Cabal+import Pipes+ -- Local import Data.Fasta.Text.Lazy.Types @@ -72,7 +77,7 @@  -- | Parse a CLIP fasta file into lazy text sequences parseCLIPFasta :: T.Text -> CloneMap-parseCLIPFasta = M.fromList+parseCLIPFasta = Map.fromList                . map (\(!x, (!y, !z)) -> ((x, y), z))                . zip [0..]                . eToV@@ -81,6 +86,32 @@     eToV (Right x) = x     eToV (Left x)  = error ("Unable to parse fasta file\n" ++ show x) +-- | Parse a standard fasta file into lazy text sequences for pipes. This is+-- the highly recommeded way of parsing, as it is computationally fast and+-- uses constant file memory+pipesFasta :: (MonadIO m) => IO.Handle -> Pipe T.Text FastaSequence m ()+pipesFasta h = do+    first <- await+    getRest first ""+  where+    getRest x !acc = do+        eof <- liftIO $ IO.hIsEOF h+        if eof+            then yield FastaSequence { fastaHeader = T.tail x+                                     , fastaSeq    = T.filter+                                                     (`notElem` ("\n\r " :: String))+                                                     acc }+            else do+                y <- await+                if T.take 1 y == ">"+                    then do+                        yield FastaSequence { fastaHeader = T.tail x+                                            , fastaSeq    = T.filter+                                                            (`notElem` ("\n\r " :: String))+                                                            acc }+                        getRest y ""+                    else getRest x (acc `T.append` y)+ -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence] removeNs = map (\x -> x { fastaSeq = noN . fastaSeq $ x })@@ -95,7 +126,7 @@  -- | Remove Ns from a collection of CLIP fasta sequences removeCLIPNs :: CloneMap -> CloneMap-removeCLIPNs = M.fromList . map remove . M.toList+removeCLIPNs = Map.fromList . map remove . Map.toList   where     remove   ((!x, !y), !z)    = ((x, newSeq y), map newSeq z)     newSeq !x = x { fastaSeq = noN . fastaSeq $ x }
src/Data/Fasta/Text/Parse.hs view
@@ -10,18 +10,23 @@  module Data.Fasta.Text.Parse ( parseFasta                              , parseCLIPFasta+                             , pipesFasta                              , removeNs                              , removeN                              , removeCLIPNs ) where  -- Built-in import Data.Char-import qualified Data.Map.Strict as M import Control.Monad (void) import Text.Parsec import Text.Parsec.Text+import qualified Data.Map.Strict as Map import qualified Data.Text as T+import qualified System.IO as IO +-- Cabal+import Pipes+ -- Local import Data.Fasta.Text.Types @@ -73,7 +78,7 @@  -- | Parse a CLIP fasta file into text sequences parseCLIPFasta :: T.Text -> CloneMap-parseCLIPFasta = M.fromList+parseCLIPFasta = Map.fromList                . map (\(!x, (!y, !z)) -> ((x, y), z))                . zip [0..]                . eToV@@ -82,6 +87,32 @@     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 constant file memory+pipesFasta :: (MonadIO m) => IO.Handle -> Pipe T.Text FastaSequence m ()+pipesFasta h = do+    first <- await+    getRest first ""+  where+    getRest x !acc = do+        eof <- liftIO $ IO.hIsEOF h+        if eof+            then yield FastaSequence { fastaHeader = T.tail x+                                     , fastaSeq    = T.filter+                                                     (`notElem` ("\n\r " :: String))+                                                     acc }+            else do+                y <- await+                if T.take 1 y == ">"+                    then do+                        yield FastaSequence { fastaHeader = T.tail x+                                            , fastaSeq    = T.filter+                                                            (`notElem` ("\n\r " :: String))+                                                            acc }+                        getRest y ""+                    else getRest x (acc `T.append` y)+ -- | Remove Ns from a collection of sequences removeNs :: [FastaSequence] -> [FastaSequence] removeNs = map (\x -> x { fastaSeq = noN . fastaSeq $ x })@@ -96,7 +127,7 @@  -- | Remove Ns from a collection of CLIP fasta sequences removeCLIPNs :: CloneMap -> CloneMap-removeCLIPNs = M.fromList . map remove . M.toList+removeCLIPNs = Map.fromList . map remove . Map.toList   where     remove   ((!x, !y), !z)    = ((x, newSeq y), map newSeq z)     newSeq !x = x { fastaSeq = noN . fastaSeq $ x }