Coverage for src/python/ensembl/vep/config/sections/catalogue/add.py: 100%

23 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"""Options for adding a catalogue term.""" 

15 

16from __future__ import annotations 

17 

18from typing import ClassVar 

19 

20from attrs import define, field 

21 

22from ensembl.vep.config.option_spec import option 

23from ensembl.vep.config.sections.base import ConfigSection 

24 

25__all__ = ["CatalogueAddConfig"] 

26 

27 

28def _impact_names() -> tuple[str, ...]: 

29 """Return the impact buckets a term may be assigned. 

30 

31 Resolved lazily so this module never imports ``ensembl.vep.common``, 

32 which loads ``ensembl_vep_core``. 

33 """ 

34 # pylint: disable=import-outside-toplevel 

35 from ensembl.vep.common import ConsequenceImpact 

36 

37 return tuple(impact.value for impact in ConsequenceImpact) 

38 

39 

40@define(frozen=True, kw_only=True, auto_attribs=True) 

41class CatalogueAddConfig(ConfigSection): 

42 """The term being added. 

43 

44 Attributes: 

45 term (str | None): The SO term to add. 

46 accession (str | None): Its SO accession. 

47 rank (int | None): 1-based rank to insert at, or None to append after the highest. 

48 tier (int): Tier grouping. 

49 impact (str | None): Impact bucket. 

50 so_parent (tuple[str, ...]): SO parent accessions, used to derive ``subsumes``. 

51 subsumes (tuple[str, ...]): Extra terms to subsume, on top of the derived ones. 

52 no_derive_subsumes (bool): Skip deriving from ``so_parent``. 

53 when (str | None): The ``when`` payload as JSON. Never inferred: a wrong formula is the one 

54 error conformance cannot catch, since every annotator would agree on it. 

55 allow_missing_when (bool): Write the entry as a placeholder rather than refusing. 

56 notes (str | None): Free-text notes. 

57 """ 

58 

59 section_name: ClassVar[str] = "catalogue_add" 

60 

61 term: str | None = field(default=None, metadata=option("the SO term to add")) 

62 accession: str | None = field(default=None, metadata=option("SO accession", metavar="SO:XXXXXXX")) 

63 rank: int | None = field(default=None, metadata=option("rank to insert at", metavar="N")) 

64 tier: int = field(default=3, metadata=option("tier grouping")) 

65 impact: str | None = field(default=None, metadata=option("impact bucket", choices=_impact_names)) 

66 so_parent: tuple[str, ...] = field( 

67 default=(), metadata=option("SO parent accessions, used to derive subsumes") 

68 ) 

69 subsumes: tuple[str, ...] = field(default=(), metadata=option("extra terms to subsume")) 

70 no_derive_subsumes: bool = field(default=False, metadata=option("do not derive subsumes from so_parent")) 

71 when: str | None = field(default=None, metadata=option("the when payload as JSON", metavar="JSON")) 

72 allow_missing_when: bool = field( 

73 default=False, metadata=option("accept an entry with no when, as a placeholder") 

74 ) 

75 notes: str | None = field(default=None, metadata=option("free-text notes"))