module Biobase.Infernal.VerboseHit.Export where
import Control.Monad.Trans.Class (lift)
import Data.ByteString.Char8 as BS
import Data.Iteratee as I
import Data.Maybe
import Prelude as P
import Text.Printf
import Biobase.Infernal.VerboseHit
import Biobase.Infernal.VerboseHit.Internal
eneeByteString :: Monad m => Enumeratee [VerboseHit] BS.ByteString m a
eneeByteString = eneeByteStrings ><> mapChunks BS.concat
eneeByteStrings :: Monad m => Enumeratee [VerboseHit] [ByteString] m a
eneeByteStrings = unfoldConvStream f (AliGo BS.empty BS.empty '?') where
f acc = do
h <- I.head
let na = newAcc acc h
return (fst na , return . BS.unlines $ snd na ++ [showVerboseHit h])
newAcc a@(AliGo{..}) h@VerboseHit{..}
| otherwise = ( AliGo vhCM vhScaffold vhStrand, ls )
where ls = [ "//" | aliCM /= BS.empty && aliCM /= vhCM ] ++
[ "CM: " `BS.append` vhCM | aliCM /= vhCM ] ++
[ ">" `BS.append` vhScaffold `BS.append` "\n" | aliScaffold /= vhScaffold ] ++
[ str `BS.append` " strand results:\n" | aliStrand /= vhStrand ]
str
| vhStrand == '+' = "Plus"
| vhStrand == '-' = "Minus"
| otherwise = "Unknown"
showVerboseHit :: VerboseHit -> BS.ByteString
showVerboseHit VerboseHit{..} = BS.unlines
[ BS.pack $ printf " Query = %d - %d, Target = %d - %d"
(fst vhQuery) (snd vhQuery) (fst vhTarget) (snd vhTarget)
, BS.pack $ printf " Score = %.2f, E = %f, P = %.4e, GC = %d"
vhScore vhEvalue vhPvalue vhGC
, ""
, ws11 `BS.append` vhWuss
, (BS.pack $ printf "%10d " (fst vhQuery))
`BS.append` vhConsensus
`BS.append` (BS.pack $ printf " %d" (snd vhQuery))
, ws11 `BS.append` vhScoring
, (BS.pack $ printf "%10d " (fst vhTarget))
`BS.append` vhSequence
`BS.append` (BS.pack $ printf " %d" (snd vhTarget))
] where
ws11 = BS.pack $ P.replicate 11 ' '