Coverage for src/python/ensembl/vep/config/sections/explain/explain.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 explaining a single overlap's derivation.""" 

15 

16from __future__ import annotations 

17 

18from pathlib import Path 

19from typing import ClassVar 

20 

21from attrs import define, field 

22 

23from ensembl.vep.config.option_spec import option 

24from ensembl.vep.config.report import GRAPH_FORMATS 

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

26 

27__all__ = ["ExplainConfig"] 

28 

29EXPLAIN_FORMATS = ("text",) + GRAPH_FORMATS 

30"""A derivation renders as text or as a diagram; it has no tabular form.""" 

31 

32 

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

34class ExplainConfig(ConfigSection): 

35 """Which overlap to explain, and how to render the derivation. 

36 

37 Attributes: 

38 name (str | None): Named overlap to select, for a synthetic corpus. 

39 index (int | None): Overlap position in the corpus, as an alternative to ``name``. 

40 variant (str | None): Variant to select from a real input, as ``CHR:POS:REF>ALT`` or 

41 ``CHR:POS:ID``. 

42 allele_num (int | None): Alternate allele a ``CHR:POS:ID`` variant selects, from 1; None for 

43 the first. 

44 transcript (str | None): Transcript stable id, to disambiguate when several overlap. 

45 compare (tuple[str, ...]): Two annotator names to diff against each other. 

46 list_overlaps (bool): List the selectable overlaps and exit. 

47 graph (bool): Draw the derivation as a diagram rather than printing it. 

48 output_format (str | None): The format to render in, or None for the default of the kind asked 

49 for. Spelled ``--output_format`` because ``--format`` is the input format. 

50 output_file (Path | None): Write the explanation here instead of to stdout. 

51 """ 

52 

53 section_name: ClassVar[str] = "explain" 

54 

55 name: str | None = field(default=None, metadata=option("named overlap to explain")) 

56 index: int | None = field(default=None, metadata=option("overlap index to explain", metavar="N")) 

57 variant: str | None = field( 

58 default=None, 

59 metadata=option( 

60 "variant to explain, by alleles or by the input's own ID", metavar="CHR:POS:REF>ALT|CHR:POS:ID" 

61 ), 

62 ) 

63 allele_num: int | None = field( 

64 default=None, 

65 metadata=option("alternate allele of a CHR:POS:ID variant to explain (default: 1)", metavar="N"), 

66 ) 

67 transcript: str | None = field(default=None, metadata=option("transcript stable id", metavar="STABLE_ID")) 

68 compare: tuple[str, ...] = field( 

69 default=(), metadata=option("two annotators to diff", metavar="NAME,NAME") 

70 ) 

71 list_overlaps: bool = field( 

72 default=False, 

73 metadata=option("list selectable overlaps and exit (see also: vep corpus describe)", flag="list"), 

74 ) 

75 graph: bool = field(default=False, metadata=option("draw the derivation as a diagram")) 

76 output_format: str | None = field( 

77 default=None, 

78 metadata=option("report format (default: text, svg with --graph)", choices=EXPLAIN_FORMATS), 

79 ) 

80 output_file: Path | None = field(default=None, metadata=option("write the explanation here"))