From 2c706aaad54aeec0f224ab7c313ac22aebe0bb9e Mon Sep 17 00:00:00 2001
From: Justin Bedo <cu@cua0.org>
Date: Fri, 26 Oct 2018 08:05:28 +1100
Subject: init: mutect

---
 tools/mutect-app.nix  | 32 ++++++++++++++++++++++++++++++++
 tools/mutect-call.nix | 42 ++++++++++++++++++++++++++++++++++++++++++
 tools/mutect.nix      |  9 +++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 tools/mutect-app.nix
 create mode 100644 tools/mutect-call.nix
 create mode 100644 tools/mutect.nix

(limited to 'tools')

diff --git a/tools/mutect-app.nix b/tools/mutect-app.nix
new file mode 100644
index 0000000..02c4f51
--- /dev/null
+++ b/tools/mutect-app.nix
@@ -0,0 +1,32 @@
+{stdenv, fetchurl, makeWrapper, unzip, fetchFromGitHub}:
+
+let
+  oldnix = import (fetchFromGitHub {
+    owner = "NixOS";
+    repo = "nixpkgs";
+    rev = "83a893c38a83877588e3ca7ccfeabaa973c30acd";
+    sha256 = "0q7214hag7h95irvhkdb648m09b9jspb0raw1qjrx7y4grzb165h";
+  }) {};
+
+  jre = oldnix.openjdk7;
+
+in stdenv.mkDerivation rec {
+  name = "mutect-${version}";
+  version = "1.1.5";
+
+  src = fetchurl {
+    url = "https://github.com/broadinstitute/mutect/releases/download/${version}/muTect-${version}-bin.zip";
+    sha256 = "1pq7iv720bp970qsyyshwk98xdb7naw566y6gk9cpj6bmm08z9v3";
+  };
+
+  buildInputs = [ makeWrapper jre unzip ];
+
+  unpackPhase = ''
+    unzip $src -d $TMPDIR
+  '';
+  installPhase = ''
+    install -Dt $out/libexec/mutect muTect-${version}.jar
+    mkdir $out/bin
+    makeWrapper ${jre}/bin/java $out/bin/mutect --add-flags "-jar $out/libexec/mutect/muTect-${version}.jar"
+  '';
+}
diff --git a/tools/mutect-call.nix b/tools/mutect-call.nix
new file mode 100644
index 0000000..9fd009b
--- /dev/null
+++ b/tools/mutect-call.nix
@@ -0,0 +1,42 @@
+{bionix
+, nixpkgs
+, cosmic
+, dbsnp}:
+
+with nixpkgs;
+with lib;
+
+let
+  inherit (bionix.types) matchFiletype;
+  getVCFref = matchFiletype "mutect-call" {vcf = {ref}: ref;};
+  getBAMref = matchFiletype "mutect-call" {bam = {ref, ...}: ref;};
+  refs = map getVCFref [ cosmic dbsnp ];
+  ref = head refs;
+in
+
+assert (length (unique refs) == 1);
+
+{normal, tumour}:
+
+assert (ref == getBAMref normal && ref == getBAMref tumour);
+
+stdenv.mkDerivation {
+  name = "mutect";
+  buildInputs = [ bionix.mutect.app ];
+  buildCommand = ''
+    ln -s ${normal} normal.bam
+    ln -s ${tumour} tumour.bam
+    ln -s ${dbsnp} dbsnp.vcf
+    ln -s ${cosmic} cosmic.vcf
+    ln -s ${ref} ref.fa
+    ln -s ${bionix.samtools.faidx {} ref} ref.fa.fai
+    ln -s ${bionix.samtools.dict {} ref} ref.dict
+    mutect --analysis_type MuTect \
+      --reference_sequence ref.fa \
+      --cosmic cosmic.vcf \
+      --dbsnp dbsnp.vcf \
+      --input_file:normal normal.bam \
+      --input_file:tumour tumour.bam \
+      --out $out
+  '';
+}
diff --git a/tools/mutect.nix b/tools/mutect.nix
new file mode 100644
index 0000000..9a8ce41
--- /dev/null
+++ b/tools/mutect.nix
@@ -0,0 +1,9 @@
+{bionix, nixpkgs}:
+
+with nixpkgs;
+with bionix;
+
+{
+  app = callPackage ./mutect-app.nix {inherit (nixpkgs) stdenv fetchurl makeWrapper unzip fetchFromGitHub;};
+  call = callBionix ./mutect-call.nix;
+}
-- 
cgit v1.2.3