diff options
author | l-d-s <distefano.l@wehi.edu.au> | 2018-11-13 09:10:23 +1100 |
---|---|---|
committer | l-d-s <distefano.l@wehi.edu.au> | 2018-11-13 09:10:23 +1100 |
commit | 2c92dd5c6425c67a18ab07eba7f15c07dbd4614a (patch) | |
tree | 46be9656b500e38bd4aa47066ce8296a127dd5bf /tools/samtools-sort.nix | |
parent | 886af7beaaa98ac32db88a7453d917409cf11ae8 (diff) | |
parent | 4574deb8e1649eaf63df424585d11645c7cfa7dd (diff) |
Merge branch 'master' of https://github.com/PapenfussLab/bionix
Diffstat (limited to 'tools/samtools-sort.nix')
-rw-r--r-- | tools/samtools-sort.nix | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/tools/samtools-sort.nix b/tools/samtools-sort.nix index ab9d603..5a02dab 100644 --- a/tools/samtools-sort.nix +++ b/tools/samtools-sort.nix @@ -11,7 +11,7 @@ with nixpkgs; with lib; let - inherit (bionix.types) matchFiletype coordSort; + inherit (bionix.types) matchFiletype coordSort matchFileSorting; in assert (matchFiletype "samtools-sort" { bam = _: true; sam = _: true; cram = _: true; } input); @@ -19,11 +19,20 @@ assert (matchFiletype "samtools-sort" { bam = _: true; sam = _: true; cram = _: 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;}; + alreadySorted = matchFileSorting "samtools-sort" { name = _: nameSort; coord = _: !nameSort; } input; in stdenv.mkDerivation { name = "samtools-sort"; buildInputs = [ samtools ]; - buildCommand = '' - samtools sort -@ $NIX_BUILD_CORES ${optionalString nameSort "-n"} ${outFmtFlags} ${optionalString (flags != null) flags} ${input} > $out - ''; + buildCommand = + if alreadySorted then + "ln -s $out ${input}" + else + '' + 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; } |