Total Complexity | 59 |
Total Lines | 1054 |
Duplicated Lines | 8.92 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like mandos.entries.entries often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | """ |
||
|
|||
2 | Run searches and write files. |
||
3 | """ |
||
4 | |||
5 | from __future__ import annotations |
||
6 | |||
7 | import abc |
||
8 | from pathlib import Path |
||
9 | from typing import TypeVar, Generic, Union, Mapping, Set, Sequence, Type, Optional |
||
10 | |||
11 | import typer |
||
12 | |||
13 | from mandos.entries import EntryMeta |
||
14 | from mandos.entries.args import EntryArgs |
||
15 | from mandos.model import ReflectionUtils, InjectionError |
||
16 | from mandos.model.chembl_api import ChemblApi |
||
17 | from mandos.model.chembl_support import DataValidityComment |
||
18 | from mandos.model.chembl_support.chembl_targets import TargetType |
||
19 | from mandos.model.pubchem_support.pubchem_models import ( |
||
20 | ClinicalTrialsGovUtils, |
||
21 | CoOccurrenceType, |
||
22 | DrugbankTargetType, |
||
23 | ) |
||
24 | from mandos.model.searches import Search |
||
25 | from mandos.model.settings import MANDOS_SETTINGS |
||
26 | from mandos.model.taxonomy import Taxonomy |
||
27 | from mandos.model.taxonomy_caches import TaxonomyFactories |
||
28 | from mandos.entries.api_singletons import Apis |
||
29 | from mandos.search.pubchem.acute_effects_search import AcuteEffectSearch, Ld50Search |
||
30 | from mandos.search.pubchem.bioactivity_search import BioactivitySearch |
||
31 | from mandos.search.pubchem.computed_property_search import ( |
||
32 | ComputedPropertySearch, |
||
33 | ) |
||
34 | from mandos.search.pubchem.dgidb_search import DgiSearch |
||
35 | from mandos.search.pubchem.ctd_gene_search import CtdGeneSearch |
||
36 | from mandos.entries.searcher import Searcher |
||
37 | from mandos.search.pubchem.drugbank_ddi_search import DrugbankDdiSearch |
||
38 | from mandos.search.pubchem.drugbank_interaction_search import ( |
||
39 | DrugbankTargetSearch, |
||
40 | DrugbankGeneralFunctionSearch, |
||
41 | ) |
||
42 | |||
43 | from mandos import logger, MandosMetadata, MandosLogging |
||
44 | from mandos.search.chembl.binding_search import BindingSearch |
||
45 | from mandos.search.chembl.atc_search import AtcSearch |
||
46 | from mandos.search.chembl.go_search import GoType, GoSearch |
||
47 | from mandos.search.chembl.indication_search import IndicationSearch |
||
48 | from mandos.search.chembl.mechanism_search import MechanismSearch |
||
49 | from mandos.search.pubchem.cooccurrence_search import ( |
||
50 | GeneCoOccurrenceSearch, |
||
51 | ChemicalCoOccurrenceSearch, |
||
52 | CoOccurrenceSearch, |
||
53 | DiseaseCoOccurrenceSearch, |
||
54 | ) |
||
55 | from mandos.search.pubchem.disease_search import DiseaseSearch |
||
56 | |||
57 | S = TypeVar("S", bound=Search, covariant=True) |
||
58 | U = TypeVar("U", covariant=True, bound=CoOccurrenceSearch) |
||
59 | |||
60 | |||
61 | class Utils: |
||
62 | """""" |
||
63 | |||
64 | @staticmethod |
||
65 | def split(st: str) -> Set[str]: |
||
66 | return {s.strip() for s in st.split(",")} |
||
67 | |||
68 | @staticmethod |
||
69 | def get_taxa(taxa: str) -> Sequence[Taxonomy]: |
||
70 | return [ |
||
71 | TaxonomyFactories.from_uniprot(MANDOS_SETTINGS.taxonomy_cache_path).load(int(taxon)) |
||
72 | for taxon in taxa.split(",") |
||
73 | ] |
||
74 | |||
75 | @staticmethod |
||
76 | def get_trial_statuses(st: str) -> Set[str]: |
||
77 | return ClinicalTrialsGovUtils.resolve_statuses(st) |
||
78 | |||
79 | @staticmethod |
||
80 | def get_target_types(st: str) -> Set[str]: |
||
81 | return {s.name for s in TargetType.resolve(st)} |
||
82 | |||
83 | @staticmethod |
||
84 | def get_flags(st: str) -> Set[str]: |
||
85 | return {s.name for s in DataValidityComment.resolve(st)} |
||
86 | |||
87 | |||
88 | class Entry(Generic[S], metaclass=abc.ABCMeta): |
||
89 | @classmethod |
||
90 | def cmd(cls) -> str: |
||
91 | key = cls._get_default_key() |
||
92 | if isinstance(key, typer.models.OptionInfo): |
||
93 | key = key.default |
||
94 | if key is None or not isinstance(key, str): |
||
95 | raise AssertionError(f"Key for {cls.__name__} is {key}") |
||
96 | return key |
||
97 | |||
98 | @classmethod |
||
99 | def run(cls, path: Path, **params) -> None: |
||
100 | raise NotImplementedError() |
||
101 | |||
102 | @classmethod |
||
103 | def get_search_type(cls) -> Type[S]: |
||
104 | # noinspection PyTypeChecker |
||
105 | return ReflectionUtils.get_generic_arg(cls, Search) |
||
106 | |||
107 | # noinspection PyUnusedLocal |
||
108 | @classmethod |
||
109 | def test(cls, path: Path, **params) -> None: |
||
110 | params = dict(params) |
||
111 | params["test"] = True |
||
112 | cls.run(**params) |
||
113 | |||
114 | @classmethod |
||
115 | def _run( |
||
116 | cls, |
||
117 | built: S, |
||
118 | path: Path, |
||
119 | to: Optional[Path], |
||
120 | check: bool, |
||
121 | log: Optional[Path], |
||
122 | quiet: bool, |
||
123 | verbose: bool, |
||
124 | no_setup: bool, |
||
125 | ): |
||
126 | if not no_setup: |
||
127 | level = EntryMeta.set_logging(verbose, quiet, log) |
||
128 | logger.notice(f"Ready. Set log level to {level}") |
||
129 | searcher = cls._get_searcher(built, path, to) |
||
130 | logger.notice(f"Searching {built.key} [{built.search_class}] on {path}") |
||
131 | out = searcher.output_paths[built.key] |
||
132 | if not check: |
||
133 | searcher.search() |
||
134 | logger.notice(f"Done! Wrote to {out}") |
||
135 | return searcher |
||
136 | |||
137 | @classmethod |
||
138 | def _get_searcher( |
||
139 | cls, |
||
140 | built: S, |
||
141 | path: Path, |
||
142 | to: Optional[Path], |
||
143 | ): |
||
144 | return Searcher([built], [to], path) |
||
145 | |||
146 | @classmethod |
||
147 | def default_param_values(cls) -> Mapping[str, Union[str, float, int]]: |
||
148 | return { |
||
149 | param: value |
||
150 | for param, value in ReflectionUtils.default_arg_values(cls.run).items() |
||
151 | if param not in {"key", "path"} |
||
152 | } |
||
153 | |||
154 | @classmethod |
||
155 | def _get_default_key(cls) -> str: |
||
156 | vals = ReflectionUtils.default_arg_values(cls.run) |
||
157 | try: |
||
158 | return vals["key"] |
||
159 | except KeyError: |
||
160 | logger.error(f"key not in {vals.keys()} for {cls.__name__}") |
||
161 | raise |
||
162 | |||
163 | |||
164 | class EntryChemblBinding(Entry[BindingSearch]): |
||
165 | @classmethod |
||
166 | def run( |
||
167 | cls, |
||
168 | path: Path = EntryArgs.path, |
||
169 | key: str = EntryArgs.key("chembl:binding"), |
||
170 | to: Optional[Path] = EntryArgs.to, |
||
171 | taxa: Optional[str] = EntryArgs.taxa, |
||
172 | traversal=EntryArgs.traversal_strategy, |
||
173 | target_types=EntryArgs.target_types, |
||
174 | confidence=EntryArgs.min_confidence, |
||
175 | relations=EntryArgs.relations, |
||
176 | min_pchembl=EntryArgs.min_pchembl, |
||
177 | banned_flags=EntryArgs.banned_flags, |
||
178 | check: bool = EntryArgs.test, |
||
179 | log: Optional[Path] = EntryArgs.log_path, |
||
180 | quiet: bool = EntryArgs.quiet, |
||
181 | verbose: bool = EntryArgs.verbose, |
||
182 | no_setup: bool = EntryArgs.no_setup, |
||
183 | ) -> Searcher: |
||
184 | """ |
||
185 | Binding data from ChEMBL. |
||
186 | These are 'activity' annotations of the type 'B' that have a pCHEMBL value. |
||
187 | There is extended documentation on this search; see: |
||
188 | |||
189 | https://mandos-chem.readthedocs.io/en/latest/binding.html |
||
190 | |||
191 | OBJECT: ChEMBL preferred target name |
||
192 | |||
193 | PREDICATE: "binds to" |
||
194 | |||
195 | OTHER COLUMNS: |
||
196 | |||
197 | - taxon_id: From UniProt |
||
198 | |||
199 | - taxon_name: From Uniprot (scientific name) |
||
200 | |||
201 | - pchembl: Negative base-10 log of activity value (see docs on ChEMBL) |
||
202 | |||
203 | - standard_relation: One of '<', '<=', '=', '>=', '>', '~'. Consider using <, <=, and = to indicate hits. |
||
204 | |||
205 | - std_type: e.g. EC50, Kd |
||
206 | """ |
||
207 | built = BindingSearch( |
||
208 | key=key, |
||
209 | api=Apis.Chembl, |
||
210 | taxa=Utils.get_taxa(taxa), |
||
211 | traversal_strategy=traversal, |
||
212 | allowed_target_types=Utils.get_target_types(target_types), |
||
213 | min_confidence_score=confidence, |
||
214 | allowed_relations=Utils.split(relations), |
||
215 | min_pchembl=min_pchembl, |
||
216 | banned_flags=Utils.get_flags(banned_flags), |
||
217 | ) |
||
218 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
219 | |||
220 | |||
221 | class EntryChemblMechanism(Entry[MechanismSearch]): |
||
222 | @classmethod |
||
223 | def run( |
||
224 | cls, |
||
225 | path: Path = EntryArgs.path, |
||
226 | key: str = EntryArgs.key("chembl:mechanism"), |
||
227 | to: Optional[Path] = EntryArgs.to, |
||
228 | taxa: Optional[str] = EntryArgs.taxa, |
||
229 | traversal: str = EntryArgs.traversal_strategy, |
||
230 | target_types: str = EntryArgs.target_types, |
||
231 | min_confidence: Optional[int] = EntryArgs.min_confidence, |
||
232 | check: bool = EntryArgs.test, |
||
233 | log: Optional[Path] = EntryArgs.log_path, |
||
234 | quiet: bool = EntryArgs.quiet, |
||
235 | verbose: bool = EntryArgs.verbose, |
||
236 | no_setup: bool = EntryArgs.no_setup, |
||
237 | ) -> Searcher: |
||
238 | """ |
||
239 | Mechanism of action (MoA) data from ChEMBL. |
||
240 | |||
241 | OBJECT: ChEMBL preferred target name |
||
242 | |||
243 | PREDICATE: Target action; e.g. "agonist of" or "positive allosteric modulator of" |
||
244 | |||
245 | OTHER COLUMNS: |
||
246 | |||
247 | - direct_interaction: true or false |
||
248 | |||
249 | - description: From ChEMBL |
||
250 | |||
251 | - exact_target_id: the specifically annotated target, before traversal |
||
252 | """ |
||
253 | built = MechanismSearch( |
||
254 | key=key, |
||
255 | api=Apis.Chembl, |
||
256 | taxa=Utils.get_taxa(taxa), |
||
257 | traversal_strategy=traversal, |
||
258 | allowed_target_types=Utils.get_target_types(target_types), |
||
259 | min_confidence_score=min_confidence, |
||
260 | ) |
||
261 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
262 | |||
263 | |||
264 | class EntryChemblTrials(Entry[IndicationSearch]): |
||
265 | @classmethod |
||
266 | def run( |
||
267 | cls, |
||
268 | path: Path = EntryArgs.path, |
||
269 | key: str = EntryArgs.key("chembl:trial"), |
||
270 | to: Optional[Path] = EntryArgs.to, |
||
271 | min_phase: Optional[int] = EntryArgs.chembl_trial, |
||
272 | check: bool = EntryArgs.test, |
||
273 | log: Optional[Path] = EntryArgs.log_path, |
||
274 | quiet: bool = EntryArgs.quiet, |
||
275 | verbose: bool = EntryArgs.verbose, |
||
276 | no_setup: bool = EntryArgs.no_setup, |
||
277 | ) -> Searcher: |
||
278 | """ |
||
279 | Diseases from clinical trials listed in ChEMBL. |
||
280 | |||
281 | OBJECT: MeSH code |
||
282 | |||
283 | PREDICATE: "phase <level> trial" |
||
284 | """ |
||
285 | built = IndicationSearch(key=key, api=Apis.Chembl, min_phase=min_phase) |
||
286 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
287 | |||
288 | |||
289 | class EntryChemblAtc(Entry[AtcSearch]): |
||
290 | @classmethod |
||
291 | def run( |
||
292 | cls, |
||
293 | path: Path = EntryArgs.path, |
||
294 | key: str = EntryArgs.key("chembl:atc"), |
||
295 | to: Optional[Path] = EntryArgs.to, |
||
296 | levels: str = EntryArgs.atc_level, |
||
297 | check: bool = EntryArgs.test, |
||
298 | log: Optional[Path] = EntryArgs.log_path, |
||
299 | quiet: bool = EntryArgs.quiet, |
||
300 | verbose: bool = EntryArgs.verbose, |
||
301 | no_setup: bool = EntryArgs.no_setup, |
||
302 | ) -> Searcher: |
||
303 | """ |
||
304 | ATC codes from ChEMBL. |
||
305 | |||
306 | OBJECT: ATC Code |
||
307 | |||
308 | PREDICATE: "ATC L<leveL> code" |
||
309 | """ |
||
310 | built = AtcSearch( |
||
311 | key=key, api=Apis.Chembl, levels={int(x.strip()) for x in levels.split(",")} |
||
312 | ) |
||
313 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
314 | |||
315 | |||
316 | class _EntryChemblGo(Entry[GoSearch], metaclass=abc.ABCMeta): |
||
317 | @classmethod |
||
318 | def go_type(cls) -> GoType: |
||
319 | raise NotImplementedError() |
||
320 | |||
321 | @classmethod |
||
322 | def cmd(cls) -> str: |
||
323 | me = str(cls.go_type().name) |
||
324 | return f"chembl:go.{me.lower()}" |
||
325 | |||
326 | @classmethod |
||
327 | def run( |
||
328 | cls, |
||
329 | path: Path = EntryArgs.path, |
||
330 | key: str = EntryArgs.key("<see above>"), |
||
331 | to: Optional[Path] = EntryArgs.to, |
||
332 | taxa: Optional[str] = EntryArgs.taxa, |
||
333 | traversal_strategy: str = EntryArgs.traversal_strategy, |
||
334 | target_types: str = EntryArgs.target_types, |
||
335 | confidence: Optional[int] = EntryArgs.min_confidence, |
||
336 | relations: str = EntryArgs.relations, |
||
337 | min_pchembl: float = EntryArgs.min_pchembl, |
||
338 | banned_flags: Optional[str] = EntryArgs.banned_flags, |
||
339 | binding_search: Optional[str] = EntryArgs.binding_search_name, |
||
340 | check: bool = EntryArgs.test, |
||
341 | log: Optional[Path] = EntryArgs.log_path, |
||
342 | quiet: bool = EntryArgs.quiet, |
||
343 | verbose: bool = EntryArgs.verbose, |
||
344 | no_setup: bool = EntryArgs.no_setup, |
||
345 | ) -> Searcher: |
||
346 | """ |
||
347 | GO terms associated with ChEMBL binding targets. |
||
348 | |||
349 | OBJECT: GO Term name |
||
350 | |||
351 | PREDICATE: "associated with ""Function"|"Process"|"Component"" term" |
||
352 | |||
353 | OTHER COLUMNS: |
||
354 | See the docs for ``mandos chembl:binding`` |
||
355 | |||
356 | Note: |
||
357 | |||
358 | By default, the key is the "chembl:go.function", "chembl:go.process", or "chembl:go.component". |
||
359 | |||
360 | """ |
||
361 | if key is None or key == "<see above>": |
||
362 | key = cls.cmd() |
||
363 | api = ChemblApi.wrap(Apis.Chembl) |
||
364 | if binding_search is None: |
||
365 | binding_clazz = BindingSearch |
||
366 | else: |
||
367 | binding_clazz = ReflectionUtils.injection(binding_search, BindingSearch) |
||
368 | logger.info(f"NOTICE: Passing parameters to {binding_clazz.__qualname__}") |
||
369 | try: |
||
370 | binding_search = binding_clazz( |
||
371 | key=key, |
||
372 | api=Apis.Chembl, |
||
373 | taxa=Utils.get_taxa(taxa), |
||
374 | traversal_strategy=traversal_strategy, |
||
375 | allowed_target_types=Utils.get_target_types(target_types), |
||
376 | min_confidence_score=confidence, |
||
377 | allowed_relations=Utils.split(relations), |
||
378 | min_pchembl=min_pchembl, |
||
379 | banned_flags=Utils.get_flags(banned_flags), |
||
380 | ) |
||
381 | except (TypeError, ValueError): |
||
382 | raise InjectionError(f"Failed to build {binding_clazz.__qualname__}") |
||
383 | built = GoSearch(key, api, cls.go_type(), binding_search) |
||
384 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
385 | |||
386 | |||
387 | class EntryGoFunction(_EntryChemblGo): |
||
388 | @classmethod |
||
389 | def go_type(cls) -> GoType: |
||
390 | return GoType.function |
||
391 | |||
392 | |||
393 | class EntryGoProcess(_EntryChemblGo): |
||
394 | @classmethod |
||
395 | def go_type(cls) -> GoType: |
||
396 | return GoType.process |
||
397 | |||
398 | |||
399 | class EntryGoComponent(_EntryChemblGo): |
||
400 | @classmethod |
||
401 | def go_type(cls) -> GoType: |
||
402 | return GoType.component |
||
403 | |||
404 | |||
405 | class EntryPubchemDisease(Entry[DiseaseSearch]): |
||
406 | @classmethod |
||
407 | def run( |
||
408 | cls, |
||
409 | path: Path = EntryArgs.path, |
||
410 | key: str = EntryArgs.key("disease.ctd:mesh"), |
||
411 | to: Optional[Path] = EntryArgs.to, |
||
412 | check: bool = EntryArgs.test, |
||
413 | log: Optional[Path] = EntryArgs.log_path, |
||
414 | quiet: bool = EntryArgs.quiet, |
||
415 | verbose: bool = EntryArgs.verbose, |
||
416 | no_setup: bool = EntryArgs.no_setup, |
||
417 | ) -> Searcher: |
||
418 | """ |
||
419 | Diseases in the CTD. |
||
420 | |||
421 | Comparative Toxicogenomics Database. |
||
422 | |||
423 | OBJECT: MeSH code of disease |
||
424 | |||
425 | PREDICATE: "marker/mechanism evidence for" or "disease evidence for" |
||
426 | """ |
||
427 | built = DiseaseSearch(key, Apis.Pubchem) |
||
428 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
429 | |||
430 | |||
431 | class _EntryPubchemCoOccurrence(Entry[U], metaclass=abc.ABCMeta): |
||
432 | @classmethod |
||
433 | def cmd(cls) -> str: |
||
434 | me = str(cls.get_cooccurrence_type().name) |
||
435 | return f"lit.pubchem:{me.lower()}" |
||
436 | |||
437 | @classmethod |
||
438 | def get_cooccurrence_type(cls) -> CoOccurrenceType: |
||
439 | s: CoOccurrenceSearch = cls.get_search_type() |
||
440 | return s.cooccurrence_type() |
||
441 | |||
442 | @classmethod |
||
443 | def run( |
||
444 | cls, |
||
445 | path: Path = EntryArgs.path, |
||
446 | key: str = EntryArgs.key("<see above>"), |
||
447 | to: Optional[Path] = EntryArgs.to, |
||
448 | min_score: float = EntryArgs.min_cooccurrence_score, |
||
449 | min_articles: int = EntryArgs.min_cooccurring_articles, |
||
450 | log: Optional[Path] = EntryArgs.log_path, |
||
451 | check: bool = EntryArgs.test, |
||
452 | quiet: bool = EntryArgs.quiet, |
||
453 | verbose: bool = EntryArgs.verbose, |
||
454 | no_setup: bool = EntryArgs.no_setup, |
||
455 | ) -> Searcher: |
||
456 | """ |
||
457 | Co-occurrences from PubMed articles. |
||
458 | There is extended documentation on this search. |
||
459 | Also refer to https://pubchemdocs.ncbi.nlm.nih.gov/knowledge-panels |
||
460 | |||
461 | OBJECT: Name of gene/chemical/disease |
||
462 | |||
463 | PREDICATE: "co-occurs with <gene/chemical/disease>" |
||
464 | |||
465 | OTHER COLUMNS: |
||
466 | |||
467 | - score: enrichment score; see PubChem docs |
||
468 | |||
469 | - intersect_count: Number of articles co-occurring |
||
470 | |||
471 | - query_count: Total number of articles for query compound |
||
472 | |||
473 | - neighbor_count: Total number of articles for target (co-occurring) compound |
||
474 | """ |
||
475 | if key is None or key == "<see above>": |
||
476 | key = cls.cmd() |
||
477 | clazz = cls.get_search_type() |
||
478 | built = clazz(key, Apis.Pubchem, min_score=min_score, min_articles=min_articles) |
||
479 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
480 | |||
481 | |||
482 | class EntryPubchemGeneCoOccurrence(_EntryPubchemCoOccurrence[GeneCoOccurrenceSearch]): |
||
483 | """""" |
||
484 | |||
485 | |||
486 | class EntryPubchemDiseaseCoOccurrence(_EntryPubchemCoOccurrence[DiseaseCoOccurrenceSearch]): |
||
487 | """""" |
||
488 | |||
489 | |||
490 | class EntryPubchemChemicalCoOccurrence(_EntryPubchemCoOccurrence[ChemicalCoOccurrenceSearch]): |
||
491 | """""" |
||
492 | |||
493 | |||
494 | class EntryPubchemDgi(Entry[DgiSearch]): |
||
495 | @classmethod |
||
496 | def run( |
||
497 | cls, |
||
498 | path: Path = EntryArgs.path, |
||
499 | key: str = EntryArgs.key("inter.dgidb:gene"), |
||
500 | to: Optional[Path] = EntryArgs.to, |
||
501 | log: Optional[Path] = EntryArgs.log_path, |
||
502 | check: bool = EntryArgs.test, |
||
503 | quiet: bool = EntryArgs.quiet, |
||
504 | verbose: bool = EntryArgs.verbose, |
||
505 | no_setup: bool = EntryArgs.no_setup, |
||
506 | ) -> Searcher: |
||
507 | """ |
||
508 | Drug/gene interactions in the DGIDB. |
||
509 | |||
510 | Drug Gene Interaction Database. |
||
511 | Also see ``disease.dgidb:int``. |
||
512 | |||
513 | OBJECT: Name of the gene |
||
514 | |||
515 | PREDICATE: "interacts with gene" |
||
516 | """ |
||
517 | built = DgiSearch(key, Apis.Pubchem) |
||
518 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
519 | |||
520 | |||
521 | class EntryPubchemCgi(Entry[CtdGeneSearch]): |
||
522 | @classmethod |
||
523 | def run( |
||
524 | cls, |
||
525 | path: Path = EntryArgs.path, |
||
526 | key: str = EntryArgs.key("inter.ctd:gene"), |
||
527 | to: Optional[Path] = EntryArgs.to, |
||
528 | log: Optional[Path] = EntryArgs.log_path, |
||
529 | check: bool = EntryArgs.test, |
||
530 | quiet: bool = EntryArgs.quiet, |
||
531 | verbose: bool = EntryArgs.verbose, |
||
532 | no_setup: bool = EntryArgs.no_setup, |
||
533 | ) -> Searcher: |
||
534 | """ |
||
535 | Compound/gene interactions in the DGIDB. |
||
536 | |||
537 | Drug Gene Interaction Database. |
||
538 | Also see ``interact.dgidb:int``. |
||
539 | |||
540 | OBJECT: Name of the gene |
||
541 | |||
542 | PREDICATE: "compound/gene interaction" |
||
543 | |||
544 | """ |
||
545 | built = CtdGeneSearch(key, Apis.Pubchem) |
||
546 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
547 | |||
548 | |||
549 | class EntryDrugbankTarget(Entry[DrugbankTargetSearch]): |
||
550 | View Code Duplication | @classmethod |
|
551 | def run( |
||
552 | cls, |
||
553 | path: Path = EntryArgs.path, |
||
554 | key: str = EntryArgs.key("inter.drugbank:target"), |
||
555 | to: Optional[Path] = EntryArgs.to, |
||
556 | check: bool = EntryArgs.test, |
||
557 | log: Optional[Path] = EntryArgs.log_path, |
||
558 | quiet: bool = EntryArgs.quiet, |
||
559 | verbose: bool = EntryArgs.verbose, |
||
560 | no_setup: bool = EntryArgs.no_setup, |
||
561 | ) -> Searcher: |
||
562 | """ |
||
563 | Protein targets from DrugBank. |
||
564 | |||
565 | OBJECT: Target name (e.g. "Solute carrier family 22 member 11") from DrugBank |
||
566 | |||
567 | PREDICATE: Action (e.g. "binder", "downregulator", or "agonist") |
||
568 | """ |
||
569 | built = DrugbankTargetSearch(key, Apis.Pubchem, {DrugbankTargetType.target}) |
||
570 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
571 | |||
572 | |||
573 | class EntryGeneralFunction(Entry[DrugbankGeneralFunctionSearch]): |
||
574 | View Code Duplication | @classmethod |
|
575 | def run( |
||
576 | cls, |
||
577 | path: Path = EntryArgs.path, |
||
578 | key: str = EntryArgs.key("inter.drugbank:target-fn"), |
||
579 | to: Optional[Path] = EntryArgs.to, |
||
580 | check: bool = EntryArgs.test, |
||
581 | log: Optional[Path] = EntryArgs.log_path, |
||
582 | quiet: bool = EntryArgs.quiet, |
||
583 | verbose: bool = EntryArgs.verbose, |
||
584 | no_setup: bool = EntryArgs.no_setup, |
||
585 | ) -> Searcher: |
||
586 | """ |
||
587 | General functions from DrugBank targets. |
||
588 | |||
589 | OBJECT: Name of the general function (e.g. "Toxic substance binding") |
||
590 | |||
591 | PREDICATE: against on target (e.g. "binder", "downregulator", or "agonist"). |
||
592 | """ |
||
593 | built = DrugbankGeneralFunctionSearch(key, Apis.Pubchem, {DrugbankTargetType.target}) |
||
594 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
595 | |||
596 | |||
597 | class EntryDrugbankTransporter(Entry[DrugbankTargetSearch]): |
||
598 | View Code Duplication | @classmethod |
|
599 | def run( |
||
600 | cls, |
||
601 | path: Path = EntryArgs.path, |
||
602 | key: str = EntryArgs.key("inter.drugbank:pk"), |
||
603 | to: Optional[Path] = EntryArgs.to, |
||
604 | check: bool = EntryArgs.test, |
||
605 | log: Optional[Path] = EntryArgs.log_path, |
||
606 | quiet: bool = EntryArgs.quiet, |
||
607 | verbose: bool = EntryArgs.verbose, |
||
608 | no_setup: bool = EntryArgs.no_setup, |
||
609 | ) -> Searcher: |
||
610 | """ |
||
611 | PK-related proteins from DrugBank. |
||
612 | |||
613 | OBJECT: Transporter name (e.g. "Solute carrier family 22 member 11") from DrugBank |
||
614 | |||
615 | PREDICATE: "transported by", "carried by", or "metabolized by" |
||
616 | """ |
||
617 | target_types = { |
||
618 | DrugbankTargetType.transporter, |
||
619 | DrugbankTargetType.carrier, |
||
620 | DrugbankTargetType.enzyme, |
||
621 | } |
||
622 | built = DrugbankTargetSearch(key, Apis.Pubchem, target_types) |
||
623 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
624 | |||
625 | |||
626 | class EntryTransporterGeneralFunction(Entry[DrugbankGeneralFunctionSearch]): |
||
627 | View Code Duplication | @classmethod |
|
628 | def run( |
||
629 | cls, |
||
630 | path: Path = EntryArgs.path, |
||
631 | key: str = EntryArgs.key("inter.drugbank:pk-fn"), |
||
632 | to: Optional[Path] = EntryArgs.to, |
||
633 | check: bool = EntryArgs.test, |
||
634 | log: Optional[Path] = EntryArgs.log_path, |
||
635 | quiet: bool = EntryArgs.quiet, |
||
636 | verbose: bool = EntryArgs.verbose, |
||
637 | no_setup: bool = EntryArgs.no_setup, |
||
638 | ) -> Searcher: |
||
639 | """ |
||
640 | DrugBank PK-related protein functions. |
||
641 | |||
642 | OBJECT: Name of the general function (e.g. "Toxic substance binding") |
||
643 | |||
644 | PREDICATE: "transported by", "carried by", or "metabolized by" |
||
645 | """ |
||
646 | target_types = { |
||
647 | DrugbankTargetType.transporter, |
||
648 | DrugbankTargetType.carrier, |
||
649 | DrugbankTargetType.enzyme, |
||
650 | } |
||
651 | built = DrugbankGeneralFunctionSearch(key, Apis.Pubchem, target_types) |
||
652 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
653 | |||
654 | |||
655 | class EntryDrugbankDdi(Entry[DrugbankDdiSearch]): |
||
656 | @classmethod |
||
657 | def run( |
||
658 | cls, |
||
659 | path: Path = EntryArgs.path, |
||
660 | key: str = EntryArgs.key("inter.drugbank:ddi"), |
||
661 | to: Optional[Path] = EntryArgs.to, |
||
662 | check: bool = EntryArgs.test, |
||
663 | log: Optional[Path] = EntryArgs.log_path, |
||
664 | quiet: bool = EntryArgs.quiet, |
||
665 | verbose: bool = EntryArgs.verbose, |
||
666 | no_setup: bool = EntryArgs.no_setup, |
||
667 | ) -> Searcher: |
||
668 | """ |
||
669 | Drug/drug interactions listed by DrugBank. |
||
670 | |||
671 | The 'description' column includes useful information about the interaction, |
||
672 | such as diseases and whether a risk is increased or decreased. |
||
673 | |||
674 | OBJECT: name of the drug (e.g. "ibuprofen") |
||
675 | |||
676 | PREDICATE: "ddi" |
||
677 | """ |
||
678 | built = DrugbankDdiSearch(key, Apis.Pubchem) |
||
679 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
680 | |||
681 | |||
682 | class EntryPubchemAssay(Entry[BioactivitySearch]): |
||
683 | @classmethod |
||
684 | def run( |
||
685 | cls, |
||
686 | path: Path = EntryArgs.path, |
||
687 | key: str = EntryArgs.key("assay.pubchem:activity"), |
||
688 | to: Optional[Path] = EntryArgs.to, |
||
689 | name_must_match: bool = EntryArgs.name_must_match, |
||
690 | ban_sources: Optional[str] = None, |
||
691 | check: bool = EntryArgs.test, |
||
692 | log: Optional[Path] = EntryArgs.log_path, |
||
693 | quiet: bool = EntryArgs.quiet, |
||
694 | verbose: bool = EntryArgs.verbose, |
||
695 | no_setup: bool = EntryArgs.no_setup, |
||
696 | ) -> Searcher: |
||
697 | """ |
||
698 | PubChem bioactivity results. |
||
699 | |||
700 | Note: The species name, if present, is taken from the target name. |
||
701 | The taxon ID is what was curated in PubChem. |
||
702 | |||
703 | OBJECT: Name of the target without species suffix (e.g. "Slc6a3 - solute carrier family 6 member 3") |
||
704 | |||
705 | PREDICATE: "active"|"inactive"|"inconclusive"|"undetermined" |
||
706 | |||
707 | SOURCE: "PubChem: <referrer> "(""confirmatory"|"literature"|"other"")" |
||
708 | """ |
||
709 | built = BioactivitySearch(key, Apis.Pubchem, compound_name_must_match=name_must_match) |
||
710 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
711 | |||
712 | |||
713 | class EntryDeaSchedule(Entry[BioactivitySearch]): |
||
714 | @classmethod |
||
715 | def run( |
||
716 | cls, |
||
717 | path: Path = EntryArgs.path, |
||
718 | key: str = EntryArgs.key("drug.dea:schedule"), |
||
719 | to: Optional[Path] = EntryArgs.to, |
||
720 | check: bool = EntryArgs.test, |
||
721 | log: Optional[Path] = EntryArgs.log_path, |
||
722 | quiet: bool = EntryArgs.quiet, |
||
723 | verbose: bool = EntryArgs.verbose, |
||
724 | no_setup: bool = EntryArgs.no_setup, |
||
725 | ) -> Searcher: |
||
726 | """ |
||
727 | DEA schedules (PENDING). |
||
728 | |||
729 | OBJECT: (1 to 4, or "unscheduled") |
||
730 | |||
731 | PREDICATE: "has DEA schedule" |
||
732 | """ |
||
733 | pass |
||
734 | |||
735 | |||
736 | class EntryDeaClass(Entry[BioactivitySearch]): |
||
737 | @classmethod |
||
738 | def run( |
||
739 | cls, |
||
740 | path: Path = EntryArgs.path, |
||
741 | key: str = EntryArgs.key("drug.dea:class"), |
||
742 | to: Optional[Path] = EntryArgs.to, |
||
743 | check: bool = EntryArgs.test, |
||
744 | log: Optional[Path] = EntryArgs.log_path, |
||
745 | quiet: bool = EntryArgs.quiet, |
||
746 | verbose: bool = EntryArgs.verbose, |
||
747 | no_setup: bool = EntryArgs.no_setup, |
||
748 | ) -> Searcher: |
||
749 | """ |
||
750 | DEA classes (PENDING). |
||
751 | |||
752 | OBJECT: e.g. "hallucinogen" |
||
753 | |||
754 | PREDICATE: "is in DEA class" |
||
755 | """ |
||
756 | pass |
||
757 | |||
758 | |||
759 | class EntryChemidPlusAcute(Entry[AcuteEffectSearch]): |
||
760 | @classmethod |
||
761 | def run( |
||
762 | cls, |
||
763 | path: Path = EntryArgs.path, |
||
764 | key: str = EntryArgs.key("tox.chemidplus:acute"), |
||
765 | to: Optional[Path] = EntryArgs.to, |
||
766 | level: int = EntryArgs.acute_effect_level, |
||
767 | check: bool = EntryArgs.test, |
||
768 | log: Optional[Path] = EntryArgs.log_path, |
||
769 | quiet: bool = EntryArgs.quiet, |
||
770 | verbose: bool = EntryArgs.verbose, |
||
771 | no_setup: bool = EntryArgs.no_setup, |
||
772 | ) -> Searcher: |
||
773 | """ |
||
774 | Acute effect codes from ChemIDPlus. |
||
775 | |||
776 | OBJECT: E.g. "behavioral: excitement" |
||
777 | |||
778 | PREDICATE: "causes acute effect" |
||
779 | |||
780 | OTHER COLUMNS: |
||
781 | |||
782 | - organism: e.g. 'women', 'infant', 'men', 'human', 'dog', 'domestic animals - sheep and goats' |
||
783 | - human: true or false |
||
784 | - test_type: e.g. 'TDLo' |
||
785 | - route: e.g. 'skin' |
||
786 | - mg_per_kg: e.g. 17.5 |
||
787 | """ |
||
788 | built = AcuteEffectSearch( |
||
789 | key, |
||
790 | Apis.Pubchem, |
||
791 | top_level=level == 1, |
||
792 | ) |
||
793 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
794 | |||
795 | |||
796 | class EntryChemidPlusLd50(Entry[Ld50Search]): |
||
797 | @classmethod |
||
798 | def run( |
||
799 | cls, |
||
800 | path: Path = EntryArgs.path, |
||
801 | key: str = EntryArgs.key("tox.chemidplus:ld50"), |
||
802 | to: Optional[Path] = EntryArgs.to, |
||
803 | check: bool = EntryArgs.test, |
||
804 | log: Optional[Path] = EntryArgs.log_path, |
||
805 | quiet: bool = EntryArgs.quiet, |
||
806 | verbose: bool = EntryArgs.verbose, |
||
807 | no_setup: bool = EntryArgs.no_setup, |
||
808 | ) -> Searcher: |
||
809 | """ |
||
810 | LD50 acute effects from ChemIDPlus. |
||
811 | |||
812 | OBJECT: A dose in mg/kg (e.g. 3100) |
||
813 | |||
814 | PREDICATE: "LD50 :: <route>" (e.g. "LD50 :: intravenous) |
||
815 | |||
816 | OTHER COLUMNS: |
||
817 | |||
818 | - organism: e.g. 'women', 'infant', 'men', 'human', 'dog', 'domestic animals - sheep and goats' |
||
819 | - human: true or false |
||
820 | """ |
||
821 | built = Ld50Search(key, Apis.Pubchem) |
||
822 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
823 | |||
824 | |||
825 | class EntryHmdbTissue(Entry[BioactivitySearch]): |
||
826 | @classmethod |
||
827 | def run( |
||
828 | cls, |
||
829 | path: Path = EntryArgs.path, |
||
830 | key: str = EntryArgs.key("hmdb:tissue"), |
||
831 | to: Optional[Path] = EntryArgs.to, |
||
832 | min_nanomolar: Optional[float] = None, |
||
833 | check: bool = EntryArgs.test, |
||
834 | log: Optional[Path] = EntryArgs.log_path, |
||
835 | quiet: bool = EntryArgs.quiet, |
||
836 | verbose: bool = EntryArgs.verbose, |
||
837 | no_setup: bool = EntryArgs.no_setup, |
||
838 | ) -> Searcher: |
||
839 | """ |
||
840 | Tissue concentrations from HMDB (PENDING). |
||
841 | |||
842 | OBJECT: |
||
843 | |||
844 | PREDICATE: "tissue" |
||
845 | """ |
||
846 | pass |
||
847 | |||
848 | |||
849 | class EntryHmdbComputed(Entry[BioactivitySearch]): |
||
850 | @classmethod |
||
851 | def run( |
||
852 | cls, |
||
853 | path: Path = EntryArgs.path, |
||
854 | key: str = EntryArgs.key("hmdb:computed"), |
||
855 | to: Optional[Path] = EntryArgs.to, |
||
856 | min_nanomolar: Optional[float] = None, |
||
857 | check: bool = EntryArgs.test, |
||
858 | log: Optional[Path] = EntryArgs.log_path, |
||
859 | quiet: bool = EntryArgs.quiet, |
||
860 | verbose: bool = EntryArgs.verbose, |
||
861 | no_setup: bool = EntryArgs.no_setup, |
||
862 | ) -> Searcher: |
||
863 | """ |
||
864 | Computed properties from HMDB (PENDING). |
||
865 | |||
866 | Keys include pKa, logP, logS, etc. |
||
867 | |||
868 | OBJECT: A number; booleans are converted to 0/1 |
||
869 | |||
870 | PREDICATE: The name of the property |
||
871 | """ |
||
872 | pass |
||
873 | |||
874 | |||
875 | class EntryPubchemReact(Entry[BioactivitySearch]): |
||
876 | @classmethod |
||
877 | def run( |
||
878 | cls, |
||
879 | path: Path = EntryArgs.path, |
||
880 | key: str = EntryArgs.key("inter.pubchem:react"), |
||
881 | to: Optional[Path] = EntryArgs.to, |
||
882 | check: bool = EntryArgs.test, |
||
883 | log: Optional[Path] = EntryArgs.log_path, |
||
884 | quiet: bool = EntryArgs.quiet, |
||
885 | verbose: bool = EntryArgs.verbose, |
||
886 | no_setup: bool = EntryArgs.no_setup, |
||
887 | ) -> Searcher: |
||
888 | """ |
||
889 | Metabolic reactions (PENDING). |
||
890 | |||
891 | OBJECT: Equation |
||
892 | |||
893 | PREDICATE: "<pathway>" |
||
894 | """ |
||
895 | pass |
||
896 | |||
897 | |||
898 | class EntryPubchemComputed(Entry[ComputedPropertySearch]): |
||
899 | @classmethod |
||
900 | def run( |
||
901 | cls, |
||
902 | path: Path = EntryArgs.path, |
||
903 | key: str = EntryArgs.key("chem.pubchem:computed"), |
||
904 | keys: str = EntryArgs.pubchem_computed_keys, |
||
905 | to: Optional[Path] = EntryArgs.to, |
||
906 | check: bool = EntryArgs.test, |
||
907 | log: Optional[Path] = EntryArgs.log_path, |
||
908 | quiet: bool = EntryArgs.quiet, |
||
909 | verbose: bool = EntryArgs.verbose, |
||
910 | no_setup: bool = EntryArgs.no_setup, |
||
911 | ) -> Searcher: |
||
912 | """ |
||
913 | Computed properties from PubChem. |
||
914 | |||
915 | OBJECT: Number |
||
916 | |||
917 | PREDICATE: e.g. "complexity" |
||
918 | """ |
||
919 | # replace acronyms, etc. |
||
920 | # ComputedPropertySearch standardizes punctuation and casing |
||
921 | known = { |
||
922 | k: v |
||
923 | for k, v in { |
||
924 | **EntryArgs.KNOWN_USEFUL_KEYS, |
||
925 | **EntryArgs.KNOWN_USELESS_KEYS, |
||
926 | } |
||
927 | if v is not None |
||
928 | } |
||
929 | keys = {known.get(s.strip(), s) for s in keys.split(",")} |
||
930 | built = ComputedPropertySearch(key, Apis.Pubchem, descriptors=keys, source="PubChem") |
||
931 | return cls._run(built, path, to, check, log, quiet, verbose, no_setup) |
||
932 | |||
933 | |||
934 | class EntryDrugbankAdmet(Entry[DrugbankTargetSearch]): |
||
935 | @classmethod |
||
936 | def run( |
||
937 | cls, |
||
938 | path: Path = EntryArgs.path, |
||
939 | key: str = EntryArgs.key("drugbank.admet:properties"), |
||
940 | to: Optional[Path] = EntryArgs.to, |
||
941 | check: bool = EntryArgs.test, |
||
942 | log: Optional[Path] = EntryArgs.log_path, |
||
943 | quiet: bool = EntryArgs.quiet, |
||
944 | verbose: bool = EntryArgs.verbose, |
||
945 | no_setup: bool = EntryArgs.no_setup, |
||
946 | ) -> Searcher: |
||
947 | """ |
||
948 | Enzyme predictions from DrugBank (PENDING). |
||
949 | |||
950 | OBJECT: Enzyme name |
||
951 | |||
952 | PREDICATE: Action |
||
953 | """ |
||
954 | |||
955 | |||
956 | class EntryDrugbankMetabolites(Entry[DrugbankTargetSearch]): |
||
957 | @classmethod |
||
958 | def run( |
||
959 | cls, |
||
960 | path: Path = EntryArgs.path, |
||
961 | key: str = EntryArgs.key("drugbank.admet:metabolites"), |
||
962 | to: Optional[Path] = EntryArgs.to, |
||
963 | check: bool = EntryArgs.test, |
||
964 | log: Optional[Path] = EntryArgs.log_path, |
||
965 | quiet: bool = EntryArgs.quiet, |
||
966 | verbose: bool = EntryArgs.verbose, |
||
967 | no_setup: bool = EntryArgs.no_setup, |
||
968 | ) -> Searcher: |
||
969 | """ |
||
970 | Metabolites from DrugBank (PENDING). |
||
971 | |||
972 | OBJECT: Compound name (e.g. "norcocaine"). |
||
973 | |||
974 | PREDICATE: "metabolized to" |
||
975 | """ |
||
976 | |||
977 | |||
978 | class EntryDrugbankDosage(Entry[DrugbankTargetSearch]): |
||
979 | @classmethod |
||
980 | def run( |
||
981 | cls, |
||
982 | path: Path = EntryArgs.path, |
||
983 | key: str = EntryArgs.key("drugbank.admet:dosage"), |
||
984 | to: Optional[Path] = EntryArgs.to, |
||
985 | check: bool = EntryArgs.test, |
||
986 | log: Optional[Path] = EntryArgs.log_path, |
||
987 | quiet: bool = EntryArgs.quiet, |
||
988 | verbose: bool = EntryArgs.verbose, |
||
989 | no_setup: bool = EntryArgs.no_setup, |
||
990 | ) -> Searcher: |
||
991 | """ |
||
992 | Dosage from DrugBank (PENDING). |
||
993 | |||
994 | OBJECT: concentration in mg/mL |
||
995 | |||
996 | PREDICATE: "dosage :: <route>" |
||
997 | |||
998 | OTHER COLUMNS: |
||
999 | |||
1000 | - form (e.g. liquid) |
||
1001 | """ |
||
1002 | |||
1003 | |||
1004 | class EntryMetaRandom(Entry[BioactivitySearch]): |
||
1005 | @classmethod |
||
1006 | def run( |
||
1007 | cls, |
||
1008 | path: Path = EntryArgs.path, |
||
1009 | key: str = EntryArgs.key("meta:random"), |
||
1010 | to: Optional[Path] = EntryArgs.to, |
||
1011 | check: bool = EntryArgs.test, |
||
1012 | log: Optional[Path] = EntryArgs.log_path, |
||
1013 | quiet: bool = EntryArgs.quiet, |
||
1014 | verbose: bool = EntryArgs.verbose, |
||
1015 | no_setup: bool = EntryArgs.no_setup, |
||
1016 | ) -> Searcher: |
||
1017 | """ |
||
1018 | Random class assignment (PENDING). |
||
1019 | |||
1020 | OBJECT: 1 thru n-compounds |
||
1021 | |||
1022 | PREDICATE: "random" |
||
1023 | """ |
||
1024 | pass |
||
1025 | |||
1026 | |||
1027 | Entries = [ |
||
1028 | EntryChemblBinding, |
||
1029 | EntryChemblMechanism, |
||
1030 | EntryChemblAtc, |
||
1031 | EntryChemblTrials, |
||
1032 | EntryGoFunction, |
||
1033 | EntryGoProcess, |
||
1034 | EntryGoComponent, |
||
1035 | EntryPubchemDisease, |
||
1036 | EntryPubchemGeneCoOccurrence, |
||
1037 | EntryPubchemDiseaseCoOccurrence, |
||
1038 | EntryPubchemChemicalCoOccurrence, |
||
1039 | EntryPubchemDgi, |
||
1040 | EntryPubchemCgi, |
||
1041 | EntryDrugbankTarget, |
||
1042 | EntryGeneralFunction, |
||
1043 | EntryDrugbankTransporter, |
||
1044 | EntryTransporterGeneralFunction, |
||
1045 | EntryDrugbankDdi, |
||
1046 | EntryPubchemAssay, |
||
1047 | EntryDeaSchedule, |
||
1048 | EntryDeaClass, |
||
1049 | EntryChemidPlusAcute, |
||
1050 | EntryChemidPlusLd50, |
||
1051 | EntryHmdbTissue, |
||
1052 | EntryPubchemReact, |
||
1053 | EntryMetaRandom, |
||
1054 | ] |
||
1055 |