aboutsummaryrefslogtreecommitdiff
path: root/tools/mosdepth-depth.nix
blob: 4627071230a68d8378a6554f928d45877259d201 (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
{
  bionix,
  indexAttrs ? {},
  targets ? null,
  flags ? null,
}:
with bionix;
with lib;
  input: let
    handleTarget = x: let
      type = builtins.typeOf x;
      handler = handlers."${type}" or (builtins.throw "mosdepth-depth:unhandled target type:${type}");
      handlers = {
        string = handleTarget [x];
        list = let
          file = pkgs.writeText "target.bed" (concatStringsSep "\n" x);
        in "-b ${file}";
        path = "-b ${x}";
        set = "-b ${x}";
      };
    in
      handler;
  in
    stage {
      name = "mosdepth-depth";
      buildInputs = with pkgs; [mosdepth];
      buildCommand = ''
        mkdir $out
        ln -s ${input} input.bam
        ln -s ${bionix.samtools.index indexAttrs input} input.bam.bai
        mosdepth -t $NIX_BUILD_CORES \
          ${optionalString (targets != null) (handleTarget targets)} \
          ${optionalString (flags != null) flags} $out/out input.bam
      '';
      passthru.multicore = true;
    }