diff options
Diffstat (limited to 'tools/samtools-sort.nix')
-rw-r--r-- | tools/samtools-sort.nix | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/samtools-sort.nix b/tools/samtools-sort.nix index 2de579e..ab9d603 100644 --- a/tools/samtools-sort.nix +++ b/tools/samtools-sort.nix @@ -2,6 +2,7 @@ , nixpkgs , nameSort ? false , flags ? null +, outfmt ? null }: input: @@ -9,10 +10,20 @@ input: with nixpkgs; with lib; -stdenv.mkDerivation { +let + inherit (bionix.types) matchFiletype coordSort; +in + +assert (matchFiletype "samtools-sort" { bam = _: true; sam = _: true; cram = _: true; } input); + +let + outfmtR = if outfmt != null then outfmt input else input.filetype; + outFmtFlags = matchFiletype "samtools-sort-outfmt" { bam = _: "-O BAM"; sam = _: "-O SAM"; cram = ref: "-O CRAM -T ${ref}"; } {filetype = outfmtR;}; +in stdenv.mkDerivation { name = "samtools-sort"; buildInputs = [ samtools ]; buildCommand = '' - samtools sort -@ $NIX_BUILD_CORES ${optionalString nameSort "-n"} ${optionalString (flags != null) flags} ${input} > $out + samtools sort -@ $NIX_BUILD_CORES ${optionalString nameSort "-n"} ${outFmtFlags} ${optionalString (flags != null) flags} ${input} > $out ''; + passthru.filetype = if nameSort then bionix.types.nameSort outfmtR else coordSort outfmtR; } |