aboutsummaryrefslogtreecommitdiff
path: root/tools/cnvkit-batch.nix
blob: 114b6b9a8609023f7f49159166b1db734a76bbb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{bionix
,targets ? null
,annotations ? null
,flags ? null
,indexAttrs ? {}}:

{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) "--annotate ${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 *.cn{r,s,n} $out
  '';
  passthru.multicore = true;
}