Skip to content

fix: derive omitted RLE sequence when translating to HGVS - #705

Open
chenyangsu wants to merge 1 commit into
ga4gh:mainfrom
chenyangsu:fix/to-hgvs-rle-without-sequence
Open

chenyangsu wants to merge 1 commit into
ga4gh:mainfrom
chenyangsu:fix/to-hgvs-rle-without-sequence

Conversation

@chenyangsu

Copy link
Copy Markdown

translate_to(allele, "hgvs") raises AttributeError: 'NoneType' object has no attribute 'root' for a ReferenceLengthExpression allele whose sequence was left out by rle_seq_limit (the case in #344). test_rle_seq_limit currently expects this error. _to_spdi already rebuilds the sequence with denormalize_reference_length_expression.

HgvsTools._to_sequence_variant now does the same when sequence is missing. Alleles that carry a sequence are unchanged. Happy to raise a clearer error instead if you prefer.

Testing: test_rle_seq_limit now expects ["NC_000013.11:g.32331043_32331094dup"] for the allele without a sequence. It fails on main and passes with the change. Full suite: 224 passed.

@chenyangsu
chenyangsu requested review from a team as code owners November 26, 2026 20:45

@arieleven arieleven left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this fixes a real round-trip gap: with the default rle_seq_limit, translate_from(..., fmt="hgvs") drops state.sequence for long repeats, and translate_to(..., "hgvs") then failed on .root. Deriving the alt from the reference with denormalize_reference_length_expression matches what _to_spdi already does, and the updated test_rle_seq_limit dup case now round-trips.

A few thoughts:

  • _to_spdi always re-derives the alt for RLEs and logs a warning if a provided sequence disagrees, while here the derived alt is only used when sequence is missing. Either is reasonable, but making the two translators behave the same (or noting why they differ) would avoid surprises later.
  • The test covers an expansion (dup). A contraction case, such as an RLE whose length is shorter than the reference span, would exercise the deletion path through the same code.
  • Minor: when start == end, ref is None. That shouldn't happen for a normalized RLE, but a clear error there would be easier to debug than a TypeError from slicing None.

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.

2 participants