diff options
-rw-r--r-- | lib/types.nix | 1 | ||||
-rw-r--r-- | tools/compression-gzip.nix | 13 | ||||
-rw-r--r-- | tools/compression.nix | 28 |
3 files changed, 36 insertions, 6 deletions
diff --git a/lib/types.nix b/lib/types.nix index 7e58ce0..11f4bf4 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -33,6 +33,7 @@ rec { vcf = { ref = any; }; bed = { ref = any; }; gz = filetype; + bgz = filetype; bz2 = filetype; }; diff --git a/tools/compression-gzip.nix b/tools/compression-gzip.nix index 0229b94..80fb9f4 100644 --- a/tools/compression-gzip.nix +++ b/tools/compression-gzip.nix @@ -1,12 +1,17 @@ -{ bionix }: +{ bionix, block ? false, flags ? "" }: with bionix; +with types; input: stage { name = "gzip"; - buildInputs = with pkgs; [ gzip ]; - buildCommand = "gzip < ${input} > $out"; - passthru.filetype = filetype.gzip input.filetype; + buildInputs = with pkgs; [ (if block then htslib else gzip) ]; + buildCommand = + if block then + "bgzip -c ${flags} ${input} > $out" + else + "gzip ${flags} < ${input} > $out"; + passthru.filetype = (if block then filetype.bgz else filetype.gz) input.filetype; } diff --git a/tools/compression.nix b/tools/compression.nix index c9c8777..b32d057 100644 --- a/tools/compression.nix +++ b/tools/compression.nix @@ -20,6 +20,7 @@ in vcf = _: f; bed = _: f; gz = _: gunzip attrs f; + bgz = _: gunzip attrs f; bz2 = _: bunzip2 attrs f; } f; @@ -36,10 +37,31 @@ in cram = _: gz; vcf = _: gz; bed = _: gz; - gz = x: x; + gz = _: f; + bgz = _: f; + bz2 = _: with compression; gzip { } (uncompress { } f); } f; + bgzip = attrs: f: + let gz = gzip (attrs // { block = true; }) f; + in + types.matchFiletype "compressed" + { + fa = _: gz; + fq = _: gz; + bam = _: gz; + sam = _: gz; + cram = _: gz; + vcf = _: gz; + bed = _: gz; + bgz = _: f; + gz = _: with compression; bgzip { } (uncompress { } f); + bz2 = _: with compression; bgzip { } (uncompress { } f); + } + f; + + bzip2 = attrs: f: let bz2 = bzip2 attrs f; in @@ -52,7 +74,9 @@ in cram = _: gz; vcf = _: gz; bed = _: gz; - bz2 = x: x; + bz2 = _: f; + bgz = _: with compression; bzip2 { } (uncompress { } f); + gz = _: with compression; bzip2 { } (uncompress { } f); } f; } |