Coverage for src/python/ensembl/vep/config/sections/common/corpus.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"""Registered corpus selection and construction options.""" 

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__ = ["CorpusConfig"] 

27 

28 

29def _corpus_kinds() -> tuple[str, ...]: 

30 """Return registered corpus names. 

31 

32 Resolved lazily so this module never imports ensembl.vep.corpus. 

33 

34 Returns: 

35 tuple[str, ...]: Every registered corpus name, sorted. 

36 """ 

37 # pylint: disable=import-outside-toplevel 

38 from ensembl.vep.corpus.registry import available_corpora 

39 

40 return available_corpora() 

41 

42 

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

44class CorpusConfig(ConfigSection): 

45 """Which registered corpus to build, and how. 

46 

47 Consumed by ensembl.vep.corpus. Seeds are per stream rather than one global seed because the 

48 generator draws the chromosome sequence, the boundary variants and the fuzz variants from 

49 independent ``random.Random`` instances. 

50 

51 Attributes: 

52 kind (str): Registered corpus name. 

53 parameters (tuple[str, ...]): Repeatable factory-owned ``KEY=VALUE`` parameters. JSON 

54 scalar values are decoded; other values remain strings. 

55 fuzz (int): Number of random variants to add to the default corpus. 

56 step (int): Position increment for the heavy-locus variant sweep. 

57 genome_seed (int): Seed for the default corpus's chromosome sequence and transcript layout. 

58 boundary_seed (int): Seed for the adversarial boundary variants. 

59 fuzz_seed (int): Seed for the random fuzz variants. 

60 heavy_genome_seed (int): Seed for the heavy locus's chromosome. Separate from 

61 ``genome_seed`` because the two corpora have always started from different seeds. 

62 sweep_seed (int): Seed for the heavy-locus variant sweep. 

63 corpus_dir (Path | None): Directory to load a saved corpus from, or write one to. 

64 """ 

65 

66 section_name: ClassVar[str] = "corpus" 

67 

68 kind: str = field( 

69 default="synthetic.all", metadata=option("registered corpus to use", choices=_corpus_kinds) 

70 ) 

71 parameters: tuple[str, ...] = field( 

72 factory=tuple, 

73 metadata=option( 

74 "factory parameter as KEY=VALUE (repeatable)", 

75 flag="corpus_parameter", 

76 metavar="KEY=VALUE", 

77 repeatable=True, 

78 ), 

79 ) 

80 fuzz: int = field(default=4000, metadata=option("fuzz variant count", metavar="N")) 

81 step: int = field(default=13, metadata=option("heavy-locus variant sweep step", metavar="N")) 

82 genome_seed: int = field(default=7, metadata=option("seed for the synthetic genome")) 

83 boundary_seed: int = field(default=11, metadata=option("seed for the boundary variants")) 

84 fuzz_seed: int = field(default=23, metadata=option("seed for the fuzz variants")) 

85 heavy_genome_seed: int = field(default=31, metadata=option("seed for the heavy-locus genome")) 

86 sweep_seed: int = field(default=41, metadata=option("seed for the heavy-locus variant sweep")) 

87 corpus_dir: Path | None = field(default=None, metadata=option("directory to load or save a corpus"))