aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2019-05-02 07:45:02 +1000
committerJustin Bedo <cu@cua0.org>2019-05-02 07:45:02 +1000
commite7a2705bb3818db7647c7a37ef675760c323bd26 (patch)
treebfab0205d6414f8ee0c76c80c5bc21866e310db6
parent95c8a36a7e673fac090175729069a668daa919da (diff)
samtools-merge: detect correct sorting
-rw-r--r--test-tnpair.nix2
-rw-r--r--tools/samtools-merge.nix7
2 files changed, 7 insertions, 2 deletions
diff --git a/test-tnpair.nix b/test-tnpair.nix
index 1b5f347..f2e84ac 100644
--- a/test-tnpair.nix
+++ b/test-tnpair.nix
@@ -13,6 +13,7 @@ let
alignWithRG = rg: bwa.align { inherit ref; flags = "-R'@RG\\tID:${rg}\\tSM:${rg}'";};
sort = samtools.sort {};
+ nameSort = samtools.sort {nameSort = true;};
flagstat = samtools.flagstat {};
check-fastqc = fastqc.check {};
check-fastp = fastp.run {};
@@ -56,6 +57,7 @@ let
(ln (gridss.call (with tnpairResult.alignments; [normal tumour])) "gridss2")
(ln (gridss.callAndAssemble (with tnpairResult.alignments; [normal tumour])) "gridss3")
(ln (samtools.merge {} [tnpairResult.alignments.tumour tnpairResult.alignments.normal]) "alignments/merged.bam")
+ (ln (samtools.merge {} [(nameSort tnpairResult.alignments.tumour) (nameSort tnpairResult.alignments.normal)]) "alignments/merged-namesorted.bam")
(ln (samtools.view { outfmt = types.toCram; } (tnpairResult.alignments.tumour)) "alignments/${tnpair.tumour.name}.cram")
#(ln (samtools.view { outfmt = types.toCram; } (tnpairResult.alignments.normal)) "alignments/${tnpair.normal.name}.cram")
(ln (flagstat tnpairResult.alignments.tumour) "alignments/${tnpair.tumour.name}.flagstat")
diff --git a/tools/samtools-merge.nix b/tools/samtools-merge.nix
index 9b7d133..81b0c15 100644
--- a/tools/samtools-merge.nix
+++ b/tools/samtools-merge.nix
@@ -10,7 +10,8 @@ with lib;
let
inherit (bionix.types) matchFiletype matchSorting;
- inputIsHomogenous = length (unique (map (matchFiletype "samtools-merge" {bam = x: x // {sorting = matchSorting "samtools-merge" {coord = _: "coord";} x;};}) inputs)) == 1;
+ inputIsHomogenous = length (unique (map (matchFiletype "samtools-merge" {bam = x: x // {sorting = matchSorting "samtools-merge" {coord = _: "coord"; name = _: "name"; } x;};}) inputs)) == 1;
+ nameSorted = matchFiletype "samtools-merge" { bam = x: matchSorting "samtools-merge" {coord = _: false; name = _: true;} x;} (lib.head inputs);
in
assert inputIsHomogenous;
@@ -19,7 +20,9 @@ stage {
name = "samtools-merge";
buildInputs = with pkgs; [ samtools ];
buildCommand = ''
- samtools merge ${optionalString (flags != null) flags} out.bam ${concatStringsSep " " inputs}
+ samtools merge ${optionalString (flags != null) flags} \
+ ${if nameSorted then "-n" else ""} \
+ out.bam ${concatStringsSep " " inputs}
# Merge is non-deterministic with PG lines; if files have clashing PG IDs then a random
# suffix is appended to make it unique. PG lines are stripped in the following to