Coverage for src/python/ensembl/vep/corpus/golden/base.py: 98%
42 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"""The golden corpus model."""
16from __future__ import annotations
18from contextlib import AbstractContextManager
20from attrs import define, field
22from ensembl.vep.corpus.base import Corpus, NamedOverlap, NamedVariant
23from ensembl.vep.corpus.golden.terms import GoldenTerms
24from ensembl.vep.corpus.spec import CorpusSpec
25from ensembl.vep.models.genic import Transcript
26from ensembl.vep.models.sequence import Slice
28__all__ = ["GoldenCorpus"]
31@define(kw_only=True, auto_attribs=True)
32class GoldenCorpus(Corpus):
33 """Pair a corpus with pinned expected consequence terms.
35 Attributes:
36 spec (CorpusSpec): Specification identifying the golden dataset.
37 corpus (Corpus): Loaded or generated corpus whose overlaps the terms describe.
38 expected_terms (GoldenTerms): Pinned consequences for the wrapped corpus.
39 resource_context (AbstractContextManager[object] | None): Context retaining packaged
40 files for the lifetime of the corpus.
41 """
43 _spec: CorpusSpec = field(alias="spec")
44 corpus: Corpus
45 expected_terms: GoldenTerms
46 resource_context: AbstractContextManager[object] | None = field(default=None, repr=False)
47 _closed: bool = field(default=False, init=False, repr=False)
49 @property
50 def spec(self) -> CorpusSpec:
51 """Return the golden corpus specification."""
52 return self._spec
54 @property
55 def sequence_regions(self) -> tuple[Slice, ...]:
56 """Return the wrapped sequence regions."""
57 return self.corpus.sequence_regions
59 @property
60 def named_variants(self) -> tuple[NamedVariant, ...]:
61 """Return the wrapped variants."""
62 return self.corpus.named_variants
64 @property
65 def transcripts(self) -> tuple[Transcript, ...]:
66 """Return the wrapped transcripts."""
67 return self.corpus.transcripts
69 @property
70 def named_overlaps(self) -> tuple[NamedOverlap, ...]:
71 """Return the wrapped overlaps."""
72 return self.corpus.named_overlaps
74 @property
75 def description(self) -> str:
76 """Return a short golden-corpus description."""
77 return f"golden corpus ({self.spec.parameter('dataset', 'default')})"
79 def close(self) -> None:
80 """Release the wrapped corpus and packaged-resource context once."""
81 if self._closed:
82 return
83 self._closed = True
84 try:
85 self.corpus.close()
86 finally:
87 if self.resource_context is not None:
88 self.resource_context.__exit__(None, None, None)