Exclude unmapped calls from CpG summaries - #650
Open
SuhasSrinivasan wants to merge 1 commit into
Open
Conversation
SuhasSrinivasan
marked this pull request as ready for review
August 5, 2026 05:56
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.
Fixes #649.
Summary
summary --cpgresults, matching the documented--motif CG 0behavior.Severity
Severity: High — scientific correctness
Rationale: The shorthand can silently include an ineligible unmapped population and alter read totals and modification statistics while the command exits successfully.
Root cause
The indexed Summary path correctly constructs a
CGmotif for--cpg, but the later guard that skips unmapped collection checked onlymapped_only,matched_only, and an explicitmotif. Omitting the CpG shorthand allowed all unmapped calls to be merged into the mapped reference-CpG histogram.Implementation
Treat
--cpgas a resolved motif restriction in the unmapped-collection guard. The regression copies the 10 mapped test records and appends an unmappedCCCCrecord withMM:Z:C+m?,0,0,0,0;, four ML values of 255, andMN:i:4, then compares normalized CLI output with mapped-only and explicit-motif controls.Preserved behavior
--motif CG 0behavior remains unchanged.Non-goals
Behavior before and after
--cpg--motif CG 0and mapped-only controltotal_reads_used=11total_reads_used=10Testing
Test environment
a99f411a8dacfd4bf705fc9adb068219bc7bafc70b532f8ee0fd65de5e489f32485792209182112f; clean at final verification5cecc3fb3a9336068d9e3c68d5c08d678153dd2ctotal_reads_used=11instead of 10cargo test -p modkit --test test_summary test_summary_cpg_excludes_unmapped_calls -- --exactcargo test -p modkit --test test_summarycargo test -p modkit --test test_pileup -- --test-threads=1cargo test --workspace --quiet -- --test-threads=1--cpg, explicit--motif CG 0, and mapped-only control20 / 186becomes10 / 77and matches both controlsrustfmt --check --edition 2021 modkit-core/src/modbam_util/subcommands.rs modkit/tests/test_summary.rs;git diff --checktest_pileup_no_filtandtest_pileup_with_headershare/tmp/test_pileup_nofilt.bed; serial affected and workspace gates pass, and this PR does not touch pileupTests not performed
Scientific validation
--cpgequals explicit--motif CG 0after normalizing key order.Output and compatibility
Reviewer guide
cargo test -p modkit --test test_summary test_summary_cpg_excludes_unmapped_calls -- --exact.cargo test -p modkit --test test_summaryas the affected integration canary.Checklist