Skip to content

Make name sort put primary reads before secondary reads.#2012

Merged
whitwham merged 1 commit into
samtools:developfrom
jkbonfield:sort_primary
Apr 4, 2024
Merged

Make name sort put primary reads before secondary reads.#2012
whitwham merged 1 commit into
samtools:developfrom
jkbonfield:sort_primary

Conversation

@jkbonfield

Copy link
Copy Markdown
Contributor

For completeness, we consider non-secondary supplementaries as before secondaries, and non-supplementary secondaries before secondary+supplementary.

This is because a (non-2ndary) supplementary read is a continuation of the primary read and should be grouped before alternate alignments for this read.

We still have all READ1 data before all READ2 data, so the primary alignment has not changed ordering. This is simply a better way of resolving ties than keeping the original ordering.

Fixes #2010

@jkbonfield

Copy link
Copy Markdown
Contributor Author

For validation, I've just been doing some perl one-liner hackery to summarise the samtools view outputs. Eg:

samtools sort -Osam -n test.sam | perl -ane 'next if /^@/; next if $F[1]&1;$F[1]&=~0x10;$flags=`samtools flag $F[1]`;$flags=~s/.*\t//;printf("%s\t%03x\t%s",$F[0],$F[1],$flags)'

a	040	READ1
a	044	UNMAP,READ1
a	840	READ1,SUPPLEMENTARY
a	140	READ1,SECONDARY
a	940	READ1,SECONDARY,SUPPLEMENTARY
a	080	READ2
a	880	READ2,SUPPLEMENTARY
a	180	READ2,SECONDARY
a	980	READ2,SECONDARY,SUPPLEMENTARY
b	044	UNMAP,READ1
b	040	READ1
b	840	READ1,SUPPLEMENTARY
b	140	READ1,SECONDARY
b	940	READ1,SECONDARY,SUPPLEMENTARY
b	080	READ2
b	880	READ2,SUPPLEMENTARY
b	180	READ2,SECONDARY
b	980	READ2,SECONDARY,SUPPLEMENTARY

For completeness, we consider non-secondary supplementaries as before
secondaries, and non-supplementary secondaries before
secondary+supplementary.

This is because a (non-2ndary) supplementary read is a continuation of
the primary read and should be grouped before alternate alignments for
this read.

We still have all READ1 data before all READ2 data, so the primary
alignment has not changed ordering.  This is simply a better way of
resolving ties than keeping the original ordering.

Fixes samtools#2010
@whitwham whitwham merged commit d92b49e into samtools:develop Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sorting by name does not guarantee primary alignment sorts before secondary and supplementary

2 participants