module Bio.Data.Bam
( Bam
, HeaderState
, runBam
, readBam
, writeBam
, bamToBed
) where
import Bio.Data.Bed
import Bio.HTS
import Bio.HTS.Types (Bam, FileHeader (..))
import Conduit
import Control.Monad.State (get, lift)
bamToBed :: Conduit Bam HeaderState BED
bamToBed = mapMC f =$= concatC
where
f bam = do
BamHeader hdr <- lift get
case getChr hdr bam of
Just chr ->
let start = fromIntegral $ position bam
end = fromIntegral $ endPos bam
nm = Just $ qName bam
strand = Just $ not $ isRev bam
in return $ Just $ BED chr start end nm Nothing strand
_ -> return Nothing