Skip to content

Protect against merging CRAM files with different headers.#2220

Merged
whitwham merged 1 commit into
samtools:developfrom
jkbonfield:cram-merge
May 21, 2025
Merged

Protect against merging CRAM files with different headers.#2220
whitwham merged 1 commit into
samtools:developfrom
jkbonfield:cram-merge

Conversation

@jkbonfield

@jkbonfield jkbonfield commented May 15, 2025

Copy link
Copy Markdown
Contributor

The protection of sharing incompatible references between multiple input files aren't strict enough. It was attempting to spot files with reordered references by checking the "lost_coord_sort" flag in the header translation table. However this doesn't cover the case where we are merging completely unrelated files that have no overlap in reference names.

Fixes #2218

Note there may be cases where we can share references for the output file descriptor but we're not doing so. For example if we have two files which are the same references but in different order, then the first and second inputs cannot share a reference as the ordering differs, but by the time we get to writing the translation table has brought them together again so the output could share the reference with the first input.

It's a bit of a corner case though and it's safer to simply avoid optimising the rare case. If any of the input refs can't be shared, we also don't share it to the output. (I think this was another bug in the original design)

The protection of sharing incompatible references between multiple
input files aren't strict enough.  It was attempting to spot files
with reordered references by checking the "lost_coord_sort" flag in
the header translation table.  However this doesn't cover the case
where we are merging completely unrelated files that have no overlap
in reference names.

Fixes samtools#2218
@whitwham whitwham self-assigned this May 19, 2025
@whitwham whitwham merged commit c0c9a36 into samtools:develop May 21, 2025
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.

samtools merge will not merge CRAM files aligned to different references

2 participants