From 99ee99c490cc109b78986181ee1be4ce1cd0c0ed Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Thu, 25 Oct 2018 08:02:20 +1100 Subject: Improve type safety of samtools-merge --- lib/types.nix | 3 ++- test-tnpair.nix | 1 + tools/samtools-index.nix | 2 +- tools/samtools-merge.nix | 8 +++----- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 2e5adca..4dbc6ff 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -38,7 +38,8 @@ 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 (defError (idst sym) y sort); in matchFiletype sym { bam = f; sam = f; cram = f; }; + matchSorting = sym: y: x: match x.sorting (defError (idst sym) y sort); + matchFileSorting = sym: y: let f = matchSorting sym y; in matchFiletype sym { bam = f; sam = f; cram = f; }; sort = make-type "sort" { none = {}; coord = {}; diff --git a/test-tnpair.nix b/test-tnpair.nix index 7deaf3b..0f6a441 100644 --- a/test-tnpair.nix +++ b/test-tnpair.nix @@ -54,6 +54,7 @@ let ln -s ${tnpairResult.variants} $out/strelka mkdir $out/alignments ln -s ${gridss.callVariants {} (with tnpairResult.alignments; [tumour])} $out/gridss + ln -s ${samtools.merge {} [tnpairResult.alignments.tumour tnpairResult.alignments.normal]} $out/alignments/merged.bam ln -s ${samtools.view { outfmt = types.toCram; } (tnpairResult.alignments.tumour)} $out/alignments/${tnpair.tumour.name}.cram ln -s ${samtools.view { outfmt = types.toCram; } (tnpairResult.alignments.normal)} $out/alignments/${tnpair.normal.name}.cram ln -s ${flagstat tnpairResult.alignments.tumour} $out/alignments/${tnpair.tumour.name}.flagstat diff --git a/tools/samtools-index.nix b/tools/samtools-index.nix index aad46a7..6919f97 100644 --- a/tools/samtools-index.nix +++ b/tools/samtools-index.nix @@ -10,7 +10,7 @@ with lib; with bionix.types; assert (matchFiletype "samtools-index" { bam = _: true; } input); -assert (matchSorting "samtools-index" { coord = _: true; } input); +assert (matchFileSorting "samtools-index" { coord = _: true; } input); stdenv.mkDerivation { name = "samtools-index"; diff --git a/tools/samtools-merge.nix b/tools/samtools-merge.nix index 6d072b0..eacf520 100644 --- a/tools/samtools-merge.nix +++ b/tools/samtools-merge.nix @@ -10,13 +10,11 @@ with nixpkgs; with lib; let - inherit (bionix.types) matchFiletype option-sort; - inputIsSorted = input: matchFiletype "samtools-merge" { - bam = _: true; #{sorting, ...}: sorting == option-sort.some (bionix.types.sorting.coord {}); - } input; + inherit (bionix.types) matchFiletype matchSorting; + inputIsHomogenous = length (unique (map (matchFiletype "samtools-merge" {bam = x: x // {sorting = matchSorting "samtools-merge" {coord = _: "coord";} x;};}) inputs)) == 1; in -assert (all inputIsSorted inputs); +assert inputIsHomogenous; stdenv.mkDerivation { name = "samtools-merge"; -- cgit v1.2.3