|
1
|
|
|
from __future__ import annotations |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
import os |
|
4
|
|
|
import logging |
|
5
|
|
|
from dataclasses import dataclass |
|
6
|
|
|
from pathlib import Path |
|
7
|
|
|
from typing import FrozenSet, Optional, Sequence, Set |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
from chembl_webresource_client.settings import Settings as ChemblSettings |
|
|
|
|
|
|
10
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
from mandos.model.targets import TargetType |
|
13
|
|
|
|
|
14
|
|
|
instance = ChemblSettings.Instance() |
|
15
|
|
|
_IS_IN_CI = "IS_IN_CI" in os.environ |
|
16
|
|
|
if _IS_IN_CI: |
|
17
|
|
|
DEFAULT_MANDOS_CACHE = ( |
|
18
|
|
|
Path(__file__).parent.parent.parent / "tests" / "resources" / ".mandos-cache" |
|
19
|
|
|
) |
|
20
|
|
|
else: |
|
21
|
|
|
DEFAULT_MANDOS_CACHE = Path( |
|
22
|
|
|
{k.lower(): v for k, v in os.environ.items()}.get("MANDOS_HOME", Path.home() / ".mandos") |
|
23
|
|
|
) |
|
24
|
|
|
|
|
25
|
|
|
DEFAULT_CHEMBL_CACHE = DEFAULT_MANDOS_CACHE / "chembl" |
|
26
|
|
|
DEFAULT_TAXONOMY_CACHE = DEFAULT_MANDOS_CACHE / "taxonomy" |
|
27
|
|
|
DEFAULT_BAD_FLAGS = [ |
|
28
|
|
|
"potential missing data", |
|
29
|
|
|
"potential transcription error", |
|
30
|
|
|
"outside typical range", |
|
31
|
|
|
] |
|
32
|
|
|
logger = logging.getLogger("mandos") |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
@dataclass(frozen=True, repr=True) |
|
|
|
|
|
|
36
|
|
|
class Settings: |
|
37
|
|
|
"""""" |
|
38
|
|
|
|
|
39
|
|
|
is_testing: bool |
|
40
|
|
|
traversal_strategy: Optional[str] |
|
41
|
|
|
require_taxon: bool |
|
42
|
|
|
taxon: int |
|
43
|
|
|
allowed_assay_types: FrozenSet[str] |
|
44
|
|
|
allowed_relations: FrozenSet[str] |
|
45
|
|
|
allowed_target_types: FrozenSet[str] |
|
46
|
|
|
banned_flags: FrozenSet[str] |
|
47
|
|
|
require_pchembl: bool |
|
48
|
|
|
min_pchembl: float |
|
49
|
|
|
require_confidence_score: bool |
|
50
|
|
|
min_confidence_score: int |
|
51
|
|
|
min_phase: int |
|
52
|
|
|
random_seed: int |
|
53
|
|
|
n_bootstrap_samples: int |
|
54
|
|
|
cache_path: Path |
|
55
|
|
|
chembl_cache_path: Path |
|
56
|
|
|
n_retries: int |
|
57
|
|
|
fast_save: bool |
|
58
|
|
|
timeout_sec: int |
|
59
|
|
|
use_pubchem_parent: bool |
|
60
|
|
|
min_query_delay: float |
|
61
|
|
|
max_query_delay: float |
|
62
|
|
|
tanimoto_vals: Sequence[float] |
|
63
|
|
|
unicode_ranges: Path |
|
64
|
|
|
stop_words: Path |
|
65
|
|
|
convert_greek: bool |
|
66
|
|
|
|
|
67
|
|
|
@classmethod |
|
68
|
|
|
def load(cls, data: NestedDotDict) -> Settings: |
|
|
|
|
|
|
69
|
|
|
# 117571 |
|
70
|
|
|
mandos_home = data.get_as("mandos.cache_path", Path, DEFAULT_MANDOS_CACHE) |
|
71
|
|
|
chembl_cache_path = data.get_as("chembl.cache_path", Path, mandos_home / "chembl") |
|
72
|
|
|
default_target_types = [s.name for s in TargetType.all_types()] |
|
73
|
|
|
return Settings( |
|
74
|
|
|
is_testing=data.get_as("is_testing", bool, False), |
|
75
|
|
|
cache_path=mandos_home, |
|
76
|
|
|
chembl_cache_path=chembl_cache_path, |
|
77
|
|
|
random_seed=data.get_as("mandos.random_seed", int, 0), |
|
78
|
|
|
traversal_strategy=data.get_as("mandos.chembl.target.traversal_strategy", str, None), |
|
79
|
|
|
allowed_target_types=frozenset( |
|
80
|
|
|
data.get_list_as("mandos.chembl.target.allowed_types", str, default_target_types) |
|
81
|
|
|
), |
|
82
|
|
|
require_taxon=data.get_as("mandos.chembl.target.require_taxon", bool, True), |
|
83
|
|
|
taxon=data.get_as("mandos.chembl.target.taxon", int, 7742), |
|
84
|
|
|
require_confidence_score=data.get_as( |
|
85
|
|
|
"mandos.chembl.target.require_confidence_score", bool, True |
|
86
|
|
|
), |
|
87
|
|
|
allowed_assay_types=frozenset( |
|
88
|
|
|
data.get_list_as("mandos.chembl.activity.allowed_assay_types", str, ["B"]) |
|
89
|
|
|
), |
|
90
|
|
|
min_confidence_score=data.get_as( |
|
91
|
|
|
"mandos.chembl.activity.min_target_confidence_score", int, 4 |
|
92
|
|
|
), |
|
93
|
|
|
allowed_relations=frozenset( |
|
94
|
|
|
data.get_list_as("mandos.chembl.activity.allowed_relations", str, ["<", "<=", "="]) |
|
95
|
|
|
), |
|
96
|
|
|
require_pchembl=data.get_as("mandos.chembl.activity.require_pchembl", bool, True), |
|
97
|
|
|
min_pchembl=data.get_as("mandos.chembl.activity.min_pchembl", float, 6.0), |
|
98
|
|
|
banned_flags=frozenset( |
|
99
|
|
|
data.get_list_as("mandos.chembl.target.disallowed_flags", str, DEFAULT_BAD_FLAGS) |
|
100
|
|
|
), |
|
101
|
|
|
min_phase=data.get_as("mandos.chembl.trial.min_phase", int, 3), |
|
102
|
|
|
min_query_delay=data.get_as("mandos.pubchem.query_delay_sec_min", float, 0.25), |
|
103
|
|
|
max_query_delay=data.get_as("mandos.pubchem.query_delay_sec_min", float, 0.25), |
|
104
|
|
|
use_pubchem_parent=data.get_as("mandos.pubchem.use_parent_molecule", bool, True), |
|
105
|
|
|
tanimoto_vals=data.get_list_as( |
|
106
|
|
|
"mandos.pubchem.similarity_tanimoto_values", float, [0.9] |
|
107
|
|
|
), |
|
108
|
|
|
unicode_ranges=data.get_as("mandos.nlp.unicode_range_file", Path, None), |
|
109
|
|
|
stop_words=data.get_as("mandos.nlp.stop_word_file", Path, None), |
|
110
|
|
|
convert_greek=data.get_as("mandos.nlp.convert_greek", bool, True), |
|
111
|
|
|
n_bootstrap_samples=data.get_as("mandos.correlation.n_bootstrap_samples", int, 10000), |
|
112
|
|
|
n_retries=data.get_as("chembl.n_retries", int, 1), |
|
113
|
|
|
fast_save=data.get_as("chembl.fast_save", bool, True), |
|
114
|
|
|
timeout_sec=data.get_as("chembl.timeout_sec", int, 1), |
|
115
|
|
|
) |
|
116
|
|
|
|
|
117
|
|
|
@property |
|
118
|
|
|
def taxonomy_cache_path(self) -> Path: |
|
|
|
|
|
|
119
|
|
|
return self.cache_path / "taxonomy" |
|
120
|
|
|
|
|
121
|
|
|
def set(self): |
|
122
|
|
|
""" |
|
123
|
|
|
|
|
124
|
|
|
Returns: |
|
125
|
|
|
|
|
126
|
|
|
""" |
|
127
|
|
|
instance.CACHING = True |
|
128
|
|
|
if not _IS_IN_CI: # not sure if this is needed |
|
129
|
|
|
instance.CACHE_NAME = str(self.chembl_cache_path) |
|
130
|
|
|
logger.info(f"Setting ChEMBL cache to {self.chembl_cache_path}") |
|
|
|
|
|
|
131
|
|
|
instance.TOTAL_RETRIES = self.n_retries |
|
132
|
|
|
instance.FAST_SAVE = self.fast_save |
|
133
|
|
|
instance.TIMEOUT = self.timeout_sec |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
__all__ = ["Settings", "DEFAULT_MANDOS_CACHE", "DEFAULT_CHEMBL_CACHE", "DEFAULT_TAXONOMY_CACHE"] |
|
137
|
|
|
|