From 6d2be63a5cb3f5811a17c0ed515ace3296087174 Mon Sep 17 00:00:00 2001 From: Kyle Ferriter Date: Mon, 9 Nov 2026 21:25:09 -0500 Subject: [PATCH 1/3] feat(normalize)!: select smallest RLE repeat subunit length (VRS 2.1) --- src/ga4gh/vrs/normalize.py | 16 +- .../test_normalize_rle_smallest_subunit.yaml | 170 ++++++++++++++++++ tests/extras/test_allele_translator.py | 7 +- tests/test_vrs_normalize.py | 23 +++ 4 files changed, 207 insertions(+), 9 deletions(-) create mode 100644 tests/cassettes/test_normalize_rle_smallest_subunit.yaml diff --git a/src/ga4gh/vrs/normalize.py b/src/ga4gh/vrs/normalize.py index 72d1ccc1..072c7699 100644 --- a/src/ga4gh/vrs/normalize.py +++ b/src/ga4gh/vrs/normalize.py @@ -364,20 +364,24 @@ def denormalize_reference_length_expression( def _factor_gen(n: int) -> Iterator[int]: - """Yield all factors of an integer in descending order. + """Yield all factors of an integer in ascending order. + + The first factor that passes `_is_valid_cycle` becomes the ``repeatSubunitLength``, + so ascending order selects the smallest valid factor (VRS 2.1 normalization). VRS + 2.0 selected the largest; see ``PrevVrsVersion.V2_0`` for computing 2.0 digests. :param n: Positive integer to factor. Nonpositive inputs yield no values. - :return: Iterator yielding factors from largest to smallest. + :return: Iterator yielding factors from smallest to largest. """ - lower_factors = [] + upper_factors = [] i = 1 while i * i <= n: if n % i == 0: - yield n // i + yield i if n // i != i: - lower_factors.append(i) + upper_factors.append(n // i) i += 1 - yield from reversed(lower_factors) + yield from reversed(upper_factors) def _define_rle_allele( diff --git a/tests/cassettes/test_normalize_rle_smallest_subunit.yaml b/tests/cassettes/test_normalize_rle_smallest_subunit.yaml new file mode 100644 index 00000000..5b1cc262 --- /dev/null +++ b/tests/cassettes/test_normalize_rle_smallest_subunit.yaml @@ -0,0 +1,170 @@ +interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007183&end=1007183 + response: + body: + string: '' + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007182&end=1007183 + response: + body: + string: T + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007181&end=1007182 + response: + body: + string: G + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007180&end=1007181 + response: + body: + string: T + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007179&end=1007180 + response: + body: + string: G + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007178&end=1007179 + response: + body: + string: T + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007177&end=1007178 + response: + body: + string: G + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007176&end=1007177 + response: + body: + string: T + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007175&end=1007176 + response: + body: + string: G + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007174&end=1007175 + response: + body: + string: T + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007173&end=1007174 + response: + body: + string: G + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007172&end=1007173 + response: + body: + string: C + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007183&end=1007184 + response: + body: + string: C + headers: {} + status: + code: 200 + message: OK +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/sequence/ga4gh:SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO?start=1007173&end=1007183 + response: + body: + string: GTGTGTGTGT + headers: {} + status: + code: 200 + message: OK +version: 1 diff --git a/tests/extras/test_allele_translator.py b/tests/extras/test_allele_translator.py index feb9f2f6..472915d5 100644 --- a/tests/extras/test_allele_translator.py +++ b/tests/extras/test_allele_translator.py @@ -257,7 +257,8 @@ def tlr(rest_dataproxy): }, }, { - # single base expansion (9*A -> 11*A) + # two base expansion (9*A -> 11*A): subunit lengths 1 and 2 are both valid, and + # VRS 2.1 selects the smallest (VRS 2.0 selected 2) "spdi": "NC_000001.11:236900409:AAAAAAAAA:AAAAAAAAAAA", "gnomad": "1-236900410-A-AAA", "expected_allele": { @@ -272,7 +273,7 @@ def tlr(rest_dataproxy): }, "state": { "length": 11, - "repeatSubunitLength": 2, + "repeatSubunitLength": 1, "sequence": "AAAAAAAAAAA", "type": "ReferenceLengthExpression", }, @@ -629,7 +630,7 @@ def test_to_spdi_with_ref(tlr) -> None: }, "state": { "length": 14, - "repeatSubunitLength": 2, + "repeatSubunitLength": 1, "sequence": "TTTTTTTTTTTTTT", "type": "ReferenceLengthExpression", }, diff --git a/tests/test_vrs_normalize.py b/tests/test_vrs_normalize.py index d6f62545..fbb257ab 100644 --- a/tests/test_vrs_normalize.py +++ b/tests/test_vrs_normalize.py @@ -1005,3 +1005,26 @@ def test_normalize_location_out_of_bounds( ) with pytest.raises(DataProxyValidationError, match=f"^{re.escape(expected_msg)}$"): normalize(_bounds_allele(case["start"], case["end"], "A"), dataproxy) + + +@pytest.mark.vcr +def test_normalize_rle_smallest_subunit(rest_dataproxy): + """A reference-derived insertion uses the smallest valid repeat subunit length. + Inserting GTGT into chr1 (GT) x 5: of the factors of seed length 4, 1 is not valid, + and 2 is selected over 4 (VRS 2.0 selected 4). + """ + allele = models.Allele( + location=models.SequenceLocation( + sequenceReference=models.SequenceReference( + refgetAccession="SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO" + ), + start=1007183, + end=1007183, + ), + state=models.LiteralSequenceExpression(sequence="GTGT"), + ) + normalized = normalize(allele, rest_dataproxy, rle_seq_limit=None) + assert (normalized.location.start, normalized.location.end) == (1007173, 1007183) + assert normalized.state == models.ReferenceLengthExpression( + length=14, repeatSubunitLength=2, sequence="GT" * 7 + ) From d9588fd51fd70533506498adf76a515ec49c27d2 Mon Sep 17 00:00:00 2001 From: Kyle Ferriter Date: Mon, 9 Nov 2026 21:25:21 -0500 Subject: [PATCH 2/3] feat: add PrevVrsVersion.V2_0 for VRS 2.0 Allele identifiers --- src/ga4gh/core/identifiers.py | 3 ++ src/ga4gh/vrs/models.py | 84 ++++++++++++++++++++++++++--- tests/test_vrs.py | 99 +++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 7 deletions(-) diff --git a/src/ga4gh/core/identifiers.py b/src/ga4gh/core/identifiers.py index a36b747e..537f9bdd 100644 --- a/src/ga4gh/core/identifiers.py +++ b/src/ga4gh/core/identifiers.py @@ -84,6 +84,9 @@ class PrevVrsVersion(str, Enum): """Define prior VRS versions supported for digest and identifier computation.""" V1_3 = "1.3" + # VRS 2.0 normalization selected the largest valid repeat subunit length for + # reference-derived insertions; VRS 2.1 selects the smallest + V2_0 = "2.0" @classmethod def validate(cls, version: object) -> None: diff --git a/src/ga4gh/vrs/models.py b/src/ga4gh/vrs/models.py index 4555a1dc..a58bf1b6 100644 --- a/src/ga4gh/vrs/models.py +++ b/src/ga4gh/vrs/models.py @@ -771,6 +771,9 @@ def ga4gh_serialize_as_version(self, as_version: PrevVrsVersion) -> str: raise ValueError(msg) out.append(result) return f'{{"interval":{{"end":{out[1]},"start":{out[0]},"type":"SequenceInterval"}},"sequence_id":"{self.sequenceReference.refgetAccession.split(".")[1]}","type":"SequenceLocation"}}' + if as_version == PrevVrsVersion.V2_0: + # SequenceLocation serialization is unchanged between VRS 2.0 and 2.1 + return encode_canonical_json(self.ga4gh_serialize()).decode("utf-8") msg = f"Received an unexpected value for `as_version`: {as_version}. MUST be an instance of `PrevVrsVersion`." raise TypeError(msg) @@ -789,7 +792,10 @@ class ga4gh(Ga4ghIdentifiableObject.ga4gh): # noqa: N801 """Define GA4GH serialization metadata for this model.""" prefix = "SL" - priorPrefix = {PrevVrsVersion.V1_3.value: "VSL"} # noqa: N815 + priorPrefix = { # noqa: N815 + PrevVrsVersion.V1_3.value: "VSL", + PrevVrsVersion.V2_0.value: "SL", + } inherent = ["end", "sequenceReference", "start", "type"] @@ -877,6 +883,17 @@ class _VariationBase(Ga4ghIdentifiableObject, ABC): expressions: list[Expression] | None = None +def _interval_value(pos: Range | int) -> int: + """Return the coordinate of an int or indefinite Range ([None, v] / [v, None])""" + value: int | list[int | None] | None = get_pydantic_root(pos) + if isinstance(value, int): + return value + if not isinstance(value, list) or None not in value: + msg = f"Expected an int or indefinite Range coordinate, but got {value}" + raise ValueError(msg) + return next(v for v in value if v is not None) + + class Allele(_VariationBase, BaseModelForbidExtra): """The state of a molecule at a `Location`.""" @@ -895,6 +912,19 @@ class Allele(_VariationBase, BaseModelForbidExtra): def ga4gh_serialize_as_version(self, as_version: PrevVrsVersion) -> str: """Return a serialized string following the conventions for Allele serialization as defined in the VRS version specified by ``as_version``. + :raises ValueError: If the Allele cannot be serialized for ``as_version``. See + ``_ga4gh_serialize_as_1_3`` and ``_ga4gh_serialize_as_2_0``. + """ + if as_version == PrevVrsVersion.V1_3: + return self._ga4gh_serialize_as_1_3() + if as_version == PrevVrsVersion.V2_0: + return self._ga4gh_serialize_as_2_0() + msg = f"Received an unexpected value for `as_version`: {as_version}. MUST be an instance of `PrevVrsVersion`." + raise TypeError(msg) + + def _ga4gh_serialize_as_1_3(self) -> str: + """Return a serialized string following VRS 1.3 Allele serialization. + :raises ValueError: If ``state`` is not a ``LiteralSequenceExpression`` or ``ReferenceLengthExpression``; ``state.sequence`` is null. @@ -902,7 +932,7 @@ def ga4gh_serialize_as_version(self, as_version: PrevVrsVersion) -> str: :raises TypeError: If the requested version is unsupported. :return: Serialization for the requested prior version. """ - location_digest = self.location.compute_digest(as_version=as_version) + location_digest = self.location.compute_digest(as_version=PrevVrsVersion.V1_3) if not isinstance( self.state, LiteralSequenceExpression | ReferenceLengthExpression @@ -915,16 +945,56 @@ def ga4gh_serialize_as_version(self, as_version: PrevVrsVersion) -> str: if sequence is None: raise ValueError("State sequence attribute must be defined.") - if as_version == PrevVrsVersion.V1_3: - return f'{{"location":"{location_digest}","state":{{"sequence":"{sequence}","type":"LiteralSequenceExpression"}},"type":"Allele"}}' - msg = f"Received an unexpected value for `as_version`: {as_version}. MUST be an instance of `PrevVrsVersion`." - raise TypeError(msg) + return f'{{"location":"{location_digest}","state":{{"sequence":"{sequence}","type":"LiteralSequenceExpression"}},"type":"Allele"}}' + + def _ga4gh_serialize_as_2_0(self) -> str: + """Return a serialized string following VRS 2.0 Allele serialization. + + VRS 2.0 normalization selected the largest valid repeat subunit length for + reference-derived insertions (``ReferenceLengthExpression`` ``length`` greater + than the location span); VRS 2.1 selects the smallest. The valid lengths are the + multiples of the smallest that divide the insertion length and fit within the + span. All other states serialize the same in VRS 2.0 and 2.1. + + :raises ValueError: If a ``ReferenceLengthExpression`` ``state`` is not on a + ``SequenceLocation`` with int or indefinite Range coordinates, has a Range + ``length``, or has a ``repeatSubunitLength`` inconsistent with a normalized + insertion + """ + state = self.state + if isinstance(state, ReferenceLengthExpression): + if not isinstance(self.location, SequenceLocation) or not isinstance( + state.length, int + ): + msg = "A VRS 2.0 `ReferenceLengthExpression` requires a `SequenceLocation` and an int `length`" + raise ValueError(msg) + ref_length = _interval_value(self.location.end) - _interval_value( + self.location.start + ) + insert_length = state.length - ref_length + if insert_length > 0: + p = state.repeatSubunitLength + multiples = range(p, ref_length + 1, p) if p > 0 else [] + valid = [c for c in multiples if insert_length % c == 0] + if not valid: + msg = ( + f"repeatSubunitLength {p} is inconsistent with a normalized " + f"insertion of {insert_length} residues into a {ref_length} " + "residue span" + ) + raise ValueError(msg) + state = state.model_copy(update={"repeatSubunitLength": valid[-1]}) + allele = self.model_copy(update={"state": state}) + return encode_canonical_json(allele.ga4gh_serialize()).decode("utf-8") class ga4gh(Ga4ghIdentifiableObject.ga4gh): # noqa: N801 """Define GA4GH serialization metadata for this model.""" prefix = "VA" - priorPrefix = {PrevVrsVersion.V1_3.value: "VA"} # noqa: N815 + priorPrefix = { # noqa: N815 + PrevVrsVersion.V1_3.value: "VA", + PrevVrsVersion.V2_0.value: "VA", + } inherent = ["location", "state", "type"] diff --git a/tests/test_vrs.py b/tests/test_vrs.py index 47e372e0..2c8a1a2a 100644 --- a/tests/test_vrs.py +++ b/tests/test_vrs.py @@ -2,6 +2,7 @@ from pydantic import ValidationError from ga4gh.core import ( + PrevVrsVersion, VrsObjectIdentifierIs, ga4gh_digest, ga4gh_identify, @@ -383,3 +384,101 @@ def test_compute_identifiers_when(): with use_ga4gh_compute_identifier_when(VrsObjectIdentifierIs.MISSING): assert ga4gh_identify(vo_a, in_place="never") == correct_id assert ga4gh_identify(vo_a, in_place="never") is correct_id + + +def _rle_allele( + start: int | list[int | None], + end: int | list[int | None], + length: int | list[int], + repeat_subunit_length: int, +) -> models.Allele: + """Build a GRCh38 chr1 Allele with a ReferenceLengthExpression state""" + return models.Allele( + location=models.SequenceLocation( + sequenceReference=models.SequenceReference( + refgetAccession="SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO" + ), + start=start, + end=end, + ), + state=models.ReferenceLengthExpression( + length=length, repeatSubunitLength=repeat_subunit_length + ), + ) + + +@pytest.mark.parametrize( + ("allele", "expected_id", "expected_2_0_id"), + [ + # A x 9 + AA: subunit lengths 1 and 2 are valid (2.0 id from vrs-python main) + pytest.param( + _rle_allele(236900409, 236900418, 11, 1), + "ga4gh:VA.b3Q0IQnr9q2zhTZtnn5vYvO1-wQL2yQv", + "ga4gh:VA.ZaXCGjhs7Tu13b0azh6oIxiZzKfkLOhp", + id="poly_a_ins", + ), + # (GT) x 5 + GTGT: subunit lengths 2 and 4 are valid (2.0 id from vrs-python main) + pytest.param( + _rle_allele(1007173, 1007183, 14, 2), + "ga4gh:VA.ahwf1XfAC63L8RgfDNqv0jORnM-W31SC", + "ga4gh:VA.kkbrHw87FMI-ePHgyzrCFAFTqVXJqTkQ", + id="microsatellite_ins", + ), + pytest.param( + _rle_allele([None, 236900409], [236900418, None], 11, 1), + "ga4gh:VA.qLrGhMXYoXALZ_NTcYO3Bh-TOzCRW8gj", + "ga4gh:VA.Octo9VAsfwhgSoOIMQ25UJPxBR0O3_Th", + id="indefinite_range_ins", + ), + # Deletions are the same in VRS 2.0 and 2.1 + pytest.param( + _rle_allele(40819438, 40819446, 5, 3), + "ga4gh:VA.kL06ErFmanQt9ZsXkcdpd7qSbJ8sXmj7", + "ga4gh:VA.kL06ErFmanQt9ZsXkcdpd7qSbJ8sXmj7", + id="deletion", + ), + ], +) +def test_vrs_2_0_identify(allele, expected_id, expected_2_0_id): + """`as_version` 2.0 uses the largest valid repeat subunit length""" + assert ga4gh_identify(allele, in_place="never") == expected_id + assert ga4gh_identify(allele, as_version=PrevVrsVersion.V2_0) == expected_2_0_id + assert ga4gh_identify( + allele.location, as_version=PrevVrsVersion.V2_0 + ) == ga4gh_identify(allele.location, in_place="never") + + +@pytest.mark.parametrize( + ("allele", "match"), + [ + pytest.param( + _rle_allele(1007173, 1007183, 14, 3), + "repeatSubunitLength 3 is inconsistent", + id="subunit_not_factor_of_insertion", + ), + pytest.param( + _rle_allele([236900400, 236900409], 236900418, 11, 1), + "Expected an int or indefinite Range coordinate", + id="definite_range", + ), + pytest.param( + _rle_allele(236900409, 236900418, [10, 12], 1), + "requires a `SequenceLocation` and an int `length`", + id="range_length", + ), + pytest.param( + models.Allele( + location="ga4gh:SL.shRADI_uRNo_P7bKGqD7Hrsw6iAkXciO", + state=models.ReferenceLengthExpression( + length=11, repeatSubunitLength=1 + ), + ), + "requires a `SequenceLocation` and an int `length`", + id="iri_reference_location", + ), + ], +) +def test_vrs_2_0_identify_errors(allele, match): + """`as_version` 2.0 rejects RLE Alleles that VRS 2.1 normalization cannot produce""" + with pytest.raises(ValueError, match=match): + ga4gh_identify(allele, as_version=PrevVrsVersion.V2_0) From 83550c8bb5b283686caa63bb72bf14036caf6573 Mon Sep 17 00:00:00 2001 From: Kyle Ferriter Date: Tue, 10 Nov 2026 11:23:53 -0500 Subject: [PATCH 3/3] fix: recompute nested digests for VRS 2.0 Allele ids Stop the subunit factor search at the first factor longer than the span, document the smallest-subunit assumption, and add type hints to the new tests. --- src/ga4gh/vrs/models.py | 21 +++++++++++++++++---- src/ga4gh/vrs/normalize.py | 3 ++- tests/test_vrs.py | 11 +++++++++-- tests/test_vrs_normalize.py | 8 ++++++-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/ga4gh/vrs/models.py b/src/ga4gh/vrs/models.py index a58bf1b6..93319c6a 100644 --- a/src/ga4gh/vrs/models.py +++ b/src/ga4gh/vrs/models.py @@ -956,10 +956,17 @@ def _ga4gh_serialize_as_2_0(self) -> str: multiples of the smallest that divide the insertion length and fit within the span. All other states serialize the same in VRS 2.0 and 2.1. + This assumes ``repeatSubunitLength`` is the smallest valid subunit, as produced + by VRS 2.1 normalization. Verifying that requires the reference sequence, so only + inconsistencies detectable from the Allele alone raise an error. + + Nested digests are recomputed rather than read from a cached ``digest``, and are + not stored on this Allele or its location. + :raises ValueError: If a ``ReferenceLengthExpression`` ``state`` is not on a ``SequenceLocation`` with int or indefinite Range coordinates, has a Range - ``length``, or has a ``repeatSubunitLength`` inconsistent with a normalized - insertion + ``length``, or has a ``repeatSubunitLength`` that is not a factor of the + insertion length within the span """ state = self.state if isinstance(state, ReferenceLengthExpression): @@ -984,8 +991,14 @@ def _ga4gh_serialize_as_2_0(self) -> str: ) raise ValueError(msg) state = state.model_copy(update={"repeatSubunitLength": valid[-1]}) - allele = self.model_copy(update={"state": state}) - return encode_canonical_json(allele.ga4gh_serialize()).decode("utf-8") + location = ( + self.location.compute_digest(as_version=PrevVrsVersion.V2_0) + if isinstance(self.location, SequenceLocation) + else self.location.ga4gh_serialize() + ) + return encode_canonical_json( + {"location": location, "state": state.ga4gh_serialize(), "type": self.type} + ).decode("utf-8") class ga4gh(Ga4ghIdentifiableObject.ga4gh): # noqa: N801 """Define GA4GH serialization metadata for this model.""" diff --git a/src/ga4gh/vrs/normalize.py b/src/ga4gh/vrs/normalize.py index 072c7699..1931a2dd 100644 --- a/src/ga4gh/vrs/normalize.py +++ b/src/ga4gh/vrs/normalize.py @@ -243,7 +243,8 @@ def _normalize_allele( factors = _factor_gen(seed_length) for cycle_length in factors: if cycle_length > len_extended_ref: - continue + # factors are ascending, so all remaining factors are too long + break cycle_start = len_extended_ref - cycle_length if _is_valid_cycle(cycle_start, extended_ref_seq, extended_alt_seq): _set_location_from_interval( diff --git a/tests/test_vrs.py b/tests/test_vrs.py index 2c8a1a2a..c1f83d18 100644 --- a/tests/test_vrs.py +++ b/tests/test_vrs.py @@ -439,7 +439,9 @@ def _rle_allele( ), ], ) -def test_vrs_2_0_identify(allele, expected_id, expected_2_0_id): +def test_vrs_2_0_identify( + allele: models.Allele, expected_id: str, expected_2_0_id: str +) -> None: """`as_version` 2.0 uses the largest valid repeat subunit length""" assert ga4gh_identify(allele, in_place="never") == expected_id assert ga4gh_identify(allele, as_version=PrevVrsVersion.V2_0) == expected_2_0_id @@ -447,6 +449,11 @@ def test_vrs_2_0_identify(allele, expected_id, expected_2_0_id): allele.location, as_version=PrevVrsVersion.V2_0 ) == ga4gh_identify(allele.location, in_place="never") + # 2.0 ids are recomputed, not read from a cached (here stale) location digest + stale = allele.model_copy(deep=True) + stale.location.digest = "0" * 32 + assert ga4gh_identify(stale, as_version=PrevVrsVersion.V2_0) == expected_2_0_id + @pytest.mark.parametrize( ("allele", "match"), @@ -478,7 +485,7 @@ def test_vrs_2_0_identify(allele, expected_id, expected_2_0_id): ), ], ) -def test_vrs_2_0_identify_errors(allele, match): +def test_vrs_2_0_identify_errors(allele: models.Allele, match: str) -> None: """`as_version` 2.0 rejects RLE Alleles that VRS 2.1 normalization cannot produce""" with pytest.raises(ValueError, match=match): ga4gh_identify(allele, as_version=PrevVrsVersion.V2_0) diff --git a/tests/test_vrs_normalize.py b/tests/test_vrs_normalize.py index fbb257ab..a3196db0 100644 --- a/tests/test_vrs_normalize.py +++ b/tests/test_vrs_normalize.py @@ -3,7 +3,11 @@ import pytest from ga4gh.vrs import models, normalize -from ga4gh.vrs.dataproxy import DataProxyValidationError, SeqRepoDataProxy +from ga4gh.vrs.dataproxy import ( + DataProxyValidationError, + SeqRepoDataProxy, + SeqRepoRESTDataProxy, +) # Single nucleotide same-as-reference allele. allele_dict1 = { @@ -1008,7 +1012,7 @@ def test_normalize_location_out_of_bounds( @pytest.mark.vcr -def test_normalize_rle_smallest_subunit(rest_dataproxy): +def test_normalize_rle_smallest_subunit(rest_dataproxy: SeqRepoRESTDataProxy) -> None: """A reference-derived insertion uses the smallest valid repeat subunit length. Inserting GTGT into chr1 (GT) x 5: of the factors of seed length 4, 1 is not valid, and 2 is selected over 4 (VRS 2.0 selected 4).