From a1d18efc18772a233aa759b622c3a9960824f109 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Tue, 30 Apr 2019 09:47:49 +1000 Subject: cleanup examples and stray files --- examples/ex-nextflow/nextflow-example1.nix | 30 ++++++++++++++++ examples/ex-tnpair/tnpair | 58 ++++++++++++++++++++++++++++++ examples/ex-tnpair/tnpair.nix | 26 ++++++++++++++ examples/ex-wdl/wdl-scatter-gather.nix | 33 +++++++++++++++++ examples/tnpair | 58 ------------------------------ examples/tnpair.nix | 26 -------------- 6 files changed, 147 insertions(+), 84 deletions(-) create mode 100644 examples/ex-nextflow/nextflow-example1.nix create mode 100755 examples/ex-tnpair/tnpair create mode 100644 examples/ex-tnpair/tnpair.nix create mode 100644 examples/ex-wdl/wdl-scatter-gather.nix delete mode 100755 examples/tnpair delete mode 100644 examples/tnpair.nix (limited to 'examples') diff --git a/examples/ex-nextflow/nextflow-example1.nix b/examples/ex-nextflow/nextflow-example1.nix new file mode 100644 index 0000000..b31984a --- /dev/null +++ b/examples/ex-nextflow/nextflow-example1.nix @@ -0,0 +1,30 @@ +# This is a translation of the Nextflow example found at +# https://www.nextflow.io/example1.html +{ bionix ? import {} +, input ? ./sample.fa}: + +with bionix; +with lib; + +let + splitSequences = fa: stage { + name = "splitSequences"; + buildInputs = [ pkgs.gawk ]; + buildCommand = '' + awk '/^>/{f="seq_"++d} {print > f}' ${fa} + mkdir $out + cp seq* $out + ''; + }; + + reverse = fa: stage { + name = "reverse"; + buildCommand = '' + ${pkgs.utillinux}/bin/rev ${fa} > $out + ''; + }; + +in pipe [ + splitSequences + (each reverse) +] input diff --git a/examples/ex-tnpair/tnpair b/examples/ex-tnpair/tnpair new file mode 100755 index 0000000..5b84d5c --- /dev/null +++ b/examples/ex-tnpair/tnpair @@ -0,0 +1,58 @@ +#!/bin/sh + +set -e + +if [[ $# -ne 5 ]] ; then + echo "Usage: $0 ref normal1 normal2 tumour1 tumour2" + exit 1 +fi + +function cleanup { + if [[ -e tnpair-$$ ]]; then + rm tnpair-$$ + fi +} +trap cleanup INT TERM EXIT + +ref=`readlink -f $1` +norm1=`readlink -f $2` +norm2=`readlink -f $3` +tumour1=`readlink -f $4` +tumour2=`readlink -f $5` + +refhash=`nix-hash --base32 --type sha256 --flat $ref` +norm1hash=`nix-hash --base32 --type sha256 --flat $norm1` +norm2hash=`nix-hash --base32 --type sha256 --flat $norm2` +tumour1hash=`nix-hash --base32 --type sha256 --flat $tumour1` +tumour2hash=`nix-hash --base32 --type sha256 --flat $tumour2` + +cat > tnpair-$$ < {} +, normal +, tumour +, ref +}: + +with bionix; +with lib; + +let + input = mapAttrs (_: fetchFastQGZ); + + preprocess = pipe [ + input + (bwa.align { ref = fetchFastA ref; }) + (samtools.fixmate {}) + (samtools.sort {}) + (samtools.markdup {}) + ]; + +in linkDrv [ + (ln (strelka.call {} {normal = preprocess normal; tumour = preprocess tumour;}) "strelka") + (ln (preprocess normal) "normal.bam") + (ln (preprocess tumour) "tumour.bam") +] diff --git a/examples/ex-wdl/wdl-scatter-gather.nix b/examples/ex-wdl/wdl-scatter-gather.nix new file mode 100644 index 0000000..387d382 --- /dev/null +++ b/examples/ex-wdl/wdl-scatter-gather.nix @@ -0,0 +1,33 @@ +# The scatter-gather example from https://github.com/openwdl/wdl +# translated to bionix +{ bionix ? import {} }: + +with bionix; +with lib; + +let + + prepare = splitString "\n" (removeSuffix "\n" (readFile (stage { + name = "prepare"; + buildInputs = [ pkgs.python3 ]; + buildCommand = '' + python -c "print('one\ntwo\nthree\nfour', end=''')" > $out + ''; + }))); + + analysis = str: removeSuffix "\n" (readFile (stage { + name = "analysis"; + buildInputs = [ pkgs.python ]; + buildCommand = '' + python -c "print('_${str}_')" > $out + ''; + })); + + gather = strs: stage { + name = "gather"; + buildCommand = '' + echo ${concatStringsSep " " strs} > $out + ''; + }; + +in gather (map analysis prepare) diff --git a/examples/tnpair b/examples/tnpair deleted file mode 100755 index 5b84d5c..0000000 --- a/examples/tnpair +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh - -set -e - -if [[ $# -ne 5 ]] ; then - echo "Usage: $0 ref normal1 normal2 tumour1 tumour2" - exit 1 -fi - -function cleanup { - if [[ -e tnpair-$$ ]]; then - rm tnpair-$$ - fi -} -trap cleanup INT TERM EXIT - -ref=`readlink -f $1` -norm1=`readlink -f $2` -norm2=`readlink -f $3` -tumour1=`readlink -f $4` -tumour2=`readlink -f $5` - -refhash=`nix-hash --base32 --type sha256 --flat $ref` -norm1hash=`nix-hash --base32 --type sha256 --flat $norm1` -norm2hash=`nix-hash --base32 --type sha256 --flat $norm2` -tumour1hash=`nix-hash --base32 --type sha256 --flat $tumour1` -tumour2hash=`nix-hash --base32 --type sha256 --flat $tumour2` - -cat > tnpair-$$ < {} -, normal -, tumour -, ref -}: - -with bionix; -with lib; - -let - input = mapAttrs (_: fetchFastQGZ); - - preprocess = pipe [ - input - (bwa.align { ref = fetchFastA ref; }) - (samtools.fixmate {}) - (samtools.sort {}) - (samtools.markdup {}) - ]; - -in linkDrv [ - (ln (strelka.call {} {normal = preprocess normal; tumour = preprocess tumour;}) "strelka") - (ln (preprocess normal) "normal.bam") - (ln (preprocess tumour) "tumour.bam") -] -- cgit v1.2.3