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

25 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 the default ``run`` path and its summary file.""" 

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.sections.base import ConfigSection 

25 

26__all__ = ["RunConfig"] 

27 

28_STDOUT_SPELLINGS = frozenset({"stdout", "-"}) 

29 

30 

31def _as_output_file(value: Path | str | None) -> Path | None: 

32 """Map the stdout spellings, and an empty value, to ``None``; read anything else as a path.""" 

33 if value is None: 

34 return None 

35 text = str(value) 

36 if text.lower() in _STDOUT_SPELLINGS: 

37 return None 

38 return Path(text) 

39 

40 

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

42class RunConfig(ConfigSection): 

43 """Where annotation output and the run summary go. 

44 

45 The summary is produced by the run itself and written unless ``no_stats`` is set, matching 

46 Perl VEP. It is cheap enough to default on: aggregating it costs roughly a microsecond per 

47 overlap, against a fact layer that is called about ninety times more often. 

48 

49 Attributes: 

50 output_file (Path | None): Annotation output path, or None to stream to stdout. ``STDOUT`` 

51 (any case) and ``-`` mean stdout, as they do in Perl VEP. 

52 output_format (str): Annotation output format. Defaults to ``vcf``; Perl VEP defaults to ``vep``, 

53 which has no writer yet. 

54 force_overwrite (bool): Overwrite ``output_file`` if it already exists. 

55 no_progress (bool): Suppress interactive variant progress. 

56 no_stats (bool): Suppress the run summary entirely. 

57 stats_file (Path | None): Summary path, or None to derive ``<output_file>_summary.html`` 

58 (no summary file when output goes to stdout). 

59 stats_format (str): Summary format. 

60 """ 

61 

62 section_name: ClassVar[str] = "run" 

63 

64 output_file: Path | None = field( 

65 default=Path("variant_effect_output.txt"), 

66 converter=_as_output_file, 

67 metadata=option("annotation output file", short="o"), 

68 ) 

69 output_format: str = field( 

70 default="vcf", 

71 metadata=option( 

72 "annotation output format (Perl VEP defaults to its own 'vep' format, " 

73 "which has no writer here yet)", 

74 constants={"vcf": "vcf", "json": "json"}, 

75 ), 

76 ) 

77 force_overwrite: bool = field( 

78 default=False, 

79 metadata=option("overwrite an existing output file", synonyms=("force",)), 

80 ) 

81 no_progress: bool = field(default=False, metadata=option("do not show variant progress")) 

82 no_stats: bool = field(default=False, metadata=option("do not write a run summary")) 

83 stats_file: Path | None = field( 

84 default=None, metadata=option("run summary output file", synonyms=("sf",)) 

85 ) 

86 stats_format: str = field( 

87 default="html", 

88 metadata=option( 

89 "run summary format", 

90 choices=("html", "text", "json"), 

91 constants={"stats_html": "html", "stats_text": "text"}, 

92 ), 

93 )