Repository navigation
feat: regenerate NM/MD on CRAM input, like htslib - #210
Merged
ewels merged 1 commit intoDec 2, 2026
Merged
Conversation
htslib rebuilds the NM and MD tags while decoding CRAM (CRAM_OPT_DECODE_MD is set to auto on every CRAM it opens), noodles leaves that to the caller. Without them samtools stats reports 0 mismatches for CRAM input and the split_bam BAMs lose NM/MD. The CRAM readers now add the missing tags from the reference, following cram_decode_seq (mismatch rules, MD zero padding, deletions, splices, NM width, tag order with RG last). Tags a record already has are kept. It runs once per run only for what a tool needs (--cram-decode-md auto, the default): NM for samtools stats, NM and MD for the split_bam BAMs. always fills both on every mapped record, never turns it off. Also settable as cram.decode_md in the config file. BAM/SAM input is untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rhassaine
force-pushed
the
feat/cram-decode-md
branch
from
December 2, 2026 13:07
f912e15 to
3c7b9d1
Compare
ewels
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
htslib regenerates
NM/MDwhen decoding CRAM; noodles leaves that to the caller by design (zaeleus/noodles#379). So with #118, CRAM input gavesamtools stats0 mismatches (main and samtools itself: 39,821 on the chr6 test data as CRAM) and the split_bam BAMs lost theirMD/NMtags. BAM input is not affected.This computes them in the shim, matching htslib:
src/rna/bam/md_nm.rs: NM/MD from CIGAR + read sequence + reference, following htslib's CRAM decoder rules (N against N is a mismatch, case-insensitive reference,^deletions, splices/clips skipped, no tags for unmapped/no-sequence records, existing tags never overwritten, tag order MD, NM then RG); 29 unit tests.NM, split_bam's written BAMs needNM+MD, otherwise nothing.--cram-decode-md auto|always|never(configrna.cram.decode_md, envRUSTQC_CRAM_DECODE_MD), mirroring htslib'sdecode_md; defaultauto. Documented in the CLI and configuration docs.On the chr6 CRAM at 1 and 6 threads: samtools stats is byte-identical to main (39,821 mismatches), split_bam's BAMs are identical including
MD/NM, other outputs identical; the 8 BAM datasets are unchanged. Cost is ~0.03 s on that dataset. Tests pass on stable and 1.89.Note: this and the shim-allocation PR both touch
io.rs(a field inIndexedReaderand an import); whichever goes in second needs a small rebase, which I'll do.🤖 Generated with Claude Code