aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2021-07-29 16:19:30 +1000
committerJustin Bedo <cu@cua0.org>2021-07-29 16:19:30 +1000
commit7c29ef494f974b457bfef6a5af7d37fa03bb7952 (patch)
tree75362d1414bb373c50a54982f69aa31c558bf027
initial import
-rw-r--r--biohazard.patch13
-rw-r--r--default.nix21
-rw-r--r--shell.nix12
-rw-r--r--xenomapper.hs41
4 files changed, 87 insertions, 0 deletions
diff --git a/biohazard.patch b/biohazard.patch
new file mode 100644
index 0000000..b075312
--- /dev/null
+++ b/biohazard.patch
@@ -0,0 +1,13 @@
+diff --git a/Control/Monad/Log.hs b/Control/Monad/Log.hs
+index 5b6598a..de4589f 100644
+--- a/Control/Monad/Log.hs
++++ b/Control/Monad/Log.hs
+@@ -14,7 +14,7 @@ module Control.Monad.Log
+ , panic
+ ) where
+
+-import BasePrelude hiding ( try, catchIOError )
++import BasePrelude hiding ( try, catchIOError, option )
+ import Control.Monad.Base ( MonadBase(..) )
+ import Control.Monad.Catch
+ import Control.Monad.Primitive
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..3314d66
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,21 @@
+let
+ pkgs = import <nixpkgs> { };
+
+ ghc = with pkgs.haskell.lib;
+ pkgs.ghc.withPackages (pkgs:
+ with pkgs;
+ [
+ (doJailbreak (markUnbroken
+ (biohazard.overrideAttrs (_: { patches = [ ./biohazard.patch ]; }))))
+ ]);
+in pkgs.stdenv.mkDerivation {
+ name = "xenomapper-hs";
+ buildInputs = [ ghc ];
+ src = ./.;
+ buildPhase = ''
+ ghc -O3 xenomapper.hs -o xenomapper
+ '';
+ installPhase = ''
+ install -D xenomapper $out/bin/xenomapper
+ '';
+}
diff --git a/shell.nix b/shell.nix
new file mode 100644
index 0000000..40ee189
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,12 @@
+let
+ pkgs = import <nixpkgs> { };
+
+ ghc = with pkgs.haskell.lib;
+ pkgs.ghc.withPackages (pkgs:
+ with pkgs;
+ [
+ hlint
+ (doJailbreak (markUnbroken
+ (biohazard.overrideAttrs (_: { patches = [ ./biohazard.patch ]; }))))
+ ]);
+in pkgs.mkShell { buildInputs = [ ghc ]; }
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)