aboutsummaryrefslogtreecommitdiff
path: root/tools/mosdepth-depth.nix
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mosdepth-depth.nix')
-rw-r--r--tools/mosdepth-depth.nix51
1 files changed, 33 insertions, 18 deletions
diff --git a/tools/mosdepth-depth.nix b/tools/mosdepth-depth.nix
index 2a72989..4627071 100644
--- a/tools/mosdepth-depth.nix
+++ b/tools/mosdepth-depth.nix
@@ -1,21 +1,36 @@
-{ bionix
-, indexAttrs ? { }
-, flags ? null
+{
+ bionix,
+ indexAttrs ? {},
+ targets ? null,
+ flags ? null,
}:
-
with bionix;
with lib;
-
-input:
-
-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 (flags != null) flags} $out/out input.bam
- '';
- passthru.multicore = true;
-}
+ 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;
+ }