aboutsummaryrefslogtreecommitdiff
path: root/tools/last-align.nix
blob: b32687741719d52d2afa67618f1f8603484f6de6 (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
{ bionix
, ref
, flags ? null
, indexAttrs ? { }
}:

{ input1
, input2 ? null
}:

with bionix;
with lib;
with types;

let
  fa = f: matchFiletype "last-ref" { fa = _: f; } f;
  fq = f: matchFiletype "last-input" { fq = _: f; } f;
  fqfa = f: matchFiletype "last-input" { fq = _: f; fa = _: f; } f;
  Q = matchFiletype "last-input" { fq = _: 1; fa = _: 0; };
  parallel = matchFiletype "last-input" { fq = _: "parallel-fastq"; fa = _: "parallel-fasta"; };

in
stage {
  name = "last-align";
  buildInputs = with pkgs; [ last ];
  buildCommand = ''
    ${if (input2 != null) then "fastq-interleave ${fq input1} ${fq input2}" else "cat ${fa input1}"} | \
      ${parallel input1} -j $NIX_BUILD_CORES \
      lastal -Q${toString (Q input1)} \
        ${optionalString (input2 != null) "-i1"} \
        ${optionalString (flags != null) flags} \
        ${bionix.lastal.index indexAttrs ref}/index \
        > tmp
  '' + (if input2 == null then ''
    cp tmp $out
  '' else ''
    last-pair-probs tmp > $out
  '');
  passthru.multicore = true;
}