Skip to content

Add fixmate -M option for base modifications#1990

Merged
daviesrob merged 2 commits into
samtools:developfrom
jkbonfield:fixmate_MM
Feb 29, 2024
Merged

Add fixmate -M option for base modifications#1990
daviesrob merged 2 commits into
samtools:developfrom
jkbonfield:fixmate_MM

Conversation

@jkbonfield

Copy link
Copy Markdown
Contributor

The specification has an MN tag to specify the length of the sequence at the time the MM/ML tags were produced. We validate this against the sequence length (or use the lack of it) as an indication that the aligner has not updated the base modification tags when doing hard-clipping of sequence during secondary alignment. Some aligners do, but most do not. This disparity makes it impossible to make assumptions, so -M is off by default and we should only use it when we know our aligner either does always output MN (it's then a useful sanity check) or if we know our aligner does not update MM/ML while hard clipping.

This also refactors the main loop of fixmate to consume all reads for a single template before fixing up the data. The original implementation was written before secondary and supplementary reads were added, so it had implicit assumptions on data ordering and made it impossible to fix secondaries after the 2nd read in a read-pair.

Draft as I still need to verify this on proper aligner output rather than my hand-crafted examples.

It no longer reads just 2 records at a time and instead fetches all
reads sharing the same template name.  It then scans these to find the
primaries so it can match the same logic as before.

This new structure however provides the opportunity for fixing
secondaries and supplementaries based on their primary reads, which
previously wasn't possible after the paired primary had been found.
@jkbonfield

jkbonfield commented Feb 14, 2024

Copy link
Copy Markdown
Contributor Author

Note: this will fail checks until samtools/htslib#1749 is merged.

The code is still compatible with earlier htslibs, but it won't be correcting all of the possible type of mistakes without it as it cannot sanity check every type of base modification error.

@jkbonfield jkbonfield force-pushed the fixmate_MM branch 2 times, most recently from 8afad7d to 4cd7ac5 Compare February 15, 2024 15:09
@jkbonfield jkbonfield marked this pull request as ready for review February 15, 2024 15:11
@jkbonfield

Copy link
Copy Markdown
Contributor Author

I just pushed a trivial commit message edit to trigger retests now the htslib PR has been merged.

@jkbonfield jkbonfield force-pushed the fixmate_MM branch 2 times, most recently from 741ad08 to 4923539 Compare February 23, 2024 10:00

@daviesrob daviesrob left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments so far. I have yet to check through all the Methylation bits...

Comment thread bam_mate.c Outdated
Comment thread bam_mate.c Outdated
Comment thread bam_mate.c
Comment thread bam_mate.c Outdated
Comment thread bam_mate.c Outdated
Comment thread bam_mate.c
If we have supplementary reads with trimmed SEQ fields and
corresponding hard-clips, the MM/ML tag may be invalid if they don't
have a corresponding MN that matches the trimmed SEQ length.

However the primary non-supplementary alignment should contain the
full sequence, allowing us to work out how to trim the supplementary
MM/ML tags and we can set a revised MN accordingly.

We also update the draft Mm and Ml tags to their official MM/ML tags.

(Dropped for a while and updated early Feb 2024)
@jkbonfield

Copy link
Copy Markdown
Contributor Author

I think I've addressed the problems now. Had I have known at the time more were coming I'd have probably made a new commit, but you can still diff 4923539 vs bc85434 to see the changes.

@daviesrob daviesrob merged commit 15d6538 into samtools:develop Feb 29, 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.

2 participants