Repository navigation
fix(index): position-bin placed-but-unmapped reads in the BAI - #651
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughPlaced-but-unmapped reads with valid coordinates are now indexed over a one-base span, while truly unplaced reads remain excluded. Unit and integration tests verify exact region records and full idxstats parity with samtools. ChangesBAM indexing behavior
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #651 +/- ##
=======================================
Coverage 93.57% 93.57%
=======================================
Files 175 175
Lines 106764 106803 +39
=======================================
+ Hits 99904 99944 +40
+ Misses 6860 6859 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
5cdcbe4 to
392c868
Compare
A read with the UNMAPPED flag but a valid reference and position — the common "mate mapped, self unmapped" record, which carries its mate's tid/pos so it coordinate-sorts alongside it — was dropped from the index entirely: no bin, no chunk, no linear-index entry. htslib/samtools position-bin such reads, so region queries and idxstats over a fgumi index silently missed them (a fetch of "all reads in this window" would lose the unmapped mates, and idxstats' unmapped column disagreed with samtools). extract_alignment_context now returns an alignment context for any read that has a reference and position, binning it over a 1-base [pos, pos+1) span when it has no CIGAR (matching htslib's bam_endpos = pos + max(rlen, 1)); only a read with no reference/position is treated as unplaced. The is_mapped flag still records the read as unmapped, so it is not miscounted as mapped — it simply becomes queryable, matching htslib. The samtools cross-check now asserts equality over ALL reads (dropping the earlier -F 4 mapped-only workaround) and over full idxstats, and passes. This also changes the .bai content for the existing IndexingBamWriter path, which is the intent: both index paths now match samtools.
392c868 to
e35d4ca
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Thank-you @tfenne!!! |
What & why
A read with the UNMAPPED flag but a valid reference and position — the common "mate mapped, self unmapped" record, which carries its mate's
tid/posso it coordinate-sorts alongside its mate — was dropped from the BAI entirely: no bin, no chunk, no linear-index entry. htslib/samtools position-bin such reads, so region queries andidxstatsover a fgumi index silently missed them (a "fetch everything in this window" would lose the unmapped mates, and theidxstatsunmapped column disagreed with samtools).What it does
extract_alignment_contextnow returns a binning context for any read that has a reference and position, binning it over a 1-base[pos, pos+1)span when it has no CIGAR (matching htslib'sbam_endpos = pos + max(rlen, 1)); only a read with no reference/position is treated as unplaced. Theis_mappedflag still records the read as unmapped, so it isn't miscounted as mapped — it just becomes queryable, matching htslib. Normal mapped reads (CIGAR span ≥ 1) bin identically to before, so the blast radius is limited to placed-unmapped reads.This changes
.baicontent for both index paths (the pooled sort writer andIndexingBamWriter), which is the intent: both now match samtools on content.Validation
[pos, pos+1)withis_mapped=false; a mapped read → its CIGAR span; a truly-unplaced read → unplaced.test_sort_write_index_matches_samtools_index) now compares ALL reads (dropping the previous-F 4mapped-only workaround) and fullidxstats— and matches.cargo ci-fmt,cargo ci-lint(clippy pedantic), and all tests including the samtools-gated ones.Stacked on #650 (BAI compaction); merge that first.
Summary by CodeRabbit