-
Notifications
You must be signed in to change notification settings - Fork 1
/
FastaTool.hs
53 lines (42 loc) · 1.48 KB
/
FastaTool.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
import Data.Conduit as C
import Data.Conduit.Binary as C
import Data.Conduit.List as CL
import Prelude hiding (length)
import System.Console.CmdArgs
import System.IO (stdin,stdout)
import Text.Printf
import qualified Data.ByteString.Char8 as B
import Biobase.Fasta.Import
import Control.Monad.IO.Class (liftIO, MonadIO (..))
data Options
= Info
{ description :: Bool
, length :: Bool
}
deriving (Show,Data,Typeable)
info = Info
{ description = False &= help "print description, not just the indentifier"
, length = False &= help "print length of data section, too. will be last element."
}
main :: IO ()
main = do
o <- cmdArgs $ modes [info &= auto]
case o of
(Info d l) -> doInfo d l
doInfo d l = do
runResourceT
$ sourceHandle stdin
$= parseEvents 10000
$= CL.concatMapAccum (countChars d l) Nothing
$$ sinkHandle stdout
countChars showD showL = go where
go h@Header{} Nothing = ( Just (h,0) , [] )
go h@Header{} (Just (hold, k)) = ( Just (h,0), [prnt hold k] )
go (Data d) Nothing = ( Just (Header "" "",0), [] )
go (Data d) (Just (h, k)) = ( Just (h, k + B.length d), [] )
go Done Nothing = ( Nothing, [] )
go Done (Just (h, k)) = ( Nothing, [prnt h k] )
prnt hdr k = printHeader hdr `B.append` (B.pack $ if showL then printf " %8d" k else "") `B.append` "\n"