packages feed

flower 0.1 → 0.1.1

raw patch · 2 files changed

+47/−10 lines, 2 filesdep ~basedep ~bio

Dependency ranges changed: base, bio

Files

flower.cabal view
@@ -1,5 +1,5 @@ Name:           flower-Version:        0.1+Version:        0.1.1 License:        GPL  Author:         Ketil Malde@@ -15,7 +15,7 @@                 The Darcs repository is at <http://malde.org/~ketil/biohaskell/flower>.  HomePage:       http://malde.org/~ketil/biohaskell/flower-Build-Depends:  bio >= 0.3.5, base, array >= 0.1, bytestring >= 0.9.1, binary+Build-Depends:  bio >= 0.3.5 && <0.4, base >= 3 && < 4, array >= 0.1, bytestring >= 0.9.1, binary Build-Type:     Simple Tested-with:    GHC==6.8.3 
src/Flower.hs view
@@ -6,14 +6,16 @@ import Bio.Sequence.Fasta import Bio.Sequence.FastQ +import Print+ import System.IO (stdout) import System.Environment (getArgs) import Numeric (showFFloat) import Data.List (intersperse, partition)-import Data.ByteString.Char8 (unpack,ByteString)+import Data.ByteString.Char8 (pack,unpack,ByteString) import qualified Data.ByteString.Char8 as B import qualified Data.ByteString as B1-import qualified Data.ByteString.Lazy.Char8 as LB+import qualified Data.ByteString.Lazy as L1  import Data.Array.Unboxed import Data.Array.ST@@ -25,18 +27,50 @@   let (opts,files) = partition (\p -> case p of ('-':_) -> True; _ -> False) args   case opts of      ["-r"] -> mapM_ (\f -> hWriteFasta stdout . sffToSequence =<< readSFF f) files+    ["-R"] -> mapM_ (\f -> writeFastaQual (f++".fasta") (f++".qual") . sffToSequence =<< readSFF f) files     ["-q"] -> mapM_ (\f -> hWriteFastQ stdout . sffToSequence =<< readSFF f) files-    ["-f"] -> LB.putStrLn . LB.fromChunks . intersperse (B.pack "\n") . concat =<< mapM showflow files+    ["-f"] -> L1.putStrLn . L1.fromChunks . intersperse (B.pack "\n") . concat =<< mapM showflow files     ["-h"] -> mapM_ (\f -> (putStr . sffToHistogram) =<< readSFF f) files+    ["-s"] -> mapM_ (\f -> summarize =<< readSFF f) files -    _ -> error ("Usage: flower -[f|q|r] <file.sff> [<file2.sff> ..]\n"+    _ -> error ("Usage: flower -[f|q|r|R] <file.sff> [<file2.sff> ..]\n"                 ++"  -r  output reads in Fasta format\n"+                ++"  -R  output reads in Fasta format with associated .qual\n"+                ++"      (generates files instead of writing to <stdout>)\n"                 ++"  -q  output in FastQ format\n"                 ++"  -f  output the flowgram in tabular format\n"-                ++"  -h  output a histogram table of flow values")-tab :: ByteString-tab = B.pack "\t"+                ++"  -h  output a histogram table of flow values\n"+                ++"  -s  output a summary of each read"+               ) +-- ----------------------------------------------------------++summarize :: SFF -> IO ()+summarize (SFF _rh rs) = do+  putStrLn "# name........\tdate......\ttime....\treg\tx_loc\ty_loc\tlen\tqual"+  L1.putStrLn . toLazyByteString . mconcat . map sum1 $ rs++-- todo: date and time are usually constants!+sum1 :: ReadBlock -> Builder+sum1 r = let rh = read_header r+             nb = num_bases rh+             h = read_name rh +             rn = decodeReadName h+             (y,m,d) = date rn+             reg = region rn+             (hh,mm,ss) = time rn+         in mconcat ([fromByteString h, tb, putDate y m d, tb, putTime hh mm ss, tb, putInt2 reg+                     ,tb, putInt (fromIntegral $ x_loc rn), tb, putInt (fromIntegral $ y_loc rn), tb, putInt (fromIntegral nb)+                     ,tb, fromByteString (fi $ quals $ flowgram r), nl])++-- | Take the fractional parts of the flows, and sum their squares+quals :: [Flow] -> Flow+quals q = floor $ (*(100/fromIntegral (length q))) $ sqrt $ sum $ map (fromIntegral . (^2) . (flip (-) 50) . (`mod` 100) . (+50)) $ q++tb, nl :: Builder+tb = char '\t'+nl = char '\n'+ -- these are clumsy, since we just might need the file name showflow :: FilePath -> IO [ByteString] showflow f = return . {- map (\s -> B.concat [B.pack f,t,s]) . -} showrun =<< readSFF f@@ -50,9 +84,12 @@ showrun :: SFF -> [ByteString] showrun (SFF h rs) = concatMap (showread h) rs +tab :: ByteString+tab = B.pack "\t"+ showread :: CommonHeader -> ReadBlock -> [ByteString] showread h rd = let rn = read_name $ read_header rd-                    qgroups = qgroup (B1.unpack $ flow_index rd) (B1.unpack $ quality rd)+                    qgroups = qgroup (B1.unpack $ flow_index rd) (L1.unpack $ quality rd)                     format p c v q = B.concat [rn,tab,B.pack (show p),tab,B.pack [c],tab,fi v,tab,B.pack (show q)]                 in zipWith4 format [(1::Int)..] (unpack $ flow h) (flowgram rd) qgroups