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