Repository navigation
peOverlap EndToEnd: keep the merged read's chromosome-edge transcript - #377
Open
BenjaminDEMAILLE wants to merge 1 commit into
Open
BenjaminDEMAILLE wants to merge 1 commit into
BenjaminDEMAILLE wants to merge 1 commit into
Conversation
With --peOverlapNbasesMin and --alignEndsType EndToEnd, a pair whose overlapping mates hang over a chromosome edge stayed unmapped; STAR maps it soft-clipped at the edge (1S99M / 100M). STAR does not drop a transcript whose end-to-end extension hits the chromosome edge: it adds -999999999 and nMMmax+1 to it and goes on (stitchWindowAligns.cpp:44-55), then floors the score at 0 when it applies the genomic-length penalty (:224), so the window keeps it, unextended. For an ordinary read it is never reported. For the merged mates, once any window scores above 0, peOverlapSEtoPE splits every window transcript back into mates and rescores it from its exons (ReadAlign_peOverlapMergeMap.cpp:276-292), and the kept edge transcript wins. The merged read now keeps such transcripts at score 0, and all of its transcripts are split and rescored, not only those in the score range. A read whose transcripts all score 0 has no window, as in STAR (ReadAlign_stitchPieces.cpp:344). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Part of #354 (
--peOverlapNbasesMinwith EndToEnd: mates overlapping at a chromosome edge).Stacked on #368. The base is
fix/end-to-end-pairs; only the last commit is this PR. It merges cleanly with #367 (fix/half-mapped-multimap).Problem
With
--alignEndsType EndToEnd --peOverlapNbasesMin 10, a pair whose mates overlap and hang 1 to 4 bases over a chromosome edge stayed unmapped. STAR maps it, with the overhang soft-clipped on the edge mate:A clip at the edge looks odd under EndToEnd. It comes from how STAR handles the merged read.
What STAR does (2.7.11b source)
extendAlign.cpp:25-32: an end-to-end extension that reaches a chromosome edge returnstruewithextendL=0,maxScore=-999999999,nMM=nMMmax+1.stitchWindowAligns.cpp:44-55, 65-77: the caller adds that to the transcript and goes on. Nothing drops it.stitchWindowAligns.cpp:221-225: whenscoreGenomicLengthLog2scale != 0(default -0.25),Score = max(0, Score). The transcript is kept in the window at score 0, unextended.ReadAlign_stitchPieces.cpp:328, 344: a score-0 transcript never becomestrBest. If no window scores above 0,nW=0and the read is unmapped. So for an ordinary read the kept transcript is never seen.ReadAlign_peOverlapMergeMap.cpp:31-39, 266-306: for the merged mates, oncenW>0,peOverlapSEtoPEconverts every transcript of every window back into a pair and rescores it from its exons withalignScore(Transcript_alignScore.cpp). The -999999999 and the extra mismatches are gone. The kept edge transcript is now the best one, and its unextended end is the soft clip.57M26I86M,AS:13). Mapping the merged read single-end with permissive filters shows both: the1S168MatAS:0 nM:171and theAS:13one.8Sabove for a 3-base overhang), since no extension is applied.Change
src/align/stitch.rs:EXTEND_TO_END_KILLis STAR's -999999999. When the scorer's newkeep_end_to_end_killsis set, a killed transcript is not dropped: its score and mismatches get the kill values, andwt_final_scorefloors at 0 when the length penalty is on, as STAR does.src/align/read_align.rs:align_read_innersetskeep_end_to_end_killsonly for the merged read (mapped_filter == false), and skips the score range there, so every transcript is split and rescored. A read whose transcripts all score 0 now has no window ("other",trBest=trInit), as in STAR; for the merged read this means the pair is not replaced.shortcut:on the field.Measured against STAR 2.7.11b
Fuzz: 4000 pairs per seed, 2 random 20 kb chromosomes, fragments 130-175 bp (mates 100 bp, overlap 25-70), 70% at a chromosome start or end with a 0-4 base random overhang, 0-2 mismatches, 30% interior.
--alignEndsType EndToEnd --peOverlapNbasesMin 10 --outFilterScoreMinOverLread 0.3 --outFilterMatchNminOverLread 0.3 --outSAMunmapped Within. Reads whose SAM fields 1-9 and tags differ from STAR:The 7 fixed here are all clipped edge pairs like the ones above. The 18 left are half-mapped pairs (multimapper
NH, the unmapped mate's record), which #367 fixes; merged together, all 32000 match.Same fuzz, other modes (seeds 1-2):
--alignEndsType Local0 differences before and after.Extend5pOfReads12: 815 → 221 and 791 → 190; see Not checked.Tests
tests/end_to_end_pairs.rs:overlapping_mates_over_a_chromosome_edge_are_clipped_like_star. Overhangs of 1 and 2 bases, fragments 130 and 169, over the start and the end ofc1. A diverged copy of the merged read's edge end onc2gives the window above 0, so the case does not depend on chance. Expected records are STAR 2.7.11b's output on the same genome and reads (1S99M/2S98Mat 1,99M1S/98M2Sat 19902/19903,AS197/196,nM0). It fails on #368 (no records) and passes here.rungainsrun_onto take a FASTA.cargo test --release,cargo clippy --all-targets -- -D warningsandcargo fmt --checkare clean on macOS.Not checked
Extend5pOfReads12with--peOverlapNbasesMinstill differs on ~200 of 4000 fuzz pairs. Cause seen: STAR'speOverlapSEtoPEalso converts a merged transcript that lies in one mate only (AS:7, then the pair failsmappedFilter), whileconvert_merged_transcript_to_pedrops it, so rustar keeps the separate-mate result. Separate issue, not fixed here.trAllhas them).--peOverlapNbasesMin, plus the all-score-0 rule.🤖 Generated with Claude Code