Coverage for src/python/ensembl/vep/annotators/base.py: 100%

12 statements  

« 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"""Annotator protocol shared by all annotation domains. 

15 

16``Annotator`` is the contract callers depend on. ``registry.get_annotator`` returns one without 

17requiring inheritance, allowing Python and native implementations to share the registry. The 

18protocol exposes single-overlap and batch annotation; implementations may derive either operation 

19from the other. 

20""" 

21 

22from __future__ import annotations 

23 

24from collections.abc import Sequence 

25from typing import Protocol, TypeVar, runtime_checkable 

26 

27from ensembl.vep.models.overlap import FeatureOverlap 

28 

29__all__ = ["Annotator", "ResultT"] 

30 

31ResultT = TypeVar("ResultT") 

32"""What an annotator produces per overlap.""" 

33 

34 

35@runtime_checkable 

36class Annotator(Protocol[ResultT]): 

37 """Define the common contract for annotators producing ``ResultT``. 

38 

39 Attributes: 

40 name (str): The registry name this annotator is registered under, e.g. "consequence.linear". 

41 """ 

42 

43 name: str 

44 

45 def annotate_feature_overlap(self, overlap: FeatureOverlap) -> list[ResultT]: 

46 """Annotate a feature overlap. 

47 

48 Args: 

49 overlap (FeatureOverlap): The overlap to annotate. 

50 

51 Returns: 

52 list[ResultT]: What this annotator produces for the overlap. May be empty -- for a 

53 consequence annotator that means callers apply the default/fallback term (e.g. 

54 ``intergenic_variant``) themselves rather than the annotator doing so. 

55 """ 

56 raise NotImplementedError 

57 

58 def annotate_feature_overlaps(self, overlaps: Sequence[FeatureOverlap]) -> list[list[ResultT]]: 

59 """Annotate a batch of feature overlaps at once. 

60 

61 Args: 

62 overlaps (Sequence[FeatureOverlap]): The overlaps to annotate, in order. 

63 

64 Returns: 

65 list[list[ResultT]]: One result list per input overlap, in the same order as 

66 ``overlaps``. 

67 """ 

68 raise NotImplementedError