Coverage for src/python/ensembl/vep/models/genic/translation.py: 100%

24 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"""Translation class.""" 

15 

16from __future__ import annotations 

17 

18from typing import TYPE_CHECKING 

19from functools import cached_property 

20from threading import RLock 

21from attrs import define, field 

22 

23from ensembl.vep.common import invalidates 

24 

25if TYPE_CHECKING: 

26 from ensembl.vep.models.genic import Transcript 

27 

28 

29@define(kw_only=True, auto_attribs=True) 

30class Translation: 

31 """ 

32 Represents a translation. 

33 

34 Attributes: 

35 start (int): 

36 The start position of the translation on the transcript, 

37 relative to the start of the transcript. 

38 end (int): 

39 The end position of the translation on the transcript, 

40 relative to the start of the transcript. 

41 stable_id (str): 

42 Ensembl stable transcript identifier (e.g. "ENST00000366667"). 

43 version (int | None): 

44 Version of the stable identifier. 

45 seq (str | None): 

46 The amino acid sequence of the translation. 

47 transcript (Transcript | None): 

48 The transcript to which this translation belongs. 

49 exon_coding_start (int | None): 

50 The position of the first coding base in the start exon, relative to the start of 

51 the exon (1-based). 

52 exon_coding_end (int | None): 

53 The position of the last coding base in the end exon, relative to the start of the 

54 exon (1-based). 

55 derived_from_coding_sequence (bool): 

56 Whether ``seq`` was computed by ``Transcript._translation`` from this transcript's own 

57 ``coding_sequence``, as opposed to seeded from an external source that may curate it 

58 differently (for example without a trailing stop, or with selenocysteine edits). 

59 ``False`` by default and for every externally seeded translation; set True only at the 

60 one place that derives ``seq`` this way (``Transcript._translation``). 

61 """ 

62 

63 start: int = field(on_setattr=invalidates("_length")) 

64 end: int = field(on_setattr=invalidates("_length")) 

65 stable_id: str 

66 version: int | None = field(default=None, init=False) 

67 seq: str | None = field(default=None, init=False) 

68 transcript: Transcript | None = field(default=None, init=False) 

69 exon_coding_start: int | None = field(default=None) 

70 exon_coding_end: int | None = field(default=None) 

71 derived_from_coding_sequence: bool = field(default=False, init=False) 

72 _lock: RLock = field(factory=RLock, init=False, repr=False) 

73 

74 @property 

75 def length(self) -> int: 

76 """Public accessor for _length. 

77 

78 Returns: 

79 int: The length of the translation. 

80 """ 

81 return self._length 

82 

83 @cached_property 

84 def _length(self) -> int: 

85 """ 

86 Returns the length of the feature. 

87 

88 Returns: 

89 int: The length of the feature. 

90 """ 

91 return self.end - self.start + 1