Coverage for src/python/ensembl/vep/corpus/synthetic/base.py: 100%
41 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 synthetic corpus model."""
16from __future__ import annotations
18from attrs import field, frozen
19from attrs.validators import instance_of
21from ensembl.vep.corpus.base import Corpus, NamedOverlap, NamedVariant
22from ensembl.vep.corpus.spec import CorpusSpec
23from ensembl.vep.corpus.validation import validate_corpus
24from ensembl.vep.models.genic import Transcript
25from ensembl.vep.models.overlap import TranscriptVariationAllele
26from ensembl.vep.models.sequence import Slice
27from ensembl.vep.models.variation import VariationAllele
29__all__ = [
30 "SyntheticCorpus",
31]
34@frozen(kw_only=True, auto_attribs=True)
35class SyntheticCorpus(Corpus):
36 """A synthetic chromosome slice, its transcripts, variants, and named variant overlaps.
38 Attributes:
39 spec (CorpusSpec): Specification used to generate the corpus.
40 synthetic_slice (Slice): The whole-chromosome slice every feature and variant is
41 expressed against.
42 named_variants (tuple[tuple[str, VariationAllele], ...]): Every generated variant, including
43 variants that do not overlap any transcript.
44 transcripts (tuple[Transcript, ...]): Every transcript in the corpus.
45 named_overlaps (tuple[tuple[str, TranscriptVariationAllele], ...]): (name, overlap) pairs,
46 suitable for ``pytest.mark.parametrize`` IDs.
47 """
49 _synthetic_slice: Slice = field(alias="synthetic_slice")
50 _named_variants: tuple[tuple[str, VariationAllele], ...] = field(
51 validator=instance_of(tuple), alias="named_variants"
52 )
53 _transcripts: tuple[Transcript, ...] = field(
54 factory=tuple, validator=instance_of(tuple), alias="transcripts"
55 )
56 _named_overlaps: tuple[tuple[str, TranscriptVariationAllele], ...] = field(
57 factory=tuple, validator=instance_of(tuple), alias="named_overlaps"
58 )
59 _spec: CorpusSpec = field(factory=lambda: CorpusSpec(kind="synthetic.default"), alias="spec")
61 def __attrs_post_init__(self) -> None:
62 """Validate identities shared by the variant and overlap views of the corpus."""
63 validate_corpus(
64 self.sequence_regions,
65 self.named_variants,
66 self.transcripts,
67 self.named_overlaps,
68 )
70 @property
71 def spec(self) -> CorpusSpec:
72 """Return the specification that generated the corpus."""
73 return self._spec
75 @property
76 def synthetic_slice(self) -> Slice:
77 """Return the synthetic sequence region."""
78 return self._synthetic_slice
80 @property
81 def sequence_regions(self) -> tuple[Slice, ...]:
82 """Return the synthetic sequence region as a one-item sequence."""
83 return (self._synthetic_slice,)
85 @property
86 def named_variants(self) -> tuple[NamedVariant, ...]:
87 """Return every generated variant."""
88 return self._named_variants
90 @property
91 def transcripts(self) -> tuple[Transcript, ...]:
92 """Return every generated transcript."""
93 return self._transcripts
95 @property
96 def named_overlaps(self) -> tuple[NamedOverlap, ...]:
97 """Return every generated transcript overlap."""
98 return self._named_overlaps
100 @property
101 def description(self) -> str:
102 """Return a short synthetic-corpus description."""
103 return f"synthetic corpus ({self.spec.kind})"