aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorl-d-s <distefano.l@wehi.edu.au>2018-12-11 14:17:22 +1100
committerl-d-s <distefano.l@wehi.edu.au>2018-12-11 14:17:22 +1100
commitf0357e09b8c473b55d22c4632692fcc79021570d (patch)
tree9c92993d1f0c788a162159e6440ea958eae3e35d
parent6742864b8f92f5d7d56da4901486b7e83a271e23 (diff)
parent10bdecf6c1338d7f531ddf7b41da14dfe4a4ac33 (diff)
Merge branch 'master' of https://github.com/PapenfussLab/bionix
-rw-r--r--default.nix1
-rw-r--r--lib/qsub.nix22
-rw-r--r--test-tnpair.nix11
-rw-r--r--tools/bowtie-align.nix36
-rw-r--r--tools/bowtie-index.nix22
-rw-r--r--tools/bowtie.nix8
-rw-r--r--tools/gridss-annotateVariants.nix4
-rw-r--r--tools/gridss-assemble.nix2
-rw-r--r--tools/gridss-softClipsToSplitReads.nix2
-rw-r--r--tools/samtools-sort.nix2
10 files changed, 90 insertions, 20 deletions
diff --git a/default.nix b/default.nix
index 50b85a3..d607aa2 100644
--- a/default.nix
+++ b/default.nix
@@ -12,6 +12,7 @@ let
types = callBionix ./lib/types.nix {};
bwa = callBionix ./tools/bwa.nix {};
+ bowtie = callBionix ./tools/bowtie.nix {};
compression = callBionix ./tools/compression.nix {};
crumble = callBionix ./tools/crumble.nix {};
fastqc = callBionix ./tools/fastqc.nix {};
diff --git a/lib/qsub.nix b/lib/qsub.nix
index 4ef6dbc..f7b3c3e 100644
--- a/lib/qsub.nix
+++ b/lib/qsub.nix
@@ -5,17 +5,17 @@
args = let
script = writeScript "qsub-script" ''
#!${stdenv.shell}
- while [ ! -e ${tmpDir}/$PBS_JOBID ] ; do
+ while [ ! -e ${tmpDir}/qsub-$PBS_JOBID ] ; do
sleep ${toString sleepTime}
done
- TMPDIR=${tmpDir}/$PBS_JOBID
+ set -a
+ . ${tmpDir}/qsub-$PBS_JOBID/nix-set
+ set +a
+ TMPDIR=${tmpDir}/qsub-$PBS_JOBID
TEMP=$TMPDIR
TMP=$TMPDIR
NIX_BUILD_TOP=$TMPDIR
cd $TMPDIR
- set -a
- . nix-set
- set +a
${builder} ${lib.escapeShellArgs args} > qsub-stdout 2> qsub-stderr
echo $? > qsub-exit
'';
@@ -46,15 +46,15 @@
}
trap cleanup INT TERM EXIT
- cp -r $TMPDIR ${tmpDir}/$id
- set > ${tmpDir}/$id/nix-set
+ cp -r $TMPDIR ${tmpDir}/qsub-$id
+ set > ${tmpDir}/qsub-$id/nix-set
until qstat -f ''${id%%.} 2>&1 | grep "\(Unknown Job\|job_state = C\)" > /dev/null ; do
sleep ${toString sleepTime}
done
- cat ${tmpDir}/$id/qsub-stderr >&2
- cat ${tmpDir}/$id/qsub-stdout
- if [ -e ${tmpDir}/$id/qsub-exit ]; then
- exitCode=$(cat ${tmpDir}/$id/qsub-exit)
+ cat ${tmpDir}/qsub-$id/qsub-stderr >&2
+ cat ${tmpDir}/qsub-$id/qsub-stdout
+ if [ -e ${tmpDir}/qsub-$id/qsub-exit ]; then
+ exitCode=$(cat ${tmpDir}/qsub-$id/qsub-exit)
else
exitCode=1
fi
diff --git a/test-tnpair.nix b/test-tnpair.nix
index a6ea163..b01d61e 100644
--- a/test-tnpair.nix
+++ b/test-tnpair.nix
@@ -21,7 +21,9 @@ let
fetchfq = attrs: types.tagFiletype (types.filetype.fq {}) (fetchlocal attrs);
fetchfa = attrs: types.tagFiletype (types.filetype.fa {}) (fetchlocal attrs);
- alignWithRG = rg: bwa.align { ref = fetchfa ./example/ref.fa; flags = "-R'@RG\\tID:${rg}\\tSM:${rg}'";};
+ ref = fetchfa ./example/ref.fa;
+
+ alignWithRG = rg: bwa.align { inherit ref; flags = "-R'@RG\\tID:${rg}\\tSM:${rg}'";};
sort = samtools.sort {};
flagstat = samtools.flagstat {};
check = fastqc.check {};
@@ -35,7 +37,7 @@ let
};
normal = {name = "mysample2"; files = {
input1 = fetchfq ./example/sample2-1.fq;
- input2 = fetchfq ./example/sample2-1.fq;
+ input2 = fetchfq ./example/sample2-2.fq;
};
};
};
@@ -53,8 +55,9 @@ let
mkdir $out
ln -s ${tnpairResult.variants} $out/strelka
mkdir $out/alignments
- ln -s ${gridss.callVariants {} (with tnpairResult.alignments; [tumour])} $out/gridss
- ln -s ${gridss.call (with tnpairResult.alignments; [tumour])} $out/gridss2
+ ln -s ${bowtie.align {inherit ref;} tnpair.normal.files} $out/alignments/bowtie-normal.bam
+ ln -s ${gridss.callVariants {} (with tnpairResult.alignments; [normal tumour])} $out/gridss
+ ln -s ${gridss.call (with tnpairResult.alignments; [normal tumour])} $out/gridss2
ln -s ${samtools.merge {} [tnpairResult.alignments.tumour tnpairResult.alignments.normal]} $out/alignments/merged.bam
ln -s ${samtools.view { outfmt = types.toCram; } (tnpairResult.alignments.tumour)} $out/alignments/${tnpair.tumour.name}.cram
ln -s ${samtools.view { outfmt = types.toCram; } (tnpairResult.alignments.normal)} $out/alignments/${tnpair.normal.name}.cram
diff --git a/tools/bowtie-align.nix b/tools/bowtie-align.nix
new file mode 100644
index 0000000..456747a
--- /dev/null
+++ b/tools/bowtie-align.nix
@@ -0,0 +1,36 @@
+{ bionix
+, nixpkgs
+, ref
+, bamOutput ? true
+, flags ? null
+, indexAttrs ? {}
+}:
+
+{ input1
+, input2 ? null
+}:
+
+with nixpkgs;
+with lib;
+with bionix.types;
+with bionix.compression;
+
+let
+ fa = f: matchFiletype "bowtie2-ref" { fa = _: f; } f;
+ fq = f: matchFiletype "bowtie2-input" { fq = _: f; gz = matchFiletype' "bowtie2-input" { fq = _: f; }; } f;
+
+in stdenv.mkDerivation {
+ name = "bowtie2-align";
+ buildInputs = [ bowtie2 bc ] ++ optional bamOutput samtools;
+ buildCommand = ''
+ cores=$(echo $NIX_BUILD_CORES ${optionalString bamOutput "- 1"} | bc)
+ if [[ $cores -lt 1 ]] ; then
+ cores=1
+ fi
+ bowtie2 -x ${bionix.bowtie.index indexAttrs ref}/ref ${optionalString (flags != null) flags} --threads $cores \
+ ${if input2 != null then "-1 " + fq input1 + " -2 " + fq input2 else "-U " + fq input1} \
+ ${optionalString bamOutput "| samtools view -b"} \
+ > $out
+ '';
+ passthru.filetype = if bamOutput then filetype.bam {ref = ref; sorting = sort.name {};} else filetype.sam {ref = ref; sorting = sort.name {};};
+}
diff --git a/tools/bowtie-index.nix b/tools/bowtie-index.nix
new file mode 100644
index 0000000..98e529f
--- /dev/null
+++ b/tools/bowtie-index.nix
@@ -0,0 +1,22 @@
+{ bionix
+, nixpkgs
+, flags ? null
+, seed ? 42
+}:
+
+ref:
+
+with nixpkgs;
+with lib;
+with bionix.types;
+
+assert (matchFiletype "bowtie-index" { fa = _: true; } ref);
+
+stdenv.mkDerivation {
+ name = "bowtie-index";
+ buildInputs = [ bowtie2 ];
+ buildCommand = ''
+ mkdir $out
+ bowtie2-build --seed ${toString seed} --threads $NIX_BUILD_CORES ${optionalString (flags != null) flags} ${ref} $out/ref
+ '';
+}
diff --git a/tools/bowtie.nix b/tools/bowtie.nix
new file mode 100644
index 0000000..a9fa2e8
--- /dev/null
+++ b/tools/bowtie.nix
@@ -0,0 +1,8 @@
+{ bionix, nixpkgs }:
+
+with bionix;
+
+{
+ align = callBionix ./bowtie-align.nix;
+ index = callBionix ./bowtie-index.nix;
+}
diff --git a/tools/gridss-annotateVariants.nix b/tools/gridss-annotateVariants.nix
index d5390b9..e0a6f0f 100644
--- a/tools/gridss-annotateVariants.nix
+++ b/tools/gridss-annotateVariants.nix
@@ -5,7 +5,7 @@
, indexAttrs ? {}
, assemblyAttrs ? {}
, collectMetricsAttrs ? {}
-, softClipsToSplitReadsAttrs ? {}
+, softClipsToSplitReadsAttrs ? { flags = "REALIGN_ENTIRE_READ=true"; }
, identifyVariantsAttrs ? {}
, flags ? null
, config ? null
@@ -47,7 +47,7 @@ let
ln -s ${bionix.samtools.index indexAttrs input} $WRKDIR/$BASENAME.sv.bai
'';
- assembly = bionix.samtools.sort {} (softClipsToSplitReads softClipsToSplitReadsAttrs (bionix.samtools.sort { nameSort = true;} (bionix.gridss.assemble assemblyAttrs inputs)));
+ assembly = bionix.samtools.sort {} (softClipsToSplitReads softClipsToSplitReadsAttrs (bionix.gridss.assemble assemblyAttrs inputs));
in
assert (all sorted inputs);
diff --git a/tools/gridss-assemble.nix b/tools/gridss-assemble.nix
index 00408d6..f57bc12 100644
--- a/tools/gridss-assemble.nix
+++ b/tools/gridss-assemble.nix
@@ -57,5 +57,5 @@ stdenv.mkDerivation rec {
WORKING_DIR=$TMPDIR/ \
TMP_DIR=$TMPDIR/
'';
- passthru.filetype = filetype.bam { ref = ref; sorting = sort.coord {}; };
+ passthru.filetype = filetype.bam { ref = ref; sorting = sort.name {}; };
}
diff --git a/tools/gridss-softClipsToSplitReads.nix b/tools/gridss-softClipsToSplitReads.nix
index 68ea0a5..c5d8062 100644
--- a/tools/gridss-softClipsToSplitReads.nix
+++ b/tools/gridss-softClipsToSplitReads.nix
@@ -37,5 +37,5 @@ stdenv.mkDerivation rec {
${optionalString (config != null) ("OPTIONS_FILE=" + bionix.gridss.gridssConfig config)} \
WORKER_THREADS=$NIX_BUILD_CORES
'';
- passthru.filetype = filetype.bam { ref = ref; sorting = matchFileSorting "grids-softClipsToSplitReads" { coord = _: input.sorting; name = _: sort.none {}; none = _: input.sorting;} input;};
+ passthru.filetype = filetype.bam { ref = ref; sorting = sort.none {}; };
}
diff --git a/tools/samtools-sort.nix b/tools/samtools-sort.nix
index e77f3db..37df5c8 100644
--- a/tools/samtools-sort.nix
+++ b/tools/samtools-sort.nix
@@ -25,7 +25,7 @@ in stdenv.mkDerivation {
buildInputs = [ samtools ];
buildCommand =
if alreadySorted then
- "ln -s $out ${input}"
+ "ln -s ${input} $out"
else
''
samtools sort -@ $NIX_BUILD_CORES \