biofasta 0.0.2 → 0.0.3
raw patch · 3 files changed
+36/−35 lines, 3 filesdep ~biocorePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: biocore
API changes (from Hackage documentation)
+ Bio.Sequence.Fasta: seqdata :: BioSeq s => s -> SeqData
+ Bio.Sequence.Fasta: seqheader :: BioSeq s => s -> SeqLabel
+ Bio.Sequence.Fasta: seqid :: BioSeq s => s -> SeqLabel
+ Bio.Sequence.Fasta: seqlength :: BioSeq s => s -> Offset
+ Bio.Sequence.Fasta: toStr :: SeqData -> String
Files
- biofasta.cabal +4/−3
- src/Bio/Sequence/Fasta.hs +16/−32
- src/Test.hs +16/−0
biofasta.cabal view
@@ -1,19 +1,20 @@ Name: biofasta-Version: 0.0.2+Version: 0.0.3 Synopsis: Library for reading fasta sequence files Description: Library for reading fasta sequence files Homepage: https://patch-tag.com/r/dfornika/biofasta/home License: GPL License-file: LICENSE Cabal-Version: >=1.6-Author: Dan Fornika <dfornika@gmail.com>+Author: Ketil Malde <ketil@malde.org> Maintainer: dfornika@gmail.com Stability: Provisional Category: Bioinformatics Build-Type: Simple+Extra-Source-Files: src/Test.hs Library- Build-depends: base >= 2 && < 5, biocore, bytestring+ Build-depends: base >= 2 && < 5, biocore >= 0.3.1, bytestring Exposed-modules: Bio.Sequence.Fasta Hs-source-dirs: src
src/Bio/Sequence/Fasta.hs view
@@ -4,11 +4,7 @@ This module incorporates functionality for reading and writing sequence data in the Fasta format. Each sequence consists of a header (with a '>' prefix)- and a set of lines containing the sequence data.-- As Fasta is used for both amino acids and nucleotides, the- resulting 'Sequence's are type-tagged with 'Unknown'. If you know the - type of sequence you are reading, use 'castToAmino' or 'castToNuc'.+ and a set of lines containing the sequence data.. -} module Bio.Sequence.Fasta@@ -19,6 +15,8 @@ , countSeqs -- * Helper function for reading your own sequences , mkSeqs+ -- * Other+ , toStr, seqid, seqheader, seqdata, seqlength ) where @@ -36,32 +34,15 @@ splitsAt n s = let (s1,s2) = B.splitAt (unOff n) s in if B.null s2 then [s1] else s1 : splitsAt n s2 -{---- ugly?-class SeqType sd where- toSeq :: sd -> sd -> Sequence- fromSeq :: Sequence -> (sd,sd)--instance SeqType B.ByteString where- toSeq = Seq- fromSeq (Seq x y) = (x,y)--instance SeqType BS.ByteString where- toSeq h s = Seq (B.fromChunks [h]) (B.fromChunks [s])- fromSeq (Seq x y) = (c x, c y) where c = BS.concat . B.toChunks--}- data Sequence = Seq SeqLabel SeqData (Maybe QualData)- deriving Eq+ deriving (Show, Eq) instance BioSeq Sequence where- seqlabel (Seq lab seq mqual) = lab+ seqid (Seq lab seq mqual) = SeqLabel {unSL = B.takeWhile (/= ' ') $ unSL lab}+ seqheader (Seq lab seq mqual) = lab seqdata (Seq lab seq mqual) = seq seqlength (Seq lab seq mqual) = Offset {unOff = B.length $ unSD seq} -instance Show Sequence where- show (Seq lab seq qual) = ">" ++ (B.unpack $ unSL lab) ++ "\n" ++ (B.unpack $ unSD seq)- toStr :: SeqData -> String toStr = B.unpack . unSD @@ -106,17 +87,20 @@ mkSeqs = map mkSeq . blocks mkSeq :: [ByteString] -> Sequence-mkSeq (l:ls) - -- maybe check this? | B.length l < 2 || isSpace (B.head $ B.tail l) - -- = error "Trying to read sequence without a name...and failing."- | otherwise = Seq (SeqLabel (B.drop 1 l)) (SeqData (B.filter (not . isSpace) $ B.concat $ takeWhile isSeq ls)) Nothing- where isSeq s = (not . B.null) s && ((flip elem) (['A'..'Z']++['a'..'z']) . B.head) s-mkSeq [] = error "empty input to mkSeq"+mkSeq (l:ls) = Seq (SeqLabel (B.drop 1 l))+ (SeqData (B.filter (not . isSpace) $ B.concat $ takeWhile isSeq ls))+ Nothing+ where isSeq s = (not . B.null) s &&+ (flip elem (['A'..'Z']++['a'..'z']) . B.head) s+mkSeq [] = error "empty input to mkSeq" -- | Split lines into blocks starting with '>' characters -- Filter out # comments (but not semicolons?) blocks :: [ByteString] -> [[ByteString]]-blocks = groupBy (const (('>' /=) . B.head)) . filter ((/='#') . B.head) . dropWhile (('>' /=) . B.head) . filter (not . B.null)+blocks = groupBy (const (('>' /=) . B.head))+ . filter ((/='#') . B.head)+ . dropWhile (('>' /=) . B.head)+ . filter (not . B.null) countSeqs :: FilePath -> IO Int countSeqs f = do
+ src/Test.hs view
@@ -0,0 +1,16 @@+import Test.QuickCheck+import Text.Printf (printf)++import qualified Data.ByteString.Lazy.Char8 as B++main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests++prop_test_00 s = s == s+ where _ = s :: Int++prop_block seq = block seq+ where seq = B.pack '>' B.cons (s :: Bytestring)++tests = [("test_00", quickCheck prop_test_00)+ ,("test_01", quickCheck prop_block )+ ]