Skip to content

fix(consensus): trim read-through on dovetail FR pairs in the MC-tag path - #853

Merged
nh13 merged 1 commit into
mainfrom
839/nhomer/consensus-dovetail-fr-trim
Aug 22, 2026
Merged

nh13 merged 1 commit into
mainfrom
839/nhomer/consensus-dovetail-fr-trim

Conversation

@nh13

@nh13 nh13 commented Aug 22, 2026 •

Copy link
Copy Markdown
Member

Summary

num_bases_extending_past_mate_raw (used by the simplex and duplex consensus callers to trim read-through past the mate) gated on the per-record is_fr_pair_raw, whose forward-strand arm derives the mate's 5' position from TLEN. That misclassifies dovetail FR pairs (htsjdk/samtools#1771): the forward read reads as NOT-FR, the clip returns 0, and its read-through / adapter bases past the mate leak into the consensus. The bug is asymmetric — the reverse read is unaffected because its branch of is_fr_pair_raw is CIGAR-derived.

Fix

Classify orientation per-pair from the read plus its MC tag instead. A reverse-strand read is the reverse record, so its own CIGAR-based arm is already correct; a forward-strand read's mate is the reverse record, whose leftmost is the mate position and whose alignment end comes from the MC CIGAR, so FR holds iff the read's 5' precedes that end — the same symmetric branch is_primary_fr_pair_raw (CODEC, #505) and fgumi clip (#760) use, without needing the mate record in hand. The MC tag is now parsed before the gate; with no usable MC there is no overhang to compute regardless, so it still fails closed to 0.

Testing

Adds a dovetail regression pinning the forward read (50M50S @ 101, TLEN -90, MC 100M; mate 100M @ 61): 40 bases of read-through are now trimmed where the per-record gate returned 0, and the test cross-checks the MC-tag path against the symmetric mate-record path num_bases_extending_past_mate_vs_mate_raw on the same geometry. Full suite, clippy, and fmt pass.

Closes #839.

Risk: changes consensus output by correcting 40-base read-through trimming; no unsafe changes and no CLAUDE.md allowlist update; no memory bound, queue capacity, or thread/backpressure changes.

Fixes FR-pair classification in the MC-tag consensus path by using symmetric read-plus-MC orientation logic. Unusable MC tags fail closed with zero overhang. Regression coverage verifies the affected dovetail geometry and matches the mate-record path.

…path

`num_bases_extending_past_mate_raw` (used by the simplex and duplex consensus
callers to trim read-through past the mate) gated on the per-record
`is_fr_pair_raw`, whose forward-strand arm derives the mate's 5' position from
TLEN. That misclassifies dovetail FR pairs (htsjdk/samtools#1771): the forward
read reads as NOT-FR, the clip returns 0, and its read-through / adapter bases
past the mate leak into the consensus. The bug is asymmetric -- the reverse read
is unaffected because its branch of `is_fr_pair_raw` is CIGAR-derived.

Classify orientation per-pair from the read plus its MC tag instead. A
reverse-strand read is the reverse record, so its own CIGAR-based arm is already
correct; a forward-strand read's mate is the reverse record, whose leftmost is
the mate position and whose alignment end comes from the MC CIGAR, so FR holds
iff the read's 5' precedes that end -- the same symmetric branch
`is_primary_fr_pair_raw` (CODEC, #505) and `fgumi clip` (#760) use, without
needing the mate record in hand. The MC tag is now parsed before the gate; with
no usable MC there is no overhang to compute regardless, so it still fails closed
to 0.

Add a dovetail regression pinning `num_bases_extending_past_mate_raw` on the
forward read (50M50S @ 101, TLEN -90, MC 100M; mate 100M @ 61): 40 bases of
read-through are now trimmed where the per-record gate returned 0. Closes #839.
@nh13
nh13 deployed to github-actions August 22, 2026 07:49 — with GitHub Actions Active
@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 596d8301-64c5-4c75-a350-ec2456979935

📥 Commits

Reviewing files that changed from the base of the PR and between cd7acdd and e57a25b.

📒 Files selected for processing (1)
  • crates/fgumi-raw-bam/src/overlap.rs

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


Walkthrough

The MC-based overlap path no longer relies on TLEN for forward-read FR classification. It validates MC CIGAR data, handles invalid data by returning zero, and trims 40 read-through bases for forward dovetail pairs.

Changes

Overlap FR classification

Layer / File(s) Summary
Mate-CIGAR-aware FR classifier
crates/fgumi-raw-bam/src/overlap.rs
Adds private FR classification that validates pairing, mapping, reference, and strand conditions. Forward reads use the mate’s MC-tag CIGAR instead of TLEN.
Overlap gate and dovetail regression
crates/fgumi-raw-bam/src/overlap.rs
Validates MC data before classification and applies the new classifier to MC-based overlap. Tests verify consistent 40-base trimming through both overlap entry points.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to e57a2

This localized fix trims dovetail read-through correctly in the MC-tag consensus path and includes regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested labels: raw-bam

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title uses valid Conventional Commit syntax and clearly describes the dovetail FR trimming fix.
Linked Issues check ✅ Passed The changes implement symmetric MC-based FR classification, fail-closed handling, and regression coverage required by issue #839.
Out of Scope Changes check ✅ Passed The changes are limited to overlap classification, MC-tag handling, and regression tests within issue #839 scope.

Comment @coderabbitai help to get the list of available commands.

@nh13

nh13 commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai pause

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.50%. Comparing base (c0326c1) to head (e57a25b).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/fgumi-raw-bam/src/overlap.rs 95.65% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main     #853     +/-   ##
=========================================
  Coverage   94.50%   94.50%             
=========================================
  Files         190      193      +3     
  Lines      117990   120044   +2054     
=========================================
+ Hits       111505   113448   +1943     
- Misses       6485     6596    +111     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nh13

nh13 commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 added this pull request to the merge queue Aug 22, 2026
Merged via the queue into main with commit 4a32816 Aug 22, 2026
18 checks passed
@nh13
nh13 deleted the 839/nhomer/consensus-dovetail-fr-trim branch August 22, 2026 18:08
@nh13 nh13 mentioned this pull request Aug 22, 2026

This branch was successfully deployed

1 active deployment
github-actions — e57a25b2 Deployed Aug 22, 2026 by nh13 via coverage #3884
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.

duplex/vanilla consensus under-trims read-through on dovetail FR pairs (per-record is_fr_pair_raw)

1 participant