From 33a121a7bad5b2608cc41ce60ab3d65676541fa6 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Thu, 20 Sep 2018 13:57:12 +1000 Subject: Wrap some tools and make an example pipeline --- tools/bwa-index.nix | 19 +++++++++++++++++++ tools/bwa.nix | 34 ++++++++++++++++++++++++++++++++++ tools/platypus.nix | 33 +++++++++++++++++++++++++++++++++ tools/samtools-faidx.nix | 18 ++++++++++++++++++ tools/samtools-index.nix | 20 ++++++++++++++++++++ tools/samtools-sort.nix | 19 +++++++++++++++++++ 6 files changed, 143 insertions(+) create mode 100644 tools/bwa-index.nix create mode 100644 tools/bwa.nix create mode 100644 tools/platypus.nix create mode 100644 tools/samtools-faidx.nix create mode 100644 tools/samtools-index.nix create mode 100644 tools/samtools-sort.nix (limited to 'tools') 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 + ''; +} -- cgit v1.2.3