From 92b4ea2ddac572f8bd830858132956829d92a734 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Wed, 24 Oct 2018 16:35:52 +1100 Subject: Simplify types for sorting --- lib/types.nix | 17 ++++++++--------- tools/bwa-mem.nix | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 8dabc4f..2e5adca 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -21,15 +21,13 @@ let in rec { - option-sort = option sorting; - matchFiletype = sym: y: x: if x ? filetype then match x.filetype (defError (idft sym) y filetype) else abort "unknown filetype for ${sym}"; filetype = make-type "filetype" { fa = {}; fq = {}; - bam = {ref = any; sorting = option-sort;}; - sam = {ref = any; sorting = option-sort;}; - cram = {ref = any; sorting = option-sort;}; + bam = {ref = any; sorting = sort;}; + sam = {ref = any; sorting = sort;}; + cram = {ref = any; sorting = sort;}; vcf = {ref = any;}; bed = {ref = any;}; gz = filetype; @@ -40,13 +38,14 @@ rec { toBam = matchFiletype "bam2cram" { bam = filetype.bam; sam = filetype.bam; cram = filetype.bam; }; toSam = matchFiletype "bam2cram" { bam = filetype.sam; sam = filetype.sam; cram = filetype.sam; }; - matchSorting = sym: y: let f = x: match x.sorting { some = z: match z (defError (idst sym) y sorting); none = abort "unknown sort for ${sym}"; }; in matchFiletype sym { bam = f; sam = f; cram = f; }; - sorting = make-type "sorting" { + matchSorting = sym: y: let f = x: match x.sorting (defError (idst sym) y sort); in matchFiletype sym { bam = f; sam = f; cram = f; }; + sort = make-type "sort" { + none = {}; coord = {}; name = {}; }; - coordSort = f: matchFiletype "coordSort" { bam = x: filetype.bam (x // {sorting = option-sort.some (sorting.coord {});}); } {filetype = f;}; - nameSort = f: matchFiletype "nameSort" { bam = x: filetype.bam (x // {sorting = option-sort.some (sorting.name {});}); } {filetype = f;}; + coordSort = f: matchFiletype "coordSort" { bam = x: filetype.bam (x // {sorting = sort.coord {};}); } {filetype = f;}; + nameSort = f: matchFiletype "nameSort" { bam = x: filetype.bam (x // {sorting = sort.name {};}); } {filetype = f;}; gunzip = matchFiletype "gunzip" { gz = x: x; }; bunzip2 = matchFiletype "bunzip2" { bz2 = x: x; }; diff --git a/tools/bwa-mem.nix b/tools/bwa-mem.nix index 3208e48..eed488e 100644 --- a/tools/bwa-mem.nix +++ b/tools/bwa-mem.nix @@ -36,5 +36,5 @@ in stdenv.mkDerivation { ${optionalString bamOutput "| samtools view -b"} \ > $out ''; - passthru.filetype = if bamOutput then filetype.bam {ref = ref; sorting = option-sort.none;} else filetype.sam {ref = ref; sorting = option-sort.none;}; + passthru.filetype = if bamOutput then filetype.bam {ref = ref; sorting = sort.none {};} else filetype.sam {ref = ref; sorting = sort.none {};}; } -- cgit v1.2.3