Coverage for src/python/ensembl/vep/matcher/allele.py: 93%
20 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
1# See the NOTICE file distributed with this work for additional information
2# regarding copyright ownership.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Variant-allele association helpers."""
16from __future__ import annotations
18from collections.abc import Iterable
19from typing import TypeVar
21from ensembl.vep.matcher.base import AlleleLike
22from ensembl.vep.matcher.exact import ExactCoordinateMatcher
24__all__ = ["get_matched_variant_alleles"]
26AlleleT = TypeVar("AlleleT", bound="AlleleLike")
27"""The concrete allele type retained by the matching helper."""
30def get_matched_variant_alleles(
31 variation_alleles: Iterable[AlleleT],
32 query: AlleleLike,
33 *,
34 match_reference: bool = True,
35 match_alternate: bool = True,
36) -> list[AlleleT]:
37 """Return alleles with matching coordinates and selected allele strings.
39 Args:
40 variation_alleles (Iterable[AlleleT]): Candidate alleles to inspect.
41 query (AlleleLike): Coordinate and allele values to match.
42 match_reference (bool): Require equal reference strings.
43 match_alternate (bool): Require equal alternate strings.
45 Returns:
46 list[AlleleT]: Matching candidates in their supplied order.
47 """
48 coordinate_matcher = ExactCoordinateMatcher()
49 matched: list[AlleleT] = []
50 for variation_allele in variation_alleles:
51 if not coordinate_matcher.matches(variation_allele, query):
52 continue
53 if match_reference and variation_allele.reference_allele != query.reference_allele: 53 ↛ 54line 53 didn't jump to line 54 because the condition on line 53 was never true
54 continue
55 if match_alternate and variation_allele.alternate_allele != query.alternate_allele:
56 continue
57 matched.append(variation_allele)
58 return matched