aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2018-09-20 13:57:12 +1000
committerJustin Bedo <cu@cua0.org>2018-09-20 14:34:36 +1000
commit33a121a7bad5b2608cc41ce60ab3d65676541fa6 (patch)
treedbbce4154a85988f3bfd9b13d42ad5d37f04e18a /tools
parentf0a8a4de59ea79f56e074ddd16eff0ce1782dfe8 (diff)
Wrap some tools and make an example pipeline
Diffstat (limited to 'tools')
-rw-r--r--tools/bwa-index.nix19
-rw-r--r--tools/bwa.nix34
-rw-r--r--tools/platypus.nix33
-rw-r--r--tools/samtools-faidx.nix18
-rw-r--r--tools/samtools-index.nix20
-rw-r--r--tools/samtools-sort.nix19
6 files changed, 143 insertions, 0 deletions
diff --git a/tools/bwa-index.nix b/tools/bwa-index.nix
new file mode 100644
index 0000000..8ca0eec
--- /dev/null
+++ b/tools/bwa-index.nix
@@ -0,0 +1,19 @@
+{ stdenv
+, lib
+, bwa
+}:
+
+ref:
+
+with lib;
+
+stdenv.mkDerivation {
+ name = "bwa-index";
+ buildInputs = [ bwa ];
+ buildCommand = ''
+ ln -s ${ref} ref.fa
+ bwa index ref.fa
+ mkdir $out
+ mv ref.fa.* $out
+ '';
+}
diff --git a/tools/bwa.nix b/tools/bwa.nix
new file mode 100644
index 0000000..20a308f
--- /dev/null
+++ b/tools/bwa.nix
@@ -0,0 +1,34 @@
+{ stdenv
+, callPackage
+, lib
+, 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 ] ++ optional bamOutput samtools;
+ buildCommand = ''
+ ln -s ${ref} ref.fa
+ for f in ${index}/* ; do
+ ln -s $f
+ done
+ bwa mem ${optionalString (flags != null) flags} -t $NIX_BUILD_CORES ref.fa ${input1} \
+ ${optionalString (input2 != null) input2} \
+ ${optionalString bamOutput "| samtools view -b"} \
+ > $out
+ '';
+}
diff --git a/tools/platypus.nix b/tools/platypus.nix
new file mode 100644
index 0000000..3e150d2
--- /dev/null
+++ b/tools/platypus.nix
@@ -0,0 +1,33 @@
+{ stdenv
+, callPackage
+, lib
+, platypus
+, ref
+, index ? callPackage ./samtools-faidx.nix {}
+, bamIndex ? callPackage ./samtools-index.nix {}
+, flags ? null
+}:
+
+inputs:
+
+with lib;
+
+let filename = path: last (splitString "/" path);
+
+in stdenv.mkDerivation {
+ name = "platypus";
+ buildInputs = [ platypus ];
+ buildCommand = ''
+ ln -s ${ref} ref.fa
+ ln -s ${index ref} ref.fa.fai
+ ${concatMapStringsSep "\n" (p: "ln -s ${p} ${filename p}.bam") inputs}
+ ${concatMapStringsSep "\n" (p: "ln -s ${bamIndex p} ${filename p}.bai") inputs}
+ ls -l
+ platypus callVariants \
+ --nCPU=$NIX_BUILD_CORES \
+ --refFile=ref.fa \
+ ${optionalString (flags != null) flags} \
+ -o $out \
+ --bamFiles=${concatMapStringsSep "," (p: "${filename p}.bam") inputs}
+ '';
+}
diff --git a/tools/samtools-faidx.nix b/tools/samtools-faidx.nix
new file mode 100644
index 0000000..0dc03ee
--- /dev/null
+++ b/tools/samtools-faidx.nix
@@ -0,0 +1,18 @@
+{ stdenv
+, callPackage
+, lib
+, samtools
+, flags ? null
+}:
+
+input:
+
+with lib;
+
+stdenv.mkDerivation {
+ name = "samtools-faidx";
+ buildInputs = [ samtools ];
+ buildCommand = ''
+ samtools faidx ${optionalString (flags != null) flags} ${input} > $out
+ '';
+}
diff --git a/tools/samtools-index.nix b/tools/samtools-index.nix
new file mode 100644
index 0000000..2fd066f
--- /dev/null
+++ b/tools/samtools-index.nix
@@ -0,0 +1,20 @@
+{ stdenv
+, callPackage
+, lib
+, samtools
+, flags ? null
+}:
+
+input:
+
+with lib;
+
+stdenv.mkDerivation {
+ name = "samtools-index";
+ buildInputs = [ samtools ];
+ buildCommand = ''
+ ln -s ${input} input.bam
+ samtools index -@ $NIX_BUILD_CORES ${optionalString (flags != null) flags} input.bam
+ cp input.bam.bai $out
+ '';
+}
diff --git a/tools/samtools-sort.nix b/tools/samtools-sort.nix
new file mode 100644
index 0000000..1a79c9f
--- /dev/null
+++ b/tools/samtools-sort.nix
@@ -0,0 +1,19 @@
+{ stdenv
+, callPackage
+, lib
+, samtools
+, nameSort ? false
+, flags ? null
+}:
+
+input:
+
+with lib;
+
+stdenv.mkDerivation {
+ name = "samtools-sort";
+ buildInputs = [ samtools ];
+ buildCommand = ''
+ samtools sort -@ $NIX_BUILD_CORES ${optionalString nameSort "-n"} ${optionalString (flags != null) flags} ${input} > $out
+ '';
+}