From 7c29ef494f974b457bfef6a5af7d37fa03bb7952 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Thu, 29 Jul 2021 16:19:30 +1000 Subject: initial import --- xenomapper.hs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 xenomapper.hs (limited to 'xenomapper.hs') diff --git a/xenomapper.hs b/xenomapper.hs new file mode 100644 index 0000000..123b1a5 --- /dev/null +++ b/xenomapper.hs @@ -0,0 +1,41 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ViewPatterns #-} +module Main where + +import Bio.Prelude hiding ((.)) +import Bio.Bam +import Control.Monad +import Control.Monad.Log +import Control.Monad.IO.Class +import System.Environment +import qualified Streaming.Prelude as S +import Streaming.Prelude (Stream, Of) + +filterBams :: (MonadIO m, MonadLog m, MonadMask m) => Stream (Of BamRaw) m () -> Stream (Of BamRaw) m () -> Stream (Of BamRaw) m () +filterBams a b = do + str0 <- lift $ S.next a + str1 <- lift $ S.next b + loop str0 str1 + where + loop a@(Right (a', a'')) b@(Right (b', b'')) = + case compare (qname a') (qname b') of + EQ -> do + when (as a' > as b') $ S.yield a' + filterBams a'' b'' + LT -> do + n <- lift $ S.next a'' + loop n b + GT -> do + n <- lift $ S.next b'' + loop a n + + loop _ _ = return () + + qname = b_qname . unpackBam + as = extAsInt 0 "AS" . unpackBam + +main = do + args <- getArgs + + withLogging_ (LoggingConf Warning Error Error 10 True) $ do + decodeBamFiles args (\[(hdr, prim), (_, sec)] -> writeBamFile "primary.bam" hdr $ filterBams prim sec) -- cgit v1.2.3