Coverage for src/python/ensembl/vep/explain/annotate.py: 100%

16 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"""Traced annotation of one overlap.""" 

15 

16from __future__ import annotations 

17 

18from typing import Any 

19 

20from attrs import asdict 

21 

22from ensembl.vep.annotators.factory import build_annotator 

23from ensembl.vep.config import Config 

24from ensembl.vep.models.overlap import TranscriptVariationAllele 

25from ensembl.vep.trace import AnnotationTrace, annotation_tracing 

26 

27__all__ = ["NO_TRACE", "annotate_with_trace"] 

28 

29NO_TRACE = ( 

30 "the native rust.* annotators never record a trace. That is not a gap: every annotator is " 

31 "proven byte-identical to consequence.linear by the conformance suite, so the same overlap " 

32 "run through consequence.linear has the same derivation to show." 

33) 

34 

35 

36def annotate_with_trace( 

37 config: Config, annotator_name: str, overlap: TranscriptVariationAllele 

38) -> tuple[list[str], AnnotationTrace | None]: 

39 """Run one annotator over one overlap with tracing on. 

40 

41 Args: 

42 config (Config): The run's configuration, for the annotator and cache options. 

43 annotator_name (str): A registered annotator name. 

44 overlap (TranscriptVariationAllele): The overlap to annotate. 

45 

46 Returns: 

47 tuple[list[str], AnnotationTrace | None]: The emitted terms, and the derivation -- None 

48 for a native rust.* annotator, which never traces. 

49 """ 

50 options: dict[str, Any] = asdict(config.annotation) 

51 options["annotator"] = annotator_name 

52 annotator = build_annotator( 

53 **options, 

54 upstream_distance=config.source.upstream_distance, 

55 downstream_distance=config.source.downstream_distance, 

56 ) 

57 with annotation_tracing(quiet=config.logging.effective_level().upper() != "DEBUG"): 

58 consequences = annotator.annotate_feature_overlap(overlap) 

59 return [consequence.term for consequence in consequences], getattr(annotator, "last_trace", None)