From 5cb6f6001ea3aefd52ebaf42c1714343d51a8822 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Thu, 10 Jan 2019 11:47:05 +1100 Subject: cnvkit: init --- default.nix | 6 +-- tools/cnvkit-app.nix | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/cnvkit-batch.nix | 41 ++++++++++++++++++++ tools/cnvkit.nix | 8 ++++ 4 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 tools/cnvkit-app.nix create mode 100644 tools/cnvkit-batch.nix create mode 100644 tools/cnvkit.nix diff --git a/default.nix b/default.nix index c50e063..3ed2b50 100644 --- a/default.nix +++ b/default.nix @@ -13,8 +13,9 @@ let types = callBionix ./lib/types.nix {}; - bwa = callBionix ./tools/bwa.nix {}; bowtie = callBionix ./tools/bowtie.nix {}; + bwa = callBionix ./tools/bwa.nix {}; + cnvkit = callBionix ./tools/cnvkit.nix {}; compression = callBionix ./tools/compression.nix {}; crumble = callBionix ./tools/crumble.nix {}; fastqc = callBionix ./tools/fastqc.nix {}; @@ -25,9 +26,8 @@ let mutect = callBionix ./tools/mutect.nix {}; platypus = callBionix ./tools/platypus.nix {}; samtools = callBionix ./tools/samtools.nix {}; - strelka = callBionix ./tools/strelka.nix {}; snpeff = callBionix ./tools/snpeff.nix {}; - + strelka = callBionix ./tools/strelka.nix {}; ref = callBionix ./lib/references.nix {}; qsub = attrs: bionix.extend (self: super: with self; rec { diff --git a/tools/cnvkit-app.nix b/tools/cnvkit-app.nix new file mode 100644 index 0000000..d44c508 --- /dev/null +++ b/tools/cnvkit-app.nix @@ -0,0 +1,102 @@ +{ lib +, fetchurl +, rPackages +, rWrapper +, buildPythonPackage +, fetchPypi +, biopython +, six +, numpy +, scipy +, pandas +, matplotlib +, reportlab +, zlib +, bzip2 +, htslib +, libjpeg +, pkgconfig +, futures +}: + +let pyfaidx = buildPythonPackage rec { + pname = "pyfaidx"; + version = "0.5.3.1"; + + src = fetchPypi { + inherit pname version; + sha256 = "0mjbksbj9hh2cf0yjr951cjahhn0lg7p71kd3kvbnscqyxa44kfr"; + }; + + propagatedBuildInputs = [ six ]; + }; + + pysam = buildPythonPackage rec { + pname = "pysam"; + version = "0.14"; + + src = fetchPypi { + inherit pname version; + sha256 = "11snrwl5pn6knarf0c7zcpkhc7rijb6cfpw8sl3pdvnynj1fmj69"; + }; + + buildInputs = [ zlib ]; + + preConfigure = '' + export HTSLIB_MODE="external" + export HTSLIB_LIBRARY_DIR=${htslib}/lib + export HTSLIB_INCLUDE_DIR=${htslib}/include + ''; + + }; + + future = buildPythonPackage rec { + pname = "future"; + version = "0.16.0"; + + doCheck = false; + + src = fetchPypi { + inherit pname version; + sha256 = "1nzy1k4m9966sikp0qka7lirh8sqrsyainyf8rk97db7nwdfv773"; + }; + }; + + pillow = buildPythonPackage rec { + pname = "Pillow"; + version = "5.0.0"; + + doCheck = false; + + src = fetchPypi { + inherit pname version; + sha256 = "1fz1n1cq65dqdbiwy1cn8l21amqbzq18rdmmcr670ks24dn9vwhj"; + }; + + buildInputs = [ zlib libjpeg pkgconfig ]; + }; + + cghFLasso = rPackages.buildRPackage rec { + name = "cghFLasso-${version}"; + version = "0.2-1"; + src = fetchurl { + url = "https://cran.r-project.org/src/contrib/Archive/cghFLasso/cghFLasso_${version}.tar.gz"; + sha256 = "0b1hnjf9g0v47hbz0dy9m6jhcl1ky20yyhhmm8myng2sndcpjsbf"; + }; + }; + + cnvR = rWrapper.override { + packages = with rPackages; [ DNAcopy cghFLasso ]; + }; + +in buildPythonPackage rec { + pname = "CNVkit"; + version = "0.9.5"; + + src = fetchPypi { + inherit pname version; + sha256 = "1sa70bmnxj1lzp33pbj3axk6n77czswwj9cirimxh2qrn84i7vs3"; + }; + + propagatedBuildInputs = [ biopython numpy scipy pandas matplotlib reportlab pyfaidx pysam futures future pillow cnvR ]; +} diff --git a/tools/cnvkit-batch.nix b/tools/cnvkit-batch.nix new file mode 100644 index 0000000..6b69f1a --- /dev/null +++ b/tools/cnvkit-batch.nix @@ -0,0 +1,41 @@ +{bionix +,normals ? [] +,targets ? null +,annotations ? null +,flags ? null +,indexAttrs ? {}}: + +{normals ? normals, tumours}: + +with bionix; +with lib; +with types; + +let + getref = f: matchFiletype "cnvkit-batch" { bam = {ref, ...}: ref; } f; + refs = map getref normals ++ map getref tumours; + ref = head refs; + sorted = matchFileSorting "cnvkit-batch" { coord = _: true; }; +in + +assert (length (unique refs) == 1); +assert (all sorted (normals ++ tumours)); + +stage { + name = "cnvkit"; + buildInputs = [ cnvkit.app ]; + buildCommand = '' + ln -s ${ref} ref.fa + ln -s ${samtools.faidx indexAttrs ref} ref.fa.fai + cnvkit.py batch ${concatStringsSep " " tumours} \ + ${optionalString (normals != []) ("-n " + concatStringsSep " " normals)} \ + ${optionalString (annotations != null) annotations} \ + ${if targets != null then "--targets ${targets}" else "-m wgs"} \ + -f ref.fa \ + -p $NIX_BUILD_CORES \ + -d $TMPDIR \ + ${optionalString (flags != null) flags} + mkdir $out + cp * $out + ''; +} diff --git a/tools/cnvkit.nix b/tools/cnvkit.nix new file mode 100644 index 0000000..610b18c --- /dev/null +++ b/tools/cnvkit.nix @@ -0,0 +1,8 @@ +{bionix}: + +with bionix; + +{ +app = lib.callPackageWith (pkgs // pkgs.pythonPackages) ./cnvkit-app.nix {}; + callCNV = callBionixE ./cnvkit-batch.nix; +} -- cgit v1.2.3