Fix/819 Fix incorrect g->c mapping when CIGAR alignment gaps overlap variant interval#823
Open
andreasprlic wants to merge 6 commits intobiocommons:mainfrom
Open
Conversation
When a genomic delins spans a position where the CIGAR alignment has an I-segment (genomic bases absent from the transcript), both variant endpoints can land in normal = segments so pos_c.uncertain remains False. The previous code path would strand-flip the edit without adjusting for the missing transcript base, producing an incorrect transcript edit. Fix: add _variant_has_internal_gap() and _gap_segments_within_pos_g() helpers that detect I/D segments strictly inside the variant interval, and route these cases through _get_altered_tx_sequence() which correctly filters genomic-only bases before building the transcript edit. Also refactors _i_segment_offsets_in_pos_g into the new unified _gap_segments_within_pos_g. Tests: update expected value for the adjacent-I-segment case (c.527_532delinsTGTGA, which is the correct result since the I-segment at g.119027727 is outside the variant g.119027721-119027726), and add a new test for the true internal-gap case (g.119027726_119027728delinsTT -> c.526_527delinsAA). Closes: hgvs-cl9, hgvs-hqa, hgvs-83z, hgvs-wma, hgvs-o26 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…internal or spanning alignment gaps.
|
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.



Closes #819
Problem
The g_to_c (and g_to_n) mapping in VariantMapper produced incorrect results for two related cases involving CIGAR alignment gaps:
Both cases are manifestations of issue #819 (the "double gap" problem).
Fix
Added helper methods to VariantMapper:
_gap_segments_within_pos_g(mapper, pos_g)— returns all I/D CIGAR segments strictly inside a genomic interval (replaces the earlier _i_segment_offsets_in_pos_g)._variant_has_internal_gap(mapper, var_g)— returns True when a gap segment lies strictly inside the variant interval (both endpoints in = regions)._expand_pos_g_for_adjacent_gap(mapper, var_g)— extends the genomic position to include any I-segment immediately adjacent to the variant boundary.The mapping logic in
g_to_candg_to_nnow checks for these cases before the strand-flip path and routes them through _get_altered_tx_sequence(), which correctly filters out genomic-only bases when reconstructing the transcript edit.Tests
Three new test cases in test_hgvs_assemblymapper.py: