| Total Complexity | 60 |
| Total Lines | 1256 |
| Duplicated Lines | 3.03 % |
| 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 | import typing |
||
| 9 | from inspect import cleandoc as doc |
||
| 10 | from pathlib import Path |
||
| 11 | from typing import TypeVar, Generic, Union, Mapping, Set, Sequence, Type, Optional |
||
| 12 | |||
| 13 | import typer |
||
| 14 | |||
| 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, ConfidenceLevel |
||
| 19 | from mandos.model.pubchem_support.pubchem_models import ( |
||
| 20 | ClinicalTrialsGovUtils, |
||
| 21 | CoOccurrenceType, |
||
| 22 | AssayType, |
||
| 23 | DrugbankTargetType, |
||
| 24 | ) |
||
| 25 | from mandos.model.searches import Search |
||
| 26 | from mandos.model.settings import MANDOS_SETTINGS |
||
| 27 | from mandos.model.taxonomy import Taxonomy |
||
| 28 | from mandos.model.taxonomy_caches import TaxonomyFactories |
||
| 29 | from mandos.entries.api_singletons import Apis |
||
| 30 | from mandos.search.chembl.target_traversal import TargetTraversalStrategies |
||
| 31 | from mandos.search.pubchem.acute_effects_search import AcuteEffectSearch, Ld50Search |
||
| 32 | from mandos.search.pubchem.bioactivity_search import BioactivitySearch |
||
| 33 | from mandos.search.pubchem.computed_property_search import ( |
||
| 34 | ComputedPropertySearch, |
||
| 35 | ComputedPropertyHit, |
||
| 36 | ) |
||
| 37 | from mandos.search.pubchem.dgidb_search import DgiSearch |
||
| 38 | from mandos.search.pubchem.ctd_gene_search import CtdGeneSearch |
||
| 39 | from mandos.entries.searcher import Searcher |
||
| 40 | from mandos.search.pubchem.drugbank_ddi_search import DrugbankDdiSearch |
||
| 41 | from mandos.search.pubchem.drugbank_interaction_search import ( |
||
| 42 | DrugbankTargetSearch, |
||
| 43 | DrugbankGeneralFunctionSearch, |
||
| 44 | ) |
||
| 45 | |||
| 46 | from mandos import logger |
||
| 47 | from mandos.search.chembl.binding_search import BindingSearch |
||
| 48 | from mandos.search.chembl.atc_search import AtcSearch |
||
| 49 | from mandos.search.chembl.go_search import GoType, GoSearch |
||
| 50 | from mandos.search.chembl.indication_search import IndicationSearch |
||
| 51 | from mandos.search.chembl.mechanism_search import MechanismSearch |
||
| 52 | from mandos.search.pubchem.cooccurrence_search import ( |
||
| 53 | GeneCoOccurrenceSearch, |
||
| 54 | ChemicalCoOccurrenceSearch, |
||
| 55 | CoOccurrenceSearch, |
||
| 56 | DiseaseCoOccurrenceSearch, |
||
| 57 | ) |
||
| 58 | from mandos.search.pubchem.disease_search import DiseaseSearch |
||
| 59 | |||
| 60 | S = TypeVar("S", bound=Search, covariant=True) |
||
| 61 | U = TypeVar("U", covariant=True, bound=CoOccurrenceSearch) |
||
| 62 | |||
| 63 | |||
| 64 | class Utils: |
||
| 65 | """""" |
||
| 66 | |||
| 67 | @staticmethod |
||
| 68 | def split(st: str) -> Set[str]: |
||
| 69 | return {s.strip() for s in st.split(",")} |
||
| 70 | |||
| 71 | @staticmethod |
||
| 72 | def get_taxa(taxa: str) -> Sequence[Taxonomy]: |
||
| 73 | return [ |
||
| 74 | TaxonomyFactories.from_uniprot(MANDOS_SETTINGS.taxonomy_cache_path).load(int(taxon)) |
||
| 75 | for taxon in taxa.split(",") |
||
| 76 | ] |
||
| 77 | |||
| 78 | @staticmethod |
||
| 79 | def get_trial_statuses(st: str) -> Set[str]: |
||
| 80 | return ClinicalTrialsGovUtils.resolve_statuses(st) |
||
| 81 | |||
| 82 | @staticmethod |
||
| 83 | def get_target_types(st: str) -> Set[str]: |
||
| 84 | return {s.name for s in TargetType.resolve(st)} |
||
| 85 | |||
| 86 | @staticmethod |
||
| 87 | def get_flags(st: str) -> Set[str]: |
||
| 88 | return {s.name for s in DataValidityComment.resolve(st)} |
||
| 89 | |||
| 90 | |||
| 91 | class _Typer: |
||
| 92 | |||
| 93 | path = typer.Argument( |
||
| 94 | ..., |
||
| 95 | exists=True, |
||
| 96 | dir_okay=False, |
||
| 97 | readable=True, |
||
| 98 | help=doc( |
||
| 99 | """ |
||
| 100 | The path to the input file. |
||
| 101 | One of: |
||
| 102 | |||
| 103 | (A) *.txt or *.lines with one InChI Key per line; |
||
| 104 | |||
| 105 | (B) A *.csv, *.tsv, *.tab file (or .gzip variant) with a column called 'inchikey'; OR |
||
| 106 | |||
| 107 | (C) An Apache Arrow *.feather file with a column called 'inchikey' |
||
| 108 | """ |
||
| 109 | ), |
||
| 110 | ) |
||
| 111 | |||
| 112 | to = typer.Option( |
||
| 113 | None, |
||
| 114 | show_default=False, |
||
| 115 | help=doc( |
||
| 116 | """ |
||
| 117 | The path to the output file. |
||
| 118 | If not set, chooses <input-path>-<search>.csv.gz |
||
| 119 | The filename extension should be one of: .csv, .tsv, .tab, .json (with optional .gz/.bz2); |
||
| 120 | .feather; .snappy (or .parquet); or .h5. |
||
| 121 | Feather (.feather), Parquet (.snappy), and tab-delimited (.tsv.gz) are recommended. |
||
| 122 | JSON and HDF5 (.h5) are not recommended. If H5, will add a new dataset named <key> to the archive. |
||
| 123 | Will fail if the file exists unless the `--overwrite` flag is set. |
||
| 124 | |||
| 125 | If only the filename extension is provided (e.g. --to '.feather'), will only change the output format |
||
| 126 | (and filename extension). |
||
| 127 | """ |
||
| 128 | ), |
||
| 129 | ) |
||
| 130 | |||
| 131 | replace: bool = typer.Option(False, help="Replace output file if they exist. See also: --skip") |
||
| 132 | |||
| 133 | skip: bool = typer.Option( |
||
| 134 | False, help="Skip any search if the output file exists (only warns). See also: --replace" |
||
| 135 | ) |
||
| 136 | |||
| 137 | in_cache: bool = typer.Option( |
||
| 138 | False, |
||
| 139 | help="Do not download any data. Fails if the needed data is not cached.", |
||
| 140 | hidden=True, |
||
| 141 | ) |
||
| 142 | |||
| 143 | verbose: int = typer.Option( |
||
| 144 | 0, |
||
| 145 | "--verbose", |
||
| 146 | "-v", |
||
| 147 | count=True, |
||
| 148 | help="Configure logger to output INFO (use `--verbose --verbose` or `-vv` for DEBUG output)", |
||
| 149 | ) |
||
| 150 | |||
| 151 | @staticmethod |
||
| 152 | def key(name: str) -> typer.Option: |
||
| 153 | return typer.Option( |
||
| 154 | name, |
||
| 155 | min=1, |
||
| 156 | max=120, |
||
| 157 | help=""" |
||
| 158 | A free-text unique key for the search. |
||
| 159 | Should be a short, <60-character name that describes the search and any parameters. |
||
| 160 | The output file will be named according to a 'sanitized' variant of this value. |
||
| 161 | """, |
||
| 162 | ) |
||
| 163 | |||
| 164 | test = typer.Option( |
||
| 165 | False, |
||
| 166 | "--check", |
||
| 167 | help="Do not run searches; just check that the parameters are ok.", |
||
| 168 | ) |
||
| 169 | |||
| 170 | taxa = typer.Option( |
||
| 171 | "7742", |
||
| 172 | show_default=False, |
||
| 173 | help=doc( |
||
| 174 | """ |
||
| 175 | The IDs or names of UniProt taxa, comma-separated. |
||
| 176 | Taxon names and common names can be used for vertebrate species (where available). |
||
| 177 | |||
| 178 | This can have a significant effect on the search. See the docs fore more info. |
||
| 179 | |||
| 180 | [default: 7742] (Euteleostomi) |
||
| 181 | """ |
||
| 182 | ), |
||
| 183 | ) |
||
| 184 | |||
| 185 | traversal_strategy = typer.Option( |
||
| 186 | "@null", |
||
| 187 | "--traversal", |
||
| 188 | show_default=False, |
||
| 189 | help=doc( |
||
| 190 | """ |
||
| 191 | Target traversal strategy name, file, or class. |
||
| 192 | Dictates the way the network of ChEMBL targets is traversed (from the annotated target as a source). |
||
| 193 | Specifies the network links that are followed and which targets are 'accepted' for final annotations. |
||
| 194 | This option has a dramatic effect on the search. See the docs for more info. |
||
| 195 | |||
| 196 | Can be one of: |
||
| 197 | (A) A standard strategy name, starting with @; |
||
| 198 | (B) The path to a ``*.strat`` file; OR |
||
| 199 | (C) The fully qualified name of a ``TargetTraversal`` |
||
| 200 | |||
| 201 | The standard traversal strategies are: {} |
||
| 202 | |||
| 203 | [default: @null] (No traversal; targets as-is) |
||
| 204 | """.format( |
||
| 205 | "; ".join(TargetTraversalStrategies.standard_strategies()) |
||
| 206 | ) |
||
| 207 | ), |
||
| 208 | ) |
||
| 209 | |||
| 210 | target_types = typer.Option( |
||
| 211 | "@molecular", |
||
| 212 | "--targets", |
||
| 213 | show_default=False, |
||
| 214 | help=doc( |
||
| 215 | """ |
||
| 216 | The accepted target types, comma-separated. |
||
| 217 | |||
| 218 | NOTE: This affects only the types are are accepted after traversal, |
||
| 219 | and the types must be included in the traversal. |
||
| 220 | This means that this must be AT LEAST as restrictive as the traversal strategy. |
||
| 221 | |||
| 222 | The ChEMBL-defined types are: |
||
| 223 | |||
| 224 | {} |
||
| 225 | |||
| 226 | These special names are also accepted: |
||
| 227 | |||
| 228 | - {} |
||
| 229 | |||
| 230 | [default: @molecular] |
||
| 231 | """.format( |
||
| 232 | "; ".join([s.name for s in TargetType.all_types()]), |
||
| 233 | "\n\n - ".join( |
||
| 234 | [f"{k} ({v})" for k, v in TargetType.special_type_names().items()] |
||
| 235 | ), |
||
| 236 | ) |
||
| 237 | ), |
||
| 238 | ) |
||
| 239 | |||
| 240 | min_confidence = typer.Option( |
||
| 241 | 3, |
||
| 242 | "--confidence", |
||
| 243 | min=0, |
||
| 244 | max=9, |
||
| 245 | show_default=False, |
||
| 246 | help=doc( |
||
| 247 | """ |
||
| 248 | Minimum target confidence score, inclusive. |
||
| 249 | This is useful to modify in only some cases. More important options are min_pchembl and taxa. |
||
| 250 | |||
| 251 | Values are: {} |
||
| 252 | |||
| 253 | [default: 3] |
||
| 254 | """.format( |
||
| 255 | "; ".join([f"{s.value} ({s.name})" for s in ConfidenceLevel]) |
||
| 256 | ) |
||
| 257 | ), |
||
| 258 | ) |
||
| 259 | |||
| 260 | relations = typer.Option( |
||
| 261 | "<,<=,=", |
||
| 262 | "--relations", |
||
| 263 | show_default=False, |
||
| 264 | help=doc( |
||
| 265 | """ |
||
| 266 | Assay activity relations allowed, comma-separated. |
||
| 267 | If post-processing yourself, consider including all. |
||
| 268 | Values are: <, <=, =, >, >=, ~. |
||
| 269 | [default: <,<=,=] |
||
| 270 | """ |
||
| 271 | ), |
||
| 272 | ) |
||
| 273 | |||
| 274 | min_pchembl = typer.Option( |
||
| 275 | 6.0, |
||
| 276 | "--pchembl", |
||
| 277 | min=0.0, |
||
| 278 | show_default=False, |
||
| 279 | help=doc( |
||
| 280 | """ |
||
| 281 | Minimum pCHEMBL value, inclusive. |
||
| 282 | If post-processing yourself, consider setting to 0.0. |
||
| 283 | [default: 6.0] |
||
| 284 | """ |
||
| 285 | ), |
||
| 286 | ) |
||
| 287 | |||
| 288 | banned_flags = typer.Option( |
||
| 289 | "@negative", |
||
| 290 | show_default=False, |
||
| 291 | help=doc( |
||
| 292 | """ |
||
| 293 | Exclude activity annotations with data validity flags, comma-separated. |
||
| 294 | It is rare to need to change this. |
||
| 295 | |||
| 296 | Values are: {}. |
||
| 297 | |||
| 298 | Special sets are: |
||
| 299 | |||
| 300 | - @all (all flags are banned) |
||
| 301 | |||
| 302 | - @negative ({}) |
||
| 303 | |||
| 304 | - @positive ({}) |
||
| 305 | |||
| 306 | [default: @negative] |
||
| 307 | """.format( |
||
| 308 | "; ".join([s.name for s in DataValidityComment]), |
||
| 309 | ", ".join([s.name for s in DataValidityComment.negative_comments()]), |
||
| 310 | ", ".join([s.name for s in DataValidityComment.positive_comments()]), |
||
| 311 | ), |
||
| 312 | ), |
||
| 313 | ) |
||
| 314 | |||
| 315 | chembl_trial = typer.Option( |
||
| 316 | 0, |
||
| 317 | "--phase", |
||
| 318 | show_default=False, |
||
| 319 | help=doc( |
||
| 320 | """ |
||
| 321 | Minimum phase of a clinical trial, inclusive. |
||
| 322 | Values are: 0, 1, 2, 3. |
||
| 323 | [default: 0] |
||
| 324 | """ |
||
| 325 | ), |
||
| 326 | min=0, |
||
| 327 | max=3, |
||
| 328 | ) |
||
| 329 | |||
| 330 | |||
| 331 | class Entry(Generic[S], metaclass=abc.ABCMeta): |
||
| 332 | @classmethod |
||
| 333 | def cmd(cls) -> str: |
||
| 334 | key = cls._get_default_key() |
||
| 335 | if isinstance(key, typer.models.OptionInfo): |
||
| 336 | key = key.default |
||
| 337 | if key is None or not isinstance(key, str): |
||
| 338 | raise AssertionError(f"Key for {cls.__name__} is {key}") |
||
| 339 | return key |
||
| 340 | |||
| 341 | @classmethod |
||
| 342 | def run(cls, path: Path, **params) -> None: |
||
| 343 | raise NotImplementedError() |
||
| 344 | |||
| 345 | @classmethod |
||
| 346 | def get_search_type(cls) -> Type[S]: |
||
| 347 | # noinspection PyTypeChecker |
||
| 348 | return ReflectionUtils.get_generic_arg(cls, Search) |
||
| 349 | |||
| 350 | @classmethod |
||
| 351 | def test(cls, path: Path, **params) -> None: |
||
| 352 | params = dict(params) |
||
| 353 | params["test"] = True |
||
| 354 | cls.run(**params) |
||
| 355 | |||
| 356 | @classmethod |
||
| 357 | def _run(cls, built: S, path: Path, to: Optional[Path], check: bool): |
||
| 358 | searcher = Searcher([built], [to], path) |
||
| 359 | if not check: |
||
| 360 | searcher.search() |
||
| 361 | return searcher |
||
| 362 | |||
| 363 | # @classmethod |
||
| 364 | # def build(cls, path: Path, **params: Mapping[str, Union[int, float, str]]) -> Search: |
||
| 365 | # raise NotImplementedError() |
||
| 366 | |||
| 367 | @classmethod |
||
| 368 | def default_param_values(cls) -> Mapping[str, Union[str, float, int]]: |
||
| 369 | return { |
||
| 370 | param: value |
||
| 371 | for param, value in ReflectionUtils.default_arg_values(cls.run).items() |
||
| 372 | if param not in {"key", "path"} |
||
| 373 | } |
||
| 374 | |||
| 375 | @classmethod |
||
| 376 | def _get_default_key(cls) -> str: |
||
| 377 | vals = ReflectionUtils.default_arg_values(cls.run) |
||
| 378 | try: |
||
| 379 | return vals["key"] |
||
| 380 | except KeyError: |
||
| 381 | logger.error(f"key not in {vals.keys()} for {cls.__name__}") |
||
| 382 | raise |
||
| 383 | |||
| 384 | |||
| 385 | class EntryChemblBinding(Entry[BindingSearch]): |
||
| 386 | @classmethod |
||
| 387 | def run( |
||
| 388 | cls, |
||
| 389 | path: Path = _Typer.path, |
||
| 390 | key: str = _Typer.key("chembl:binding"), |
||
| 391 | to: Optional[Path] = _Typer.to, |
||
| 392 | taxa: Optional[str] = _Typer.taxa, |
||
| 393 | traversal=_Typer.traversal_strategy, |
||
| 394 | target_types=_Typer.target_types, |
||
| 395 | confidence=_Typer.min_confidence, |
||
| 396 | relations=_Typer.relations, |
||
| 397 | min_pchembl=_Typer.min_pchembl, |
||
| 398 | banned_flags=_Typer.banned_flags, |
||
| 399 | check: bool = _Typer.test, |
||
| 400 | ) -> Searcher: |
||
| 401 | """ |
||
| 402 | Binding data from ChEMBL. |
||
| 403 | These are 'activity' annotations of the type 'B' that have a pCHEMBL value. |
||
| 404 | There is extended documentation on this search; see: |
||
| 405 | |||
| 406 | https://mandos-chem.readthedocs.io/en/latest/binding.html |
||
| 407 | |||
| 408 | OBJECT: ChEMBL preferred target name |
||
| 409 | |||
| 410 | PREDICATE: "binds to" |
||
| 411 | |||
| 412 | OTHER COLUMNS: |
||
| 413 | |||
| 414 | - taxon_id: From UniProt |
||
| 415 | |||
| 416 | - taxon_name: From Uniprot (scientific name) |
||
| 417 | |||
| 418 | - pchembl: Negative base-10 log of activity value (see docs on ChEMBL) |
||
| 419 | |||
| 420 | - standard_relation: One of '<', '<=', '=', '>=', '>', '~'. Consider using <, <=, and = to indicate hits. |
||
| 421 | |||
| 422 | - std_type: e.g. EC50, Kd |
||
| 423 | """ |
||
| 424 | built = BindingSearch( |
||
| 425 | key=key, |
||
| 426 | api=Apis.Chembl, |
||
| 427 | taxa=Utils.get_taxa(taxa), |
||
| 428 | traversal_strategy=traversal, |
||
| 429 | allowed_target_types=Utils.get_target_types(target_types), |
||
| 430 | min_confidence_score=confidence, |
||
| 431 | allowed_relations=Utils.split(relations), |
||
| 432 | min_pchembl=min_pchembl, |
||
| 433 | banned_flags=Utils.get_flags(banned_flags), |
||
| 434 | ) |
||
| 435 | return cls._run(built, path, to, check) |
||
| 436 | |||
| 437 | |||
| 438 | class EntryChemblMechanism(Entry[MechanismSearch]): |
||
| 439 | @classmethod |
||
| 440 | def run( |
||
| 441 | cls, |
||
| 442 | path: Path = _Typer.path, |
||
| 443 | key: str = _Typer.key("chembl:mechanism"), |
||
| 444 | to: Optional[Path] = _Typer.to, |
||
| 445 | taxa: Optional[str] = _Typer.taxa, |
||
| 446 | traversal: str = _Typer.traversal_strategy, |
||
| 447 | target_types: str = _Typer.target_types, |
||
| 448 | min_confidence: Optional[int] = _Typer.min_confidence, |
||
| 449 | check: bool = _Typer.test, |
||
| 450 | verbose: int = _Typer.verbose, |
||
| 451 | ) -> Searcher: |
||
| 452 | """ |
||
| 453 | Mechanism of action (MoA) data from ChEMBL. |
||
| 454 | |||
| 455 | OBJECT: ChEMBL preferred target name |
||
| 456 | |||
| 457 | PREDICATE: Target action; e.g. "agonist of" or "positive allosteric modulator of" |
||
| 458 | |||
| 459 | OTHER COLUMNS: |
||
| 460 | |||
| 461 | - direct_interaction: true or false |
||
| 462 | |||
| 463 | - description: From ChEMBL |
||
| 464 | |||
| 465 | - exact_target_id: the specifically annotated target, before traversal |
||
| 466 | """ |
||
| 467 | built = MechanismSearch( |
||
| 468 | key=key, |
||
| 469 | api=Apis.Chembl, |
||
| 470 | taxa=Utils.get_taxa(taxa), |
||
| 471 | traversal_strategy=traversal, |
||
| 472 | allowed_target_types=Utils.get_target_types(target_types), |
||
| 473 | min_confidence_score=min_confidence, |
||
| 474 | ) |
||
| 475 | return cls._run(built, path, to, check) |
||
| 476 | |||
| 477 | |||
| 478 | class EntryChemblTrials(Entry[IndicationSearch]): |
||
| 479 | @classmethod |
||
| 480 | def run( |
||
| 481 | cls, |
||
| 482 | path: Path = _Typer.path, |
||
| 483 | key: str = _Typer.key("chembl.trial"), |
||
| 484 | to: Optional[Path] = _Typer.to, |
||
| 485 | min_phase: Optional[int] = _Typer.chembl_trial, |
||
| 486 | check: bool = _Typer.test, |
||
| 487 | verbose: int = _Typer.verbose, |
||
| 488 | ) -> Searcher: |
||
| 489 | """ |
||
| 490 | Diseases from clinical trials listed in ChEMBL. |
||
| 491 | |||
| 492 | OBJECT: MeSH code |
||
| 493 | |||
| 494 | PREDICATE: "phase <level> trial" |
||
| 495 | """ |
||
| 496 | built = IndicationSearch(key=key, api=Apis.Chembl, min_phase=min_phase) |
||
| 497 | return cls._run(built, path, to, check) |
||
| 498 | |||
| 499 | |||
| 500 | class EntryChemblAtc(Entry[AtcSearch]): |
||
| 501 | @classmethod |
||
| 502 | def run( |
||
| 503 | cls, |
||
| 504 | path: Path = _Typer.path, |
||
| 505 | key: str = _Typer.key("chembl.atc"), |
||
| 506 | to: Optional[Path] = _Typer.to, |
||
| 507 | levels: str = typer.Option( |
||
| 508 | "1,2,3,4,5", min=1, max=5, help="""List of ATC levels, comma-separated.""" |
||
| 509 | ), |
||
| 510 | check: bool = _Typer.test, |
||
| 511 | verbose: int = _Typer.verbose, |
||
| 512 | ) -> Searcher: |
||
| 513 | """ |
||
| 514 | ATC codes from ChEMBL. |
||
| 515 | |||
| 516 | OBJECT: ATC Code |
||
| 517 | |||
| 518 | PREDICATE: "ATC L<leveL> code" |
||
| 519 | """ |
||
| 520 | built = AtcSearch( |
||
| 521 | key=key, api=Apis.Chembl, levels={int(x.strip()) for x in levels.split(",")} |
||
| 522 | ) |
||
| 523 | return cls._run(built, path, to, check) |
||
| 524 | |||
| 525 | |||
| 526 | class _EntryChemblGo(Entry[GoSearch], metaclass=abc.ABCMeta): |
||
| 527 | @classmethod |
||
| 528 | def go_type(cls) -> GoType: |
||
| 529 | raise NotImplementedError() |
||
| 530 | |||
| 531 | @classmethod |
||
| 532 | def cmd(cls) -> str: |
||
| 533 | me = str(cls.go_type().name) |
||
| 534 | return f"chembl:go.{me.lower()}" |
||
| 535 | |||
| 536 | @classmethod |
||
| 537 | def run( |
||
| 538 | cls, |
||
| 539 | path: Path = _Typer.path, |
||
| 540 | key: str = _Typer.key("<see above>"), |
||
| 541 | to: Optional[Path] = _Typer.to, |
||
| 542 | taxa: Optional[str] = _Typer.taxa, |
||
| 543 | traversal_strategy: str = _Typer.traversal_strategy, |
||
| 544 | target_types: str = _Typer.target_types, |
||
| 545 | confidence: Optional[int] = _Typer.min_confidence, |
||
| 546 | relations: str = _Typer.relations, |
||
| 547 | min_pchembl: float = _Typer.min_pchembl, |
||
| 548 | banned_flags: Optional[str] = _Typer.banned_flags, |
||
| 549 | binding_search: Optional[str] = typer.Option( |
||
| 550 | None, |
||
| 551 | help=""" |
||
| 552 | The fully qualified name of a class inheriting ``BindingSearch``. |
||
| 553 | If specified, all parameters above are passed to its constructor. |
||
| 554 | """, |
||
| 555 | ), |
||
| 556 | check: bool = _Typer.test, |
||
| 557 | verbose: int = _Typer.verbose, |
||
| 558 | ) -> Searcher: |
||
| 559 | """ |
||
| 560 | GO terms associated with ChEMBL binding targets. |
||
| 561 | |||
| 562 | OBJECT: GO Term name |
||
| 563 | |||
| 564 | PREDICATE: "associated with ""Function"|"Process"|"Component"" term" |
||
| 565 | |||
| 566 | OTHER COLUMNS: |
||
| 567 | See the docs for ``mandos chembl:binding`` |
||
| 568 | |||
| 569 | Note: |
||
| 570 | |||
| 571 | By default, the key is the "chembl:go.function", "chembl:go.process", or "chembl:go.component". |
||
| 572 | |||
| 573 | """ |
||
| 574 | if key is None or key == "<see above>": |
||
| 575 | key = cls.cmd() |
||
| 576 | api = ChemblApi.wrap(Apis.Chembl) |
||
| 577 | if binding_search is None: |
||
| 578 | binding_clazz = BindingSearch |
||
| 579 | else: |
||
| 580 | binding_clazz = ReflectionUtils.injection(binding_search, BindingSearch) |
||
| 581 | logger.info(f"NOTICE: Passing parameters to {binding_clazz.__qualname__}") |
||
| 582 | try: |
||
| 583 | binding_search = binding_clazz( |
||
| 584 | key=key, |
||
| 585 | api=Apis.Chembl, |
||
| 586 | taxa=Utils.get_taxa(taxa), |
||
| 587 | traversal_strategy=traversal_strategy, |
||
| 588 | allowed_target_types=Utils.get_target_types(target_types), |
||
| 589 | min_confidence_score=confidence, |
||
| 590 | allowed_relations=Utils.split(relations), |
||
| 591 | min_pchembl=min_pchembl, |
||
| 592 | banned_flags=Utils.get_flags(banned_flags), |
||
| 593 | ) |
||
| 594 | except (TypeError, ValueError): |
||
| 595 | raise InjectionError(f"Failed to build {binding_clazz.__qualname__}") |
||
| 596 | built = GoSearch(key, api, cls.go_type(), binding_search) |
||
| 597 | return cls._run(built, path, to, check) |
||
| 598 | |||
| 599 | |||
| 600 | class EntryGoFunction(_EntryChemblGo): |
||
| 601 | @classmethod |
||
| 602 | def go_type(cls) -> GoType: |
||
| 603 | return GoType.function |
||
| 604 | |||
| 605 | |||
| 606 | class EntryGoProcess(_EntryChemblGo): |
||
| 607 | @classmethod |
||
| 608 | def go_type(cls) -> GoType: |
||
| 609 | return GoType.process |
||
| 610 | |||
| 611 | |||
| 612 | class EntryGoComponent(_EntryChemblGo): |
||
| 613 | @classmethod |
||
| 614 | def go_type(cls) -> GoType: |
||
| 615 | return GoType.component |
||
| 616 | |||
| 617 | |||
| 618 | class EntryPubchemDisease(Entry[DiseaseSearch]): |
||
| 619 | @classmethod |
||
| 620 | def run( |
||
| 621 | cls, |
||
| 622 | path: Path = _Typer.path, |
||
| 623 | key: str = _Typer.key("disease.ctd:mesh"), |
||
| 624 | to: Optional[Path] = _Typer.to, |
||
| 625 | check: bool = _Typer.test, |
||
| 626 | verbose: int = _Typer.verbose, |
||
| 627 | ) -> Searcher: |
||
| 628 | """ |
||
| 629 | Diseases in the Comparative Toxicogenomics Database (CTD). |
||
| 630 | |||
| 631 | OBJECT: MeSH code of disease |
||
| 632 | |||
| 633 | PREDICATE: "marker/mechanism evidence for" or "disease evidence for" |
||
| 634 | """ |
||
| 635 | built = DiseaseSearch(key, Apis.Pubchem) |
||
| 636 | return cls._run(built, path, to, check) |
||
| 637 | |||
| 638 | |||
| 639 | class _EntryPubchemCoOccurrence(Entry[U], metaclass=abc.ABCMeta): |
||
| 640 | @classmethod |
||
| 641 | def cmd(cls) -> str: |
||
| 642 | me = str(cls.get_cooccurrence_type().name) |
||
| 643 | return f"lit.pubchem:{me.lower()}" |
||
| 644 | |||
| 645 | @classmethod |
||
| 646 | def get_cooccurrence_type(cls) -> CoOccurrenceType: |
||
| 647 | s: CoOccurrenceSearch = cls.get_search_type() |
||
| 648 | return s.cooccurrence_type() |
||
| 649 | |||
| 650 | @classmethod |
||
| 651 | def run( |
||
| 652 | cls, |
||
| 653 | path: Path = _Typer.path, |
||
| 654 | key: str = _Typer.key("<see above>"), |
||
| 655 | to: Optional[Path] = _Typer.to, |
||
| 656 | min_score: float = typer.Option( |
||
| 657 | 0.0, |
||
| 658 | help="Minimum enrichment score, inclusive. See docs for more info.", |
||
| 659 | min=0.0, |
||
| 660 | ), |
||
| 661 | min_articles: int = typer.Option( |
||
| 662 | 0, |
||
| 663 | help="Minimum number of articles for both the compound and object, inclusive.", |
||
| 664 | min=0, |
||
| 665 | ), |
||
| 666 | check: bool = _Typer.test, |
||
| 667 | verbose: int = _Typer.verbose, |
||
| 668 | ) -> Searcher: |
||
| 669 | """ |
||
| 670 | Co-occurrences from PubMed articles. |
||
| 671 | There is extended documentation on this search. |
||
| 672 | Also refer to https://pubchemdocs.ncbi.nlm.nih.gov/knowledge-panels |
||
| 673 | |||
| 674 | OBJECT: Name of gene/chemical/disease |
||
| 675 | |||
| 676 | PREDICATE: "co-occurs with <gene/chemical/disease>" |
||
| 677 | |||
| 678 | OTHER COLUMNS: |
||
| 679 | |||
| 680 | - score: enrichment score; see PubChem docs |
||
| 681 | |||
| 682 | - intersect_count: Number of articles co-occurring |
||
| 683 | |||
| 684 | - query_count: Total number of articles for query compound |
||
| 685 | |||
| 686 | - neighbor_count: Total number of articles for target (co-occurring) compound |
||
| 687 | """ |
||
| 688 | if key is None or key == "<see above>": |
||
| 689 | key = cls.cmd() |
||
| 690 | clazz = cls.get_search_type() |
||
| 691 | built = clazz(key, Apis.Pubchem, min_score=min_score, min_articles=min_articles) |
||
| 692 | return cls._run(built, path, to, check) |
||
| 693 | |||
| 694 | |||
| 695 | class EntryPubchemGeneCoOccurrence(_EntryPubchemCoOccurrence[GeneCoOccurrenceSearch]): |
||
| 696 | """""" |
||
| 697 | |||
| 698 | |||
| 699 | class EntryPubchemDiseaseCoOccurrence(_EntryPubchemCoOccurrence[DiseaseCoOccurrenceSearch]): |
||
| 700 | """""" |
||
| 701 | |||
| 702 | |||
| 703 | class EntryPubchemChemicalCoOccurrence(_EntryPubchemCoOccurrence[ChemicalCoOccurrenceSearch]): |
||
| 704 | """""" |
||
| 705 | |||
| 706 | |||
| 707 | class EntryPubchemDgi(Entry[DgiSearch]): |
||
| 708 | @classmethod |
||
| 709 | def run( |
||
| 710 | cls, |
||
| 711 | path: Path = _Typer.path, |
||
| 712 | key: str = _Typer.key("interact.dgidb:gene"), |
||
| 713 | to: Optional[Path] = _Typer.to, |
||
| 714 | check: bool = _Typer.test, |
||
| 715 | verbose: int = _Typer.verbose, |
||
| 716 | ) -> Searcher: |
||
| 717 | """ |
||
| 718 | Drug/gene interactions in the Drug Gene Interaction Database (DGIDB). |
||
| 719 | Also see ``disease.dgidb:int``. |
||
| 720 | |||
| 721 | OBJECT: Name of the gene |
||
| 722 | |||
| 723 | PREDICATE: "interacts with gene" |
||
| 724 | """ |
||
| 725 | built = DgiSearch(key, Apis.Pubchem) |
||
| 726 | return cls._run(built, path, to, check) |
||
| 727 | |||
| 728 | |||
| 729 | class EntryPubchemCgi(Entry[CtdGeneSearch]): |
||
| 730 | @classmethod |
||
| 731 | def run( |
||
| 732 | cls, |
||
| 733 | path: Path = _Typer.path, |
||
| 734 | key: str = _Typer.key("interact.ctd:gene"), |
||
| 735 | to: Optional[Path] = _Typer.to, |
||
| 736 | check: bool = _Typer.test, |
||
| 737 | verbose: int = _Typer.verbose, |
||
| 738 | ) -> Searcher: |
||
| 739 | """ |
||
| 740 | Compound/gene interactions in the Drug Gene Interaction Database (DGIDB). |
||
| 741 | Also see ``interact.dgidb:int``. |
||
| 742 | |||
| 743 | OBJECT: Name of the gene |
||
| 744 | |||
| 745 | PREDICATE: "compound/gene interaction" |
||
| 746 | |||
| 747 | """ |
||
| 748 | built = CtdGeneSearch(key, Apis.Pubchem) |
||
| 749 | return cls._run(built, path, to, check) |
||
| 750 | |||
| 751 | |||
| 752 | class EntryDrugbankTarget(Entry[DrugbankTargetSearch]): |
||
| 753 | @classmethod |
||
| 754 | def run( |
||
| 755 | cls, |
||
| 756 | path: Path = _Typer.path, |
||
| 757 | key: str = _Typer.key("interact.drugbank:target"), |
||
| 758 | to: Optional[Path] = _Typer.to, |
||
| 759 | check: bool = _Typer.test, |
||
| 760 | verbose: int = _Typer.verbose, |
||
| 761 | ) -> Searcher: |
||
| 762 | """ |
||
| 763 | Protein targets from DrugBank. |
||
| 764 | |||
| 765 | OBJECT: Target name (e.g. "Solute carrier family 22 member 11") from DrugBank |
||
| 766 | |||
| 767 | PREDICATE: Action (e.g. "binder", "downregulator", or "agonist") |
||
| 768 | """ |
||
| 769 | built = DrugbankTargetSearch(key, Apis.Pubchem, {DrugbankTargetType.target}) |
||
| 770 | return cls._run(built, path, to, check) |
||
| 771 | |||
| 772 | |||
| 773 | View Code Duplication | class EntryGeneralFunction(Entry[DrugbankGeneralFunctionSearch]): |
|
| 774 | @classmethod |
||
| 775 | def run( |
||
| 776 | cls, |
||
| 777 | path: Path = _Typer.path, |
||
| 778 | key: str = _Typer.key("interact.drugbank:target-function"), |
||
| 779 | to: Optional[Path] = _Typer.to, |
||
| 780 | check: bool = _Typer.test, |
||
| 781 | verbose: int = _Typer.verbose, |
||
| 782 | ) -> Searcher: |
||
| 783 | """ |
||
| 784 | General functions from DrugBank targets. |
||
| 785 | |||
| 786 | OBJECT: Name of the general function (e.g. "Toxic substance binding") |
||
| 787 | |||
| 788 | PREDICATE: against on target (e.g. "binder", "downregulator", or "agonist"). |
||
| 789 | """ |
||
| 790 | built = DrugbankGeneralFunctionSearch(key, Apis.Pubchem, {DrugbankTargetType.target}) |
||
| 791 | return cls._run(built, path, to, check) |
||
| 792 | |||
| 793 | |||
| 794 | class EntryDrugbankTransporter(Entry[DrugbankTargetSearch]): |
||
| 795 | @classmethod |
||
| 796 | def run( |
||
| 797 | cls, |
||
| 798 | path: Path = _Typer.path, |
||
| 799 | key: str = _Typer.key("interact.drugbank:pk"), |
||
| 800 | to: Optional[Path] = _Typer.to, |
||
| 801 | check: bool = _Typer.test, |
||
| 802 | verbose: int = _Typer.verbose, |
||
| 803 | ) -> Searcher: |
||
| 804 | """ |
||
| 805 | Protein transporters, carriers, and enzymes from DrugBank. |
||
| 806 | |||
| 807 | OBJECT: Transporter name (e.g. "Solute carrier family 22 member 11") from DrugBank |
||
| 808 | |||
| 809 | PREDICATE: "transported by", "carried by", or "metabolized by" |
||
| 810 | """ |
||
| 811 | target_types = { |
||
| 812 | DrugbankTargetType.transporter, |
||
| 813 | DrugbankTargetType.carrier, |
||
| 814 | DrugbankTargetType.enzyme, |
||
| 815 | } |
||
| 816 | built = DrugbankTargetSearch(key, Apis.Pubchem, target_types) |
||
| 817 | return cls._run(built, path, to, check) |
||
| 818 | |||
| 819 | |||
| 820 | View Code Duplication | class EntryTransporterGeneralFunction(Entry[DrugbankGeneralFunctionSearch]): |
|
| 821 | @classmethod |
||
| 822 | def run( |
||
| 823 | cls, |
||
| 824 | path: Path = _Typer.path, |
||
| 825 | key: str = _Typer.key("interact.drugbank:pk-function"), |
||
| 826 | to: Optional[Path] = _Typer.to, |
||
| 827 | check: bool = _Typer.test, |
||
| 828 | verbose: int = _Typer.verbose, |
||
| 829 | ) -> Searcher: |
||
| 830 | """ |
||
| 831 | General functions from DrugBank transporters, carriers, and enzymes. |
||
| 832 | |||
| 833 | OBJECT: Name of the general function (e.g. "Toxic substance binding") |
||
| 834 | |||
| 835 | PREDICATE: "transported by", "carried by", or "metabolized by" |
||
| 836 | """ |
||
| 837 | built = DrugbankGeneralFunctionSearch(key, Apis.Pubchem, {DrugbankTargetType.target}) |
||
| 838 | return cls._run(built, path, to, check) |
||
| 839 | |||
| 840 | |||
| 841 | class EntryDrugbankDdi(Entry[DrugbankDdiSearch]): |
||
| 842 | @classmethod |
||
| 843 | def run( |
||
| 844 | cls, |
||
| 845 | path: Path = _Typer.path, |
||
| 846 | key: str = _Typer.key("interact.drugbank:ddi"), |
||
| 847 | to: Optional[Path] = _Typer.to, |
||
| 848 | check: bool = _Typer.test, |
||
| 849 | verbose: int = _Typer.verbose, |
||
| 850 | ) -> Searcher: |
||
| 851 | """ |
||
| 852 | Drug/drug interactions listed by DrugBank. |
||
| 853 | |||
| 854 | The 'description' column includes useful information about the interaction, |
||
| 855 | such as diseases and whether a risk is increased or decreased. |
||
| 856 | |||
| 857 | OBJECT: name of the drug (e.g. "ibuprofen") |
||
| 858 | |||
| 859 | PREDICATE: "ddi" |
||
| 860 | """ |
||
| 861 | built = DrugbankDdiSearch(key, Apis.Pubchem) |
||
| 862 | return cls._run(built, path, to, check) |
||
| 863 | |||
| 864 | |||
| 865 | class EntryPubchemAssay(Entry[BioactivitySearch]): |
||
| 866 | @classmethod |
||
| 867 | def run( |
||
| 868 | cls, |
||
| 869 | path: Path = _Typer.path, |
||
| 870 | key: str = _Typer.key("assay.pubchem:activity"), |
||
| 871 | to: Optional[Path] = _Typer.to, |
||
| 872 | name_must_match: bool = typer.Option( |
||
| 873 | False, |
||
| 874 | help=doc( |
||
| 875 | """ |
||
| 876 | Require that the name of the compound(s) exactly matches the compound name on PubChem (case-insensitive) |
||
| 877 | """ |
||
| 878 | ), |
||
| 879 | ), |
||
| 880 | ban_sources: Optional[str] = None, |
||
| 881 | check: bool = _Typer.test, |
||
| 882 | verbose: int = _Typer.verbose, |
||
| 883 | ) -> Searcher: |
||
| 884 | """ |
||
| 885 | PubChem bioactivity results. |
||
| 886 | |||
| 887 | Note: The species name, if present, is taken from the target name. |
||
| 888 | The taxon ID is what was curated in PubChem. |
||
| 889 | |||
| 890 | OBJECT: Name of the target without species suffix (e.g. "Slc6a3 - solute carrier family 6 member 3") |
||
| 891 | |||
| 892 | PREDICATE: "active"|"inactive"|"inconclusive"|"undetermined" |
||
| 893 | |||
| 894 | SOURCE: "PubChem: <referrer> "(""confirmatory"|"literature"|"other"")" |
||
| 895 | """ |
||
| 896 | built = BioactivitySearch( |
||
| 897 | key, Apis.Pubchem, assay_types=set(AssayType), compound_name_must_match=name_must_match |
||
| 898 | ) |
||
| 899 | return cls._run(built, path, to, check) |
||
| 900 | |||
| 901 | |||
| 902 | class EntryDeaSchedule(Entry[BioactivitySearch]): |
||
| 903 | @classmethod |
||
| 904 | def run( |
||
| 905 | cls, |
||
| 906 | path: Path = _Typer.path, |
||
| 907 | key: str = _Typer.key("drug.dea:schedule"), |
||
| 908 | to: Optional[Path] = _Typer.to, |
||
| 909 | check: bool = _Typer.test, |
||
| 910 | verbose: int = _Typer.verbose, |
||
| 911 | ) -> Searcher: |
||
| 912 | """ |
||
| 913 | DEA schedules (UNDER CONSTRUCTION). |
||
| 914 | |||
| 915 | OBJECT: (1 to 4, or "unscheduled") |
||
| 916 | |||
| 917 | PREDICATE: "has DEA schedule" |
||
| 918 | """ |
||
| 919 | pass |
||
| 920 | |||
| 921 | |||
| 922 | class EntryDeaClass(Entry[BioactivitySearch]): |
||
| 923 | @classmethod |
||
| 924 | def run( |
||
| 925 | cls, |
||
| 926 | path: Path = _Typer.path, |
||
| 927 | key: str = _Typer.key("drug.dea:class"), |
||
| 928 | to: Optional[Path] = _Typer.to, |
||
| 929 | check: bool = _Typer.test, |
||
| 930 | verbose: int = _Typer.verbose, |
||
| 931 | ) -> Searcher: |
||
| 932 | """ |
||
| 933 | DEA classes (UNDER CONSTRUCTION). |
||
| 934 | |||
| 935 | OBJECT: e.g. "hallucinogen" |
||
| 936 | |||
| 937 | PREDICATE: "is in DEA class" |
||
| 938 | """ |
||
| 939 | pass |
||
| 940 | |||
| 941 | |||
| 942 | class EntryChemidPlusAcute(Entry[AcuteEffectSearch]): |
||
| 943 | @classmethod |
||
| 944 | def run( |
||
| 945 | cls, |
||
| 946 | path: Path = _Typer.path, |
||
| 947 | key: str = _Typer.key("tox.chemidplus:acute"), |
||
| 948 | to: Optional[Path] = _Typer.to, |
||
| 949 | level: int = typer.Option( |
||
| 950 | 2, |
||
| 951 | min=1, |
||
| 952 | max=2, |
||
| 953 | help=""" |
||
| 954 | The level in the ChemIDPlus hierarchy of effect names. |
||
| 955 | Level 1: e.g. 'behavioral' |
||
| 956 | Level 2: 'behavioral: excitement' |
||
| 957 | """, |
||
| 958 | ), |
||
| 959 | check: bool = _Typer.test, |
||
| 960 | verbose: int = _Typer.verbose, |
||
| 961 | ) -> Searcher: |
||
| 962 | """ |
||
| 963 | Acute effect codes from ChemIDPlus. |
||
| 964 | |||
| 965 | OBJECT: E.g. "behavioral: excitement" |
||
| 966 | |||
| 967 | PREDICATE: "causes acute effect" |
||
| 968 | |||
| 969 | OTHER COLUMNS: |
||
| 970 | |||
| 971 | - organism: e.g. 'women', 'infant', 'men', 'human', 'dog', 'domestic animals - sheep and goats' |
||
| 972 | - human: true or false |
||
| 973 | - test_type: e.g. 'TDLo' |
||
| 974 | - route: e.g. 'skin' |
||
| 975 | - mg_per_kg: e.g. 17.5 |
||
| 976 | """ |
||
| 977 | built = AcuteEffectSearch( |
||
| 978 | key, |
||
| 979 | Apis.Pubchem, |
||
| 980 | top_level=level == 1, |
||
| 981 | ) |
||
| 982 | return cls._run(built, path, to, check) |
||
| 983 | |||
| 984 | |||
| 985 | class EntryChemidPlusLd50(Entry[Ld50Search]): |
||
| 986 | @classmethod |
||
| 987 | def run( |
||
| 988 | cls, |
||
| 989 | path: Path = _Typer.path, |
||
| 990 | key: str = _Typer.key("tox.chemidplus:ld50"), |
||
| 991 | to: Optional[Path] = _Typer.to, |
||
| 992 | check: bool = _Typer.test, |
||
| 993 | verbose: int = _Typer.verbose, |
||
| 994 | ) -> Searcher: |
||
| 995 | """ |
||
| 996 | LD50 acute effects from ChemIDPlus. |
||
| 997 | |||
| 998 | OBJECT: A dose in mg/kg (e.g. 3100) |
||
| 999 | |||
| 1000 | PREDICATE: "LD50 :: <route>" (e.g. "LD50 :: intravenous) |
||
| 1001 | |||
| 1002 | OTHER COLUMNS: |
||
| 1003 | |||
| 1004 | - organism: e.g. 'women', 'infant', 'men', 'human', 'dog', 'domestic animals - sheep and goats' |
||
| 1005 | - human: true or false |
||
| 1006 | """ |
||
| 1007 | built = Ld50Search(key, Apis.Pubchem) |
||
| 1008 | return cls._run(built, path, to, check) |
||
| 1009 | |||
| 1010 | |||
| 1011 | class EntryHmdbTissue(Entry[BioactivitySearch]): |
||
| 1012 | @classmethod |
||
| 1013 | def run( |
||
| 1014 | cls, |
||
| 1015 | path: Path = _Typer.path, |
||
| 1016 | key: str = _Typer.key("hmdb:tissue"), |
||
| 1017 | to: Optional[Path] = _Typer.to, |
||
| 1018 | min_nanomolar: Optional[float] = None, |
||
| 1019 | check: bool = _Typer.test, |
||
| 1020 | verbose: int = _Typer.verbose, |
||
| 1021 | ) -> Searcher: |
||
| 1022 | """ |
||
| 1023 | Tissue concentrations from HMDB (**UNDER CONSTRUCTION**). |
||
| 1024 | |||
| 1025 | OBJECT: |
||
| 1026 | |||
| 1027 | PREDICATE: "tissue" |
||
| 1028 | """ |
||
| 1029 | pass |
||
| 1030 | |||
| 1031 | |||
| 1032 | class EntryHmdbComputed(Entry[BioactivitySearch]): |
||
| 1033 | @classmethod |
||
| 1034 | def run( |
||
| 1035 | cls, |
||
| 1036 | path: Path = _Typer.path, |
||
| 1037 | key: str = _Typer.key("hmdb:computed"), |
||
| 1038 | to: Optional[Path] = _Typer.to, |
||
| 1039 | min_nanomolar: Optional[float] = None, |
||
| 1040 | check: bool = _Typer.test, |
||
| 1041 | verbose: int = _Typer.verbose, |
||
| 1042 | ) -> Searcher: |
||
| 1043 | """ |
||
| 1044 | Computed molecular properties from HMDB (**UNDER CONSTRUCTION**). |
||
| 1045 | |||
| 1046 | Keys include pKa, logP, logS, etc. |
||
| 1047 | |||
| 1048 | OBJECT: A number; booleans are converted to 0/1 |
||
| 1049 | |||
| 1050 | PREDICATE: The name of the property |
||
| 1051 | """ |
||
| 1052 | pass |
||
| 1053 | |||
| 1054 | |||
| 1055 | class EntryPubchemReact(Entry[BioactivitySearch]): |
||
| 1056 | @classmethod |
||
| 1057 | def run( |
||
| 1058 | cls, |
||
| 1059 | path: Path = _Typer.path, |
||
| 1060 | key: str = _Typer.key("interact.pubchem:react"), |
||
| 1061 | to: Optional[Path] = _Typer.to, |
||
| 1062 | check: bool = _Typer.test, |
||
| 1063 | verbose: int = _Typer.verbose, |
||
| 1064 | ) -> Searcher: |
||
| 1065 | """ |
||
| 1066 | Metabolic reactions (**UNDER CONSTRUCTION**). |
||
| 1067 | |||
| 1068 | OBJECT: Equation |
||
| 1069 | |||
| 1070 | PREDICATE: "<pathway>" |
||
| 1071 | """ |
||
| 1072 | pass |
||
| 1073 | |||
| 1074 | |||
| 1075 | class EntryPubchemComputed(Entry[ComputedPropertySearch]): |
||
| 1076 | |||
| 1077 | KNOWN_USEFUL_KEYS: Mapping[str, str] = { |
||
| 1078 | "weight": "Molecular Weight", |
||
| 1079 | "xlogp3": None, |
||
| 1080 | "hydrogen-bond-donors": "Hydrogen Bond Donor Count", |
||
| 1081 | "hydrogen-bond-acceptors": "Hydrogen Bond Acceptor Count", |
||
| 1082 | "rotatable-bonds": "Rotatable Bond Count", |
||
| 1083 | "exact-mass": None, |
||
| 1084 | "monoisotopic-mass": None, |
||
| 1085 | "tpsa": "Topological Polar Surface Area", |
||
| 1086 | "heavy-atoms": "Heavy Atom Count", |
||
| 1087 | "charge": "Formal Charge", |
||
| 1088 | "complexity": None, |
||
| 1089 | } |
||
| 1090 | KNOWN_USELESS_KEYS: Mapping[str, str] = { |
||
| 1091 | "components": "Covalently-Bonded Unit Count", |
||
| 1092 | "isotope-atoms": "Isotope Atom Count", |
||
| 1093 | "defined-atom-stereocenter-count": None, |
||
| 1094 | "undefined-atom-stereocenter-count": None, |
||
| 1095 | "defined-bond-stereocenter-count": None, |
||
| 1096 | "undefined-bond-stereocenter-count": None, |
||
| 1097 | "compound-is-canonicalized": None, |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | @staticmethod |
||
| 1101 | def __stringify(keys: Mapping[str, str]): |
||
| 1102 | return ", ".join((k if v is None else f"{k} ({v.lower()})" for k, v in keys.items())) |
||
| 1103 | |||
| 1104 | @classmethod |
||
| 1105 | def run( |
||
| 1106 | cls, |
||
| 1107 | path: Path = _Typer.path, |
||
| 1108 | key: str = _Typer.key("chem.pubchem:computed"), |
||
| 1109 | keys: str = typer.Option( |
||
| 1110 | "weight,xlogp3,tpsa,complexity,exact-mass,heavy-atom-count,charge", |
||
| 1111 | help=""" |
||
| 1112 | The keys of the computed properties, comma-separated. |
||
| 1113 | Key names are case-insensitive and ignore punctuation like underscores and hyphens. |
||
| 1114 | |||
| 1115 | Known keys are: {} |
||
| 1116 | |||
| 1117 | Known, less-useful (metadata-like) keys are: {} |
||
| 1118 | """.format( |
||
| 1119 | __stringify(KNOWN_USEFUL_KEYS), __stringify(KNOWN_USELESS_KEYS) |
||
| 1120 | ), |
||
| 1121 | ), |
||
| 1122 | to: Optional[Path] = _Typer.to, |
||
| 1123 | check: bool = _Typer.test, |
||
| 1124 | verbose: int = _Typer.verbose, |
||
| 1125 | ) -> Searcher: |
||
| 1126 | """ |
||
| 1127 | Computed properties from PubChem. |
||
| 1128 | |||
| 1129 | OBJECT: Number |
||
| 1130 | |||
| 1131 | PREDICATE: e.g. "complexity" |
||
| 1132 | """ |
||
| 1133 | # replace acronyms, etc. |
||
| 1134 | # ComputedPropertySearch standardizes punctuation and casing |
||
| 1135 | known = { |
||
| 1136 | k: v |
||
| 1137 | for k, v in { |
||
| 1138 | **EntryPubchemComputed.KNOWN_USEFUL_KEYS, |
||
| 1139 | **EntryPubchemComputed.KNOWN_USELESS_KEYS, |
||
| 1140 | } |
||
| 1141 | if v is not None |
||
| 1142 | } |
||
| 1143 | keys = {known.get(s.strip(), s) for s in keys.split(",")} |
||
| 1144 | built = ComputedPropertySearch(key, Apis.Pubchem, descriptors=keys, source="PubChem") |
||
| 1145 | return cls._run(built, path, to, check) |
||
| 1146 | |||
| 1147 | |||
| 1148 | class EntryDrugbankAdmet(Entry[DrugbankTargetSearch]): |
||
| 1149 | @classmethod |
||
| 1150 | def run( |
||
| 1151 | cls, |
||
| 1152 | path: Path = _Typer.path, |
||
| 1153 | key: str = _Typer.key("drugbank.admet:properties"), |
||
| 1154 | to: Optional[Path] = _Typer.to, |
||
| 1155 | check: bool = _Typer.test, |
||
| 1156 | verbose: int = _Typer.verbose, |
||
| 1157 | ) -> Searcher: |
||
| 1158 | """ |
||
| 1159 | Enzyme predictions from DrugBank (UNDER CONSTRUCTION). |
||
| 1160 | |||
| 1161 | OBJECT: Enzyme name |
||
| 1162 | |||
| 1163 | PREDICATE: Action |
||
| 1164 | """ |
||
| 1165 | |||
| 1166 | |||
| 1167 | class EntryDrugbankMetabolites(Entry[DrugbankTargetSearch]): |
||
| 1168 | @classmethod |
||
| 1169 | def run( |
||
| 1170 | cls, |
||
| 1171 | path: Path = _Typer.path, |
||
| 1172 | key: str = _Typer.key("drugbank.admet:metabolites"), |
||
| 1173 | to: Optional[Path] = _Typer.to, |
||
| 1174 | check: bool = _Typer.test, |
||
| 1175 | verbose: int = _Typer.verbose, |
||
| 1176 | ) -> Searcher: |
||
| 1177 | """ |
||
| 1178 | Metabolites from DrugBank (UNDER CONSTRUCTION). |
||
| 1179 | |||
| 1180 | OBJECT: Compound name (e.g. "norcocaine"). |
||
| 1181 | |||
| 1182 | PREDICATE: "metabolized to" |
||
| 1183 | """ |
||
| 1184 | |||
| 1185 | |||
| 1186 | class EntryDrugbankDosage(Entry[DrugbankTargetSearch]): |
||
| 1187 | @classmethod |
||
| 1188 | def run( |
||
| 1189 | cls, |
||
| 1190 | path: Path = _Typer.path, |
||
| 1191 | key: str = _Typer.key("drugbank.admet:dosage"), |
||
| 1192 | to: Optional[Path] = _Typer.to, |
||
| 1193 | check: bool = _Typer.test, |
||
| 1194 | verbose: int = _Typer.verbose, |
||
| 1195 | ) -> Searcher: |
||
| 1196 | """ |
||
| 1197 | Dosage from DrugBank (UNDER CONSTRUCTION). |
||
| 1198 | |||
| 1199 | OBJECT: concentration in mg/mL |
||
| 1200 | |||
| 1201 | PREDICATE: "dosage :: <route>" |
||
| 1202 | |||
| 1203 | OTHER COLUMNS: |
||
| 1204 | |||
| 1205 | - form (e.g. liquid) |
||
| 1206 | """ |
||
| 1207 | |||
| 1208 | |||
| 1209 | class EntryMetaRandom(Entry[BioactivitySearch]): |
||
| 1210 | @classmethod |
||
| 1211 | def run( |
||
| 1212 | cls, |
||
| 1213 | path: Path = _Typer.path, |
||
| 1214 | key: str = _Typer.key("meta:random"), |
||
| 1215 | to: Optional[Path] = _Typer.to, |
||
| 1216 | check: bool = _Typer.test, |
||
| 1217 | verbose: int = _Typer.verbose, |
||
| 1218 | ) -> Searcher: |
||
| 1219 | """ |
||
| 1220 | Random class assignment with replacement (**UNDER CONSTRUCTION**). |
||
| 1221 | |||
| 1222 | OBJECT: 1 thru n-compounds |
||
| 1223 | |||
| 1224 | PREDICATE: "random" |
||
| 1225 | """ |
||
| 1226 | pass |
||
| 1227 | |||
| 1228 | |||
| 1229 | Entries = [ |
||
| 1230 | EntryChemblBinding, |
||
| 1231 | EntryChemblMechanism, |
||
| 1232 | EntryChemblAtc, |
||
| 1233 | EntryChemblTrials, |
||
| 1234 | EntryGoFunction, |
||
| 1235 | EntryGoProcess, |
||
| 1236 | EntryGoComponent, |
||
| 1237 | EntryPubchemDisease, |
||
| 1238 | EntryPubchemGeneCoOccurrence, |
||
| 1239 | EntryPubchemDiseaseCoOccurrence, |
||
| 1240 | EntryPubchemChemicalCoOccurrence, |
||
| 1241 | EntryPubchemDgi, |
||
| 1242 | EntryPubchemCgi, |
||
| 1243 | EntryDrugbankTarget, |
||
| 1244 | EntryGeneralFunction, |
||
| 1245 | EntryDrugbankTransporter, |
||
| 1246 | EntryTransporterGeneralFunction, |
||
| 1247 | EntryDrugbankDdi, |
||
| 1248 | EntryPubchemAssay, |
||
| 1249 | EntryDeaSchedule, |
||
| 1250 | EntryDeaClass, |
||
| 1251 | EntryChemidPlusAcute, |
||
| 1252 | EntryChemidPlusLd50, |
||
| 1253 | EntryHmdbTissue, |
||
| 1254 | EntryPubchemReact, |
||
| 1255 | EntryMetaRandom, |
||
| 1256 | ] |
||
| 1257 |