From 05da61d166d7d4702001510a5eaa1935102d24f0 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Mon, 16 Nov 2020 11:59:41 +1100 Subject: sambamba: init --- tools/sambamba-generic.nix | 28 ++++++++++++++++++++++++++++ tools/sambamba-sort.nix | 29 +++++++++++++++++++++++++++++ tools/sambamba.nix | 15 +++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tools/sambamba-generic.nix create mode 100644 tools/sambamba-sort.nix create mode 100644 tools/sambamba.nix (limited to 'tools') diff --git a/tools/sambamba-generic.nix b/tools/sambamba-generic.nix new file mode 100644 index 0000000..a6be65c --- /dev/null +++ b/tools/sambamba-generic.nix @@ -0,0 +1,28 @@ +{ bionix +, flags ? null +, tool +, region ? null +}: + +input: + +with bionix; +with lib; + +let + inherit (bionix.types) matchFiletype coordSort matchFileSorting; +in + +assert (matchFiletype "sambamba-${tool}" { bam = _: true; } input); + +stage { + name = "sambamba-${tool}"; + buildInputs = [ pkgs.sambamba ]; + buildCommand = '' + sambamba ${tool} -t $NIX_BUILD_CORES \ + ${optionalString (flags != null) flags} \ + ${if tool == "merge" then "$out ${concatStringsSep " " input}" else if tool == "slice" then "${input} ${region} > $out" else if tool == "flagstat" then "${input} > $out" else "${input} $out"} + ''; + passthru.filetype = if tool == "flagstat" || tool == "index" then null else if tool == "merge" then (head input).filetype else input.filetype; + passthru.multicore = true; +} diff --git a/tools/sambamba-sort.nix b/tools/sambamba-sort.nix new file mode 100644 index 0000000..efdd261 --- /dev/null +++ b/tools/sambamba-sort.nix @@ -0,0 +1,29 @@ +{ bionix +, nameSort ? false +, flags ? null +}: + +input: + +with bionix; +with lib; + +let + inherit (bionix.types) matchFiletype coordSort matchFileSorting; +in + +assert (matchFiletype "sambamba-sort" { bam = _: true; } input); + +stage { + name = "sambamba-sort"; + buildInputs = [ pkgs.sambamba ]; + buildCommand = '' + sambamba sort -t $NIX_BUILD_CORES \ + ${optionalString nameSort "-n"} \ + ${optionalString (flags != null) flags} \ + -o $out \ + ${input} + ''; + passthru.filetype = if nameSort then bionix.types.nameSort input.filetype else coordSort input.filetype; + passthru.multicore = true; +} diff --git a/tools/sambamba.nix b/tools/sambamba.nix new file mode 100644 index 0000000..552e6e3 --- /dev/null +++ b/tools/sambamba.nix @@ -0,0 +1,15 @@ +{ bionix }: + +with bionix; + +let + gen = callBionixE ./sambamba-generic.nix; + +in { + sort = callBionixE ./sambamba-sort.nix; + index = def gen {tool = "index"; }; + merge = def gen {tool = "merge"; }; + slice = def gen {tool = "slice"; }; + flagstat = def gen {tool = "flagstat"; }; + markdup = def gen {tool = "markdup"; }; +} -- cgit v1.2.3