feat: support to_hgvs for single-residue protein variants - #654
Open
developer-rpai wants to merge 1 commit into
Open
developer-rpai wants to merge 1 commit into
developer-rpai wants to merge 1 commit into
Conversation
Implements HGVS export for protein Alleles with a single-residue LiteralSequenceExpression state: missense/nonsense substitutions (e.g. NP_060204.1:p.Val261Ala) and single-residue deletions (e.g. NP_060204.1:p.Val261del). Multi-residue changes, insertions, and non-literal states raise ValueError. Adds tests/extras/test_to_hgvs_protein.py with 9 tests covering the issue example plus negative controls.
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.
Summary
Closes #633 — adds
to_hgvssupport for protein variants, scoped to single-protein-residue changes as requested in the issue.Problem
HgvsTools._to_sequence_variantraisedValueError("Only nucleic acid variation is currently supported")for any allele on a protein sequence (e.g. anNP_accession), soTranslator.translate_to(allele, "hgvs")could not export protein alleles like the issue's example (NP_060204.1:p.Val261Ala).Approach
Protein variants carry the reference residue in the position itself (HGVS protein notation:
p.Val261Ala), unlike nucleic variants where ref/alt live in the edit. The fix addsHgvsTools._to_protein_sequence_variant, which:end - start == 1) with aLiteralSequenceExpressionstate — anything else (multi-residue spans, insertions,ReferenceLengthExpressionstates, reference alleles, invalid/multi-residue alt codes) raises a descriptiveValueError;hgvs.location.AAPosition+hgvs.edit.AASub(substitutions, incl. nonsense*→Ter) orhgvs.edit.AARefAlt(single-residue deletions, empty alt →del);HGVSDataNotAvailableErrorfallback as the nucleic path), so the reference residue is validated against UTA when UTA data is available.Tests
New
tests/extras/test_to_hgvs_protein.py(9 tests, all passing):["NP_060204.1:p.Val261Ala"]NP_060204.1:p.Val261TerNP_060204.1:p.Val261delValueError): multi-residue span, insertion (start == end),ReferenceLengthExpressionstate, reference allele (alt == ref), multi-residue alt, invalid residue codeThe new tests use a stub data proxy and a mocked UTA connection, so they run without SeqRepo/UTA.
ruff checkandruff format --checkpass on both changed files.Not tested locally
normalize()validation path for protein variants (no UTA database available in this environment); the no-UTA-data fallback is what the tests exercise.sequence_type == "p"branch.