Skip to content

feat: support to_hgvs for single-residue protein variants - #654

Open
developer-rpai wants to merge 1 commit into
ga4gh:mainfrom
developer-rpai:feat/to-hgvs-protein-variants-633
Open

developer-rpai wants to merge 1 commit into
ga4gh:mainfrom
developer-rpai:feat/to-hgvs-protein-variants-633

Conversation

@developer-rpai

Copy link
Copy Markdown

Summary

Closes #633 — adds to_hgvs support for protein variants, scoped to single-protein-residue changes as requested in the issue.

Problem

HgvsTools._to_sequence_variant raised ValueError("Only nucleic acid variation is currently supported") for any allele on a protein sequence (e.g. an NP_ accession), so Translator.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 adds HgvsTools._to_protein_sequence_variant, which:

  • accepts only single-residue changes (end - start == 1) with a LiteralSequenceExpression state — anything else (multi-residue spans, insertions, ReferenceLengthExpression states, reference alleles, invalid/multi-residue alt codes) raises a descriptive ValueError;
  • fetches the reference residue via the data proxy and builds the variant with hgvs.location.AAPosition + hgvs.edit.AASub (substitutions, incl. nonsense *Ter) or hgvs.edit.AARefAlt (single-residue deletions, empty alt → del);
  • runs the constructed expression through the existing parse + hgvs-normalize step (same HGVSDataNotAvailableError fallback 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):

  • the exact allele from Support to_hgvs for protein variants #633["NP_060204.1:p.Val261Ala"]
  • nonsense substitution → NP_060204.1:p.Val261Ter
  • single-residue deletion → NP_060204.1:p.Val261del
  • negative controls (all assert ValueError): multi-residue span, insertion (start == end), ReferenceLengthExpression state, reference allele (alt == ref), multi-residue alt, invalid residue code

The new tests use a stub data proxy and a mocked UTA connection, so they run without SeqRepo/UTA. ruff check and ruff format --check pass on both changed files.

Not tested locally

  • The UTA-backed normalize() validation path for protein variants (no UTA database available in this environment); the no-UTA-data fallback is what the tests exercise.
  • The full existing test suite, which requires SeqRepo data and external services not available here; no existing code paths were modified beyond delegating the sequence_type == "p" branch.

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

Support to_hgvs for protein variants

1 participant