Skip to content

fix(chimeric): well-formed single-end WithinBAM records with STAR's hard-clip rules - #282

Open
BenjaminDEMAILLE wants to merge 1 commit into
mainfrom
fix/se-chim-within-bam
Open

BenjaminDEMAILLE wants to merge 1 commit into
mainfrom
fix/se-chim-within-bam

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown
Contributor

Closes #279.

Root cause: build_within_bam_records used each segment's CIGAR as is and gave the representative the full read SEQ. SE soft-clip re-mapping (Tier 1b) and residual re-seeding (Tier 3) re-align a sub-sequence and only shifted exon coordinates, so the CIGAR was never padded (e.g. 40M with a 100 bp SEQ) and reverse-strand pieces got forward-read coordinates. Related bugs: Tiers 1b/2/3 ordered segments without accounting for strand, Tier 1b took the clip from the wrong end for a reverse primary, and Tier 3 then re-found a covered segment (duplicate chimera).

Fix (checked against STAR ChimericAlign_chimericBAMoutput.cpp, ReadAlign_alignBAM.cpp):

  • CIGARs padded with soft clips to full read length (full_length_cigar); lift_clip_transcript maps sub-sequence transcripts into full-read orientation.
  • SE: segments ordered by read position (STAR trChim), representative = strictly higher score else second (chimRepresent), supplementary hard-clipped on its junction side (itr%2==Str ? -12 : -11), SEQ trimmed accordingly. --chimOutType WithinBAM SoftClip keeps soft clips (new chim_out_bam_hard_clip()).
  • SA tags use the other record's final CIGAR.
  • PE: behaviour unchanged apart from padded CIGARs.
  • May change donor/acceptor order in Chimeric.out.junction for affected SE reads.

Tests: integration test test_se_chim_within_bam_records_well_formed (HardClip and SoftClip; fails on main with the reported error), plus 4 unit tests. fmt, clippy 0 warnings, all suites green.

Remaining STAR differences (not in this PR):

  1. STAR skips the read's normal alignment when a chimera goes into the BAM; rustar still writes it (affects Log.final.out too).
  2. rustar can emit more than one chimera per read (Tiers 2/3 are rustar-only).
  3. PE WithinBAM: no mate fields/paired flags, no hard clips, and inter-mate chimeras (STAR chimType 2) written with one supplementary record.
  4. QUAL empty on chimeric records.

Tracking: #277

🤖 Generated with Claude Code

…ip rules

Soft-clip (Tier 1b) and residual (Tier 3) segments kept sub-sequence
CIGARs, so a donor could carry 40M with a 100 bp SEQ and crash BAM
output. CIGARs are now lifted to full-read orientation and padded, SE
segments are ordered by read position, the representative follows STAR's
chimRepresent, and the supplementary record is hard-clipped on its
junction side (bamHardClip, SoftClip keeps soft clips). Also fixes Tier
1b clip side for reverse primaries and strand-aware segment ordering in
Tiers 1b, 2 and 3.

Closes #279

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Single-end --chimOutType WithinBAM fails with "read length-sequence length mismatch"

1 participant