Coverage for src/python/ensembl/vep/common/containers.py: 100%

47 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"""Common containers. 

15 

16Containers are for collection data (generally without any behavior). 

17""" 

18 

19from __future__ import annotations 

20 

21from attrs import frozen 

22 

23 

24@frozen(kw_only=True, auto_attribs=True) 

25class Locus: 

26 """Container for a genomic position and (optionally) alleles. 

27 

28 Attributes: 

29 seq_region_name (str | None): Name of the sequence region. 

30 start (int): Start position of the locus. 

31 end (int): End position of the locus. 

32 allele_string (str | None): String representation of the alleles. 

33 It could be in the format "{reference_allele}/{alternate_allele}", or just "allele" 

34 where allele could be either reference or alternate. 

35 """ 

36 

37 seq_region_name: str | None = None 

38 start: int 

39 end: int 

40 allele_string: str | None = None 

41 

42 

43@frozen(kw_only=True, auto_attribs=True) 

44class Attribute: 

45 """Container for an attribute of a feature. 

46 

47 Attributes: 

48 name (str): Name of the attribute. 

49 value (str): Value of the attribute. 

50 code (str | None): Code of the attribute. 

51 description (str | None): Description of the attribute. 

52 """ 

53 

54 name: str 

55 value: str 

56 code: str | None = None 

57 description: str | None = None 

58 

59 

60@frozen(kw_only=True, auto_attribs=True) 

61class ExternalDB: 

62 """Container for external database information. 

63 

64 Attributes: 

65 id (str): Unique identifier for the external database. 

66 name (str): Name of the external database. 

67 description (str | None): Description of the external database. 

68 url (str | None): URL where this external database can be accessed. 

69 release (str | None): Release version of the external database. 

70 """ 

71 

72 id: str 

73 name: str 

74 description: str | None = None 

75 url: str | None = None 

76 release: str | None = None 

77 

78 

79@frozen(kw_only=True, auto_attribs=True) 

80class ExternalReference: 

81 """Container for external reference information. 

82 

83 Attributes: 

84 accession_id (str): Accession ID of the external reference. 

85 name (str): Name of the external reference. 

86 description (str | None): Description of the external reference. 

87 assignment_method (str | None): Method used to assign this reference, e.g., DIRECT. 

88 url (str | None): URL where this external reference can be accessed. 

89 source (ExternalDB): Source database for this reference. 

90 """ 

91 

92 accession_id: str 

93 name: str 

94 description: str | None = None 

95 assignment_method: str | None = None 

96 url: str | None = None 

97 source: ExternalDB | None = None 

98 

99 

100@frozen(kw_only=True, auto_attribs=True) 

101class PredictionResult: 

102 """Container for a prediction result of a program. 

103 

104 Attributes: 

105 plugin_name (str): Name of the plugin that generated this prediction. 

106 consequence (str): Consequence term predicted by the plugin. 

107 score (float | None): Score associated with the prediction, if applicable. 

108 description (str | None): Description of the prediction. 

109 """ 

110 

111 tool: str 

112 # Need something more generic and can be used for both plugins and custom annotation 

113 # plugin gets attached to FeatureOverlap and works on FeatureOverlap after overlap computation is done 

114 # custom annotation after doing overlap computation gets attached to VFA 

115 # The data shape varies widely, e.g. SpliceAI, SIFT/PolyPhen; 

116 # Should we use a dict? the values can be int/str/tuple. 

117 score: int 

118 result: str 

119 classification: float | None = None 

120 version: str | None = None 

121 modes: tuple[str] | tuple[()] = () 

122 reference_data: tuple[ExternalDB] | tuple[()] = () 

123 

124 

125@frozen(kw_only=True, auto_attribs=True) 

126class SequenceEdit: 

127 """Container for edit caused by a variant on a spliced sequence. 

128 

129 Offsets are relative to whatever ``Mapper`` produced them, for example, same variant yields a 

130 different ``SequenceEdit`` against a CDS mapper than against a cDNA mapper. 

131 

132 Attributes: 

133 footprint (tuple[int, int]): ``(low, high)`` inclusive offsets the variant covers. 

134 start (int): Start of the half-open range to replace. 

135 end (int): End of that range, exclusive. Equal to ``start`` for a pure insertion. 

136 replacement (str): The allele string to replace with. Generally the alternate allele, strand-corrected 

137 to transcript sense and empty for a pure deletion. 

138 """ 

139 

140 footprint: tuple[int, int] 

141 start: int 

142 end: int 

143 replacement: str 

144 

145 @property 

146 def length_change(self) -> int: 

147 """Net change in sequence length this edit makes. 

148 

149 The change in sequence length is calculated as (replaced allele length - edited allele 

150 length). Derived 

151 here rather than at each call site so the arithmetic lives next to the geometry it comes from. 

152 

153 Returns: 

154 int: The net length change. 

155 """ 

156 return len(self.replacement) - (self.end - self.start)