aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
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
+ '';
+}