aboutsummaryrefslogtreecommitdiff
path: root/tools/bwa-mem.nix
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2018-09-26 10:53:53 +1000
committerJustin Bedo <cu@cua0.org>2018-09-26 10:53:53 +1000
commit98672cb1bba7221c5c8ecc363243cb47fcd13f47 (patch)
treec5c73fc08323a8350a0ba80aae7a7232fed19171 /tools/bwa-mem.nix
parent45af0256cf75fa28e75b6cf6874df0c48aac38cf (diff)
refactor, add mosdepth, and fixes for bwa
Diffstat (limited to 'tools/bwa-mem.nix')
-rw-r--r--tools/bwa-mem.nix40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/bwa-mem.nix b/tools/bwa-mem.nix
new file mode 100644
index 0000000..5a2772e
--- /dev/null
+++ b/tools/bwa-mem.nix
@@ -0,0 +1,40 @@
+{ stdenv
+, callPackage
+, lib
+, bc
+, bwa
+, samtools ? null
+, ref
+, bamOutput ? true
+, flags ? null
+}:
+
+{ input1
+, input2 ? null
+}:
+
+assert bamOutput -> samtools != null;
+
+with lib;
+
+let index = callPackage ./bwa-index.nix { inherit bwa stdenv lib; } ref;
+
+in stdenv.mkDerivation {
+ name = "bwa-mem";
+ buildInputs = [ bwa bc ] ++ optional bamOutput samtools;
+ buildCommand = ''
+ ln -s ${ref} ref.fa
+ for f in ${index}/* ; do
+ ln -s $f
+ done
+ cores=$(echo $NIX_BUILD_CORES ${optionalString bamOutput "- 1"} | bc)
+ if [[ $cores -lt 1 ]] ; then
+ >&2 echo "not enough build cores"
+ exit 1
+ fi
+ bwa mem ${optionalString (flags != null) flags} -t $cores ref.fa ${input1} \
+ ${optionalString (input2 != null) input2} \
+ ${optionalString bamOutput "| samtools view -b"} \
+ > $out
+ '';
+}