aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/bwa-index.nix5
-rw-r--r--tools/bwa-mem.nix15
-rw-r--r--tools/compression.nix58
-rw-r--r--tools/crumble-toCram.nix15
-rw-r--r--tools/crumble.nix1
-rw-r--r--tools/gridss-callVariants.nix13
-rw-r--r--tools/gridss.nix2
-rw-r--r--tools/platypus-callVariants.nix20
-rw-r--r--tools/platypus.nix4
-rw-r--r--tools/samtools-faidx.nix3
-rw-r--r--tools/samtools-index.nix4
-rw-r--r--tools/samtools-sort.nix15
-rw-r--r--tools/samtools-view.nix27
-rw-r--r--tools/samtools.nix1
-rw-r--r--tools/strelka-call.nix15
15 files changed, 161 insertions, 37 deletions
diff --git a/tools/bwa-index.nix b/tools/bwa-index.nix
index 48a2556..c879bc4 100644
--- a/tools/bwa-index.nix
+++ b/tools/bwa-index.nix
@@ -7,12 +7,15 @@ ref:
with nixpkgs;
with lib;
+with bionix.types;
+
+assert (matchFiletype "bwa-index" { fa = _: true; } ref);
stdenv.mkDerivation {
name = "bwa-index";
buildInputs = [ bwa ];
buildCommand = ''
- ln -s ${ref.seq} ref.fa
+ ln -s ${ref} ref.fa
bwa index ${optionalString (flags != null) flags} ref.fa
mkdir $out
mv ref.fa.* $out
diff --git a/tools/bwa-mem.nix b/tools/bwa-mem.nix
index ca9e6a8..0d0f7d8 100644
--- a/tools/bwa-mem.nix
+++ b/tools/bwa-mem.nix
@@ -12,12 +12,18 @@
with nixpkgs;
with lib;
+with bionix.types;
+with bionix.compression;
-stdenv.mkDerivation {
+let
+ fa = f: matchFiletype "bwa-ref" { fa = _: f; } f;
+ fq = f: matchFiletype "bwa-input" { fq = _: f; } f;
+
+in stdenv.mkDerivation {
name = "bwa-mem";
buildInputs = [ bwa bc ] ++ optional bamOutput samtools;
buildCommand = ''
- ln -s ${ref.seq} ref.fa
+ ln -s ${fa ref} ref.fa
for f in ${bionix.bwa.index indexAttrs ref}/* ; do
ln -s $f
done
@@ -26,9 +32,10 @@ stdenv.mkDerivation {
>&2 echo "not enough build cores"
exit 1
fi
- bwa mem ${optionalString (flags != null) flags} -t $cores ref.fa ${input1} \
- ${optionalString (input2 != null) input2} \
+ bwa mem ${optionalString (flags != null) flags} -t $cores ref.fa ${fq input1} \
+ ${optionalString (input2 != null) (fq input2)} \
${optionalString bamOutput "| samtools view -b"} \
> $out
'';
+ passthru.filetype = if bamOutput then filetype.bam {ref = ref; sorting = option-sort.none;} else filetype.sam {ref = ref; sorting = option-sort.none;};
}
diff --git a/tools/compression.nix b/tools/compression.nix
new file mode 100644
index 0000000..aea7e13
--- /dev/null
+++ b/tools/compression.nix
@@ -0,0 +1,58 @@
+{bionix, nixpkgs}:
+
+with nixpkgs;
+with bionix;
+
+{
+ uncompress = f: types.matchFiletype "uncompress" {
+ fa = _: f;
+ fq = _: f;
+ bam = _: f;
+ sam = _: f;
+ cram = _: f;
+ vcf = _: f;
+ bed = _: f;
+ gz = _: types.tagFiletype (types.gunzip f.filetype) (stdenv.mkDerivation {
+ name = "gunzip";
+ buildCommand = "gunzip < ${f} > $out";
+ });
+ bz2 = _: types.tagFiletype (types.bunzip2 f.filetype) (stdenv.mkDerivation {
+ name = "bunzip2";
+ buildCommand = "bunzip2 < ${f} > $out";
+ });
+ } f.filetype;
+
+ gzip = f:
+ let
+ gz = (stdenv.mkDerivation {
+ name = "gzip";
+ buildCommand = "gzip < ${f} > $out";
+ passthru = { filetype = types.filetype.gz f.filetype; };
+ });
+ in types.matchFiletype "compressed" {
+ fa = _: gz;
+ fq = _: gz;
+ bam = _: gz;
+ sam = _: gz;
+ cram = _: gz;
+ vcf = _: gz;
+ bed = _: gz;
+ } f;
+
+ bzip2 = f:
+ let
+ bz2 = (stdenv.mkDerivation {
+ name = "bzip2";
+ buildCommand = "bzip2 < ${f} > $out";
+ passthru = { filetype = types.filetype.bz2 f.filetype; };
+ });
+ in types.matchFiletype "compressed" {
+ fa = _: gz;
+ fq = _: gz;
+ bam = _: gz;
+ sam = _: gz;
+ cram = _: gz;
+ vcf = _: gz;
+ bed = _: gz;
+ } f;
+}
diff --git a/tools/crumble-toCram.nix b/tools/crumble-toCram.nix
deleted file mode 100644
index 2544e17..0000000
--- a/tools/crumble-toCram.nix
+++ /dev/null
@@ -1,15 +0,0 @@
-{ bionix
-, nixpkgs
-, flags ? null
-}:
-
-with nixpkgs;
-with lib;
-
-input:
-
-stdenv.mkDerivation {
- name = "crumble";
- buildInputs = [ bionix.crumble.crumble ];
- buildCommand = "crumble ${optionalString (flags != null) flags} ${input} $out";
-}
diff --git a/tools/crumble.nix b/tools/crumble.nix
index fb48c8f..6031fca 100644
--- a/tools/crumble.nix
+++ b/tools/crumble.nix
@@ -5,5 +5,4 @@ with bionix;
{
crumble = callPackage ./crumble-app.nix {};
- toCram = callBionix ./crumble-toCram.nix;
}
diff --git a/tools/gridss-callVariants.nix b/tools/gridss-callVariants.nix
index c313c3f..799c930 100644
--- a/tools/gridss-callVariants.nix
+++ b/tools/gridss-callVariants.nix
@@ -1,16 +1,25 @@
{ bionix
, nixpkgs
-, ref
, blacklist ? null
, bwaIndexAttrs ? {}
, faidxAttrs ? {}
, flags ? null
}:
+with nixpkgs;
with lib;
+with bionix.types;
inputs:
+let
+ getref = matchFiletype "gridss-callVariants" { bam = x: x.ref; };
+ refs = map getref inputs;
+ ref = head refs;
+in
+
+assert (length (unique refs) == 1);
+
stdenv.mkDerivation rec {
name = "gridss-callVariants";
buildInputs = [ jre R bwa ];
@@ -19,7 +28,7 @@ stdenv.mkDerivation rec {
sha256 = "01srl3qvv060whqg1y1fpxjc5cwga5wscs1bmf1v3z87dignra7k";
};
buildCommand = ''
- ln -s ${ref.seq} ref.fa
+ ln -s ${ref} ref.fa
ln -s ${bionix.samtools.faidx faidxAttrs ref} ref.fa.fai
for f in ${bionix.bwa.index bwaIndexAttrs ref}/*; do
ln -s $f
diff --git a/tools/gridss.nix b/tools/gridss.nix
index edf9f57..7a2f217 100644
--- a/tools/gridss.nix
+++ b/tools/gridss.nix
@@ -3,5 +3,5 @@
with bionix;
{
- callVariants = callBiolnix ./gridss-callVariants.nix;
+ callVariants = callBionix ./gridss-callVariants.nix;
}
diff --git a/tools/platypus-callVariants.nix b/tools/platypus-callVariants.nix
index 7b68b28..a3e3a65 100644
--- a/tools/platypus-callVariants.nix
+++ b/tools/platypus-callVariants.nix
@@ -1,6 +1,5 @@
{ bionix
, nixpkgs
-, ref
, indexAttrs ? {}
, bamIndexAttrs ? {}
, flags ? null
@@ -8,16 +7,26 @@
inputs:
+with nixpkgs;
with lib;
+with bionix.types;
-let filename = path: last (splitString "/" path);
-in stdenv.mkDerivation {
+let
+ filename = path: last (splitString "/" path);
+ getref = f: matchFiletype "platypus-callVariants" { bam = r: r; } f;
+ refs = map getref inputs;
+ ref = head refs;
+in
+
+assert (length (unique refs) == 1);
+
+stdenv.mkDerivation {
name = "platypus";
buildInputs = [ platypus ];
buildCommand = ''
- ln -s ${ref.seq} ref.fa
- ln -s ${bionix.samtools.faix indexAttrs ref} ref.fa.fai
+ ln -s ${ref} ref.fa
+ ln -s ${bionix.samtools.faidx indexAttrs ref} ref.fa.fai
${concatMapStringsSep "\n" (p: "ln -s ${p} ${filename p}.bam") inputs}
${concatMapStringsSep "\n" (p: "ln -s ${bionix.samtools.index bamIndexAttrs p} ${filename p}.bai") inputs}
ls -l
@@ -28,4 +37,5 @@ in stdenv.mkDerivation {
-o $out \
--bamFiles=${concatMapStringsSep "," (p: "${filename p}.bam") inputs}
'';
+ passthru.filetype = filetype.vcf {ref = ref;};
}
diff --git a/tools/platypus.nix b/tools/platypus.nix
index 88d88d7..0dfe397 100644
--- a/tools/platypus.nix
+++ b/tools/platypus.nix
@@ -1,7 +1,7 @@
{ bionix, nixpkgs }:
-with nixpkgs;
+with bionix;
{
- call = attrs: callPackage ./platypus-callVariants.nix attrs;
+ call = callBionix ./platypus-callVariants.nix;
}
diff --git a/tools/samtools-faidx.nix b/tools/samtools-faidx.nix
index bf32bdf..1fde411 100644
--- a/tools/samtools-faidx.nix
+++ b/tools/samtools-faidx.nix
@@ -7,6 +7,9 @@ input:
with nixpkgs;
with lib;
+with bionix.types;
+
+assert (matchFiletype "samtools-faidx" { fa = _: true; } input);
stdenv.mkDerivation {
diff --git a/tools/samtools-index.nix b/tools/samtools-index.nix
index 4e09dc7..aad46a7 100644
--- a/tools/samtools-index.nix
+++ b/tools/samtools-index.nix
@@ -7,6 +7,10 @@ input:
with nixpkgs;
with lib;
+with bionix.types;
+
+assert (matchFiletype "samtools-index" { bam = _: true; } input);
+assert (matchSorting "samtools-index" { coord = _: true; } input);
stdenv.mkDerivation {
name = "samtools-index";
diff --git a/tools/samtools-sort.nix b/tools/samtools-sort.nix
index 2de579e..ab9d603 100644
--- a/tools/samtools-sort.nix
+++ b/tools/samtools-sort.nix
@@ -2,6 +2,7 @@
, nixpkgs
, nameSort ? false
, flags ? null
+, outfmt ? null
}:
input:
@@ -9,10 +10,20 @@ input:
with nixpkgs;
with lib;
-stdenv.mkDerivation {
+let
+ inherit (bionix.types) matchFiletype coordSort;
+in
+
+assert (matchFiletype "samtools-sort" { bam = _: true; sam = _: true; cram = _: true; } input);
+
+let
+ outfmtR = if outfmt != null then outfmt input else input.filetype;
+ outFmtFlags = matchFiletype "samtools-sort-outfmt" { bam = _: "-O BAM"; sam = _: "-O SAM"; cram = ref: "-O CRAM -T ${ref}"; } {filetype = outfmtR;};
+in stdenv.mkDerivation {
name = "samtools-sort";
buildInputs = [ samtools ];
buildCommand = ''
- samtools sort -@ $NIX_BUILD_CORES ${optionalString nameSort "-n"} ${optionalString (flags != null) flags} ${input} > $out
+ samtools sort -@ $NIX_BUILD_CORES ${optionalString nameSort "-n"} ${outFmtFlags} ${optionalString (flags != null) flags} ${input} > $out
'';
+ passthru.filetype = if nameSort then bionix.types.nameSort outfmtR else coordSort outfmtR;
}
diff --git a/tools/samtools-view.nix b/tools/samtools-view.nix
new file mode 100644
index 0000000..e1cdac1
--- /dev/null
+++ b/tools/samtools-view.nix
@@ -0,0 +1,27 @@
+{ bionix
+, nixpkgs
+, nameSort ? false
+, flags ? null
+, outfmt ? null
+}:
+
+input:
+
+with nixpkgs;
+with lib;
+with bionix.types;
+
+assert (matchFiletype "samtools-sort" { bam = _: true; sam = _: true; cram = _: true; } input);
+
+let
+ outfmtR = if outfmt != null then outfmt input else input.filetype;
+ fa = ref: matchFiletype "samtools-view-ref" { fa = _: ref; } ref;
+ outfmtFlags = matchFiletype "samtools-sort-outfmt" { bam = _: "-O BAM"; sam = _: "-O SAM"; cram = x: "-O CRAM -T ${fa x.ref}"; } {filetype = outfmtR;};
+in stdenv.mkDerivation {
+ name = "samtools-view";
+ buildInputs = [ samtools ];
+ buildCommand = ''
+ samtools view ${outfmtFlags} ${optionalString (flags != null) flags} ${input} > $out
+ '';
+ passthru.filetype = outfmtR;
+}
diff --git a/tools/samtools.nix b/tools/samtools.nix
index 6b08c6e..89a96b0 100644
--- a/tools/samtools.nix
+++ b/tools/samtools.nix
@@ -3,6 +3,7 @@
with bionix;
{
+ view = callBionix ./samtools-view.nix;
faidx = callBionix ./samtools-faidx.nix;
flagstat = callBionix ./samtools-flagstat.nix;
index = callBionix ./samtools-index.nix;
diff --git a/tools/strelka-call.nix b/tools/strelka-call.nix
index ecdea84..bcbb6d1 100644
--- a/tools/strelka-call.nix
+++ b/tools/strelka-call.nix
@@ -1,6 +1,5 @@
{ bionix
, nixpkgs
-, ref
, indexAttrs ? {}
, bamIndexAttrs ? {}
, flags ? null
@@ -10,17 +9,25 @@
with nixpkgs;
with lib;
+with bionix.types;
let
filename = path: last (splitString "/" path);
+ getref = f: matchFiletype "strelka-call" { bam = x: x.ref; } f;
inputs = [ normal tumour ];
+ refs = map getref inputs;
+ ref = head refs;
-in stdenv.mkDerivation {
+in
+
+assert (length (unique refs) == 1);
+
+stdenv.mkDerivation {
name = "strelka";
buildInputs = [ strelka ];
buildCommand = ''
- ln -s ${ref.seq} ref.fa
- ln -s ${bionix.samtools.faidx indexAttrs ref.seq} ref.fa.fai
+ ln -s ${ref} ref.fa
+ ln -s ${bionix.samtools.faidx indexAttrs ref} ref.fa.fai
${concatMapStringsSep "\n" (p: "ln -s ${p} ${filename p}.bam") inputs}
${concatMapStringsSep "\n" (p: "ln -s ${bionix.samtools.index bamIndexAttrs p} ${filename p}.bai") inputs}