Passed
Push — dependabot/pip/flake8-bugbear-... ( 82a4d5...16d864 )
by
unknown
02:18
created

mandos.entries.entries._EntryChemblGo.run()   B

Complexity

Conditions 4

Size

Total Lines 56
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 38
nop 12
dl 0
loc 56
rs 8.968
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
"""
2
Run searches and write files.
3
"""
4
5
from __future__ import annotations
6
7
import abc
8
import logging
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
0 ignored issues
show
introduced by
Unable to import 'typer'
Loading history...
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
)
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.chembl.target_traversal import TargetTraversalStrategies
30
from mandos.search.pubchem.bioactivity_search import BioactivitySearch
31
from mandos.search.pubchem.dgidb_search import DgiSearch
32
from mandos.search.pubchem.ctd_gene_search import CtdGeneSearch
33
from mandos.entries.searcher import Searcher
34
from mandos.search.pubchem.drugbank_ddi_search import DrugbankDdiSearch
35
from mandos.search.pubchem.drugbank_interaction_search import (
36
    DrugbankTargetSearch,
37
    DrugbankGeneralFunctionSearch,
38
)
39
40
Chembl, Pubchem = Apis.Chembl, Apis.Pubchem
41
from mandos.search.chembl.binding_search import BindingSearch
0 ignored issues
show
introduced by
Import "from mandos.search.chembl.binding_search import BindingSearch" should be placed at the top of the module
Loading history...
42
from mandos.search.chembl.atc_search import AtcSearch
0 ignored issues
show
introduced by
Import "from mandos.search.chembl.atc_search import AtcSearch" should be placed at the top of the module
Loading history...
43
from mandos.search.chembl.go_search import GoType, GoSearch
0 ignored issues
show
introduced by
Import "from mandos.search.chembl.go_search import GoType, GoSearch" should be placed at the top of the module
Loading history...
44
from mandos.search.chembl.indication_search import IndicationSearch
0 ignored issues
show
introduced by
Import "from mandos.search.chembl.indication_search import IndicationSearch" should be placed at the top of the module
Loading history...
45
from mandos.search.chembl.mechanism_search import MechanismSearch
0 ignored issues
show
introduced by
Import "from mandos.search.chembl.mechanism_search import MechanismSearch" should be placed at the top of the module
Loading history...
46
from mandos.search.pubchem.cooccurrence_search import (
0 ignored issues
show
introduced by
Import "from mandos.search.pubchem.cooccurrence_search import GeneCoOccurrenceSearch, ChemicalCoOccurrenceSearch, CoOccurrenceSearch" should be placed at the top of the module
Loading history...
47
    GeneCoOccurrenceSearch,
48
    ChemicalCoOccurrenceSearch,
49
    CoOccurrenceSearch,
50
)
51
from mandos.search.pubchem.disease_search import DiseaseSearch
0 ignored issues
show
introduced by
Import "from mandos.search.pubchem.disease_search import DiseaseSearch" should be placed at the top of the module
Loading history...
52
53
logger = logging.getLogger(__package__)
54
55
S = TypeVar("S", bound=Search, covariant=True)
0 ignored issues
show
Coding Style Naming introduced by
Class name "S" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' pattern)

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.

Loading history...
56
U = TypeVar("U", covariant=True, bound=CoOccurrenceSearch)
0 ignored issues
show
Coding Style Naming introduced by
Class name "U" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' pattern)

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.

Loading history...
57
58
59
class Utils:
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
60
    """"""
61
62
    @staticmethod
63
    def split(st: str) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style Naming introduced by
Argument name "st" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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.

Loading history...
64
        return {s.strip() for s in st.split(",")}
65
66
    @staticmethod
67
    def get_taxa(taxa: str) -> Sequence[Taxonomy]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
68
        return [
69
            TaxonomyFactories.from_uniprot(MANDOS_SETTINGS.taxonomy_cache_path).load(int(taxon))
70
            for taxon in taxa.split(",")
71
        ]
72
73
    @staticmethod
74
    def get_trial_statuses(st: str) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style Naming introduced by
Argument name "st" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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.

Loading history...
75
        return ClinicalTrialsGovUtils.resolve_statuses(st)
76
77
    @staticmethod
78
    def get_target_types(st: str) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style Naming introduced by
Argument name "st" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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.

Loading history...
79
        return {s.name for s in TargetType.resolve(st)}
80
81
    @staticmethod
82
    def get_flags(st: str) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style Naming introduced by
Argument name "st" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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.

Loading history...
83
        return {s.name for s in DataValidityComment.resolve(st)}
84
85
86
class _Typer:
87
88
    path = typer.Argument(
89
        None,
90
        exists=True,
91
        dir_okay=False,
92
        readable=True,
93
        help=doc(
94
            """
95
            The path to the input file.
96
            One of:
97
98
              (A) *.txt or *.lines with one InChI Key per line;
99
100
              (B) A *.csv, *.tsv, *.tab file (or .gzip variant) with a column called 'inchikey'; OR
101
102
              (C) An Apache Arrow *.feather file with a column called 'inchikey'
103
        """
104
        ),
105
    )
106
107
    @staticmethod
108
    def key(name: str) -> typer.Option:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
109
        return typer.Option(
110
            name,
111
            min=1,
112
            max=120,
113
            help="""
114
            A free-text unique key for the search.
115
            Should be a short, <60-character name that describes the search and any parameters.
116
            The output file will be named according to a 'sanitized' variant of this value.
117
            """,
118
        )
119
120
    taxa = typer.Option(
121
        "7742",
122
        show_default=False,
123
        help=doc(
124
            """
125
        The IDs or names of UniProt taxa, comma-separated.
126
        Taxon names and common names can be used for vertebrate species (where available).
127
128
        This can have a significant effect on the search. See the docs fore more info.
129
130
        [default: 7742] (Euteleostomi)
131
        """
132
        ),
133
    )
134
135
    traversal_strategy = typer.Option(
136
        "@null",
137
        show_default=False,
138
        help=doc(
139
            """
140
        Target traversal strategy name, file, or class.
141
        Dictates the way the network of ChEMBL targets is traversed (from the annotated target as a source).
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
142
        Specifies the network links that are followed and which targets are 'accepted' for final annotations.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
143
        This option has a dramatic effect on the search. See the docs for more info.
144
145
        Can be one of:
146
        (A) A standard strategy name, starting with @;
147
        (B) The path to a ``*.strat`` file; OR
148
        (C) The fully qualified name of a ``TargetTraversal``
149
150
        The standard traversal strategies are: {}
151
152
        [default: @null] (No traversal; targets as-is)
153
        """.format(
154
                "; ".join(TargetTraversalStrategies.standard_strategies())
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
155
            )
156
        ),
157
    )
158
159
    target_types = typer.Option(
160
        "@molecular",
161
        show_default=False,
162
        help=doc(
163
            """
164
        The accepted target types, comma-separated.
165
166
        NOTE: This affects only the types are are accepted after traversal,
167
        and the types must be included in the traversal.
168
        This means that this must be AT LEAST as restrictive as the traversal strategy.
169
170
        The ChEMBL-defined types are:
171
172
          {}
173
174
        These special names are also accepted:
175
176
          - {}
177
178
        [default: @molecular]
179
        """.format(
180
                "; ".join([s.name for s in TargetType.all_types()]),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
181
                "\n\n          - ".join(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
182
                    [f"{k} ({v})" for k, v in TargetType.special_type_names().items()]
183
                ),
184
            )
185
        ),
186
    )
187
188
    min_confidence = typer.Option(
189
        3,
190
        min=0,
191
        max=9,
192
        show_default=False,
193
        help=doc(
194
            """
195
        Minimum target confidence score, inclusive.
196
        This is useful to modify in only some cases. More important options are min_pchembl and taxa.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
197
198
        Values are: {}
199
200
        [default: 3]
201
        """.format(
202
                "; ".join([f"{s.value} ({s.name})" for s in ConfidenceLevel])
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
203
            )
204
        ),
205
    )
206
207
    relations = typer.Option(
208
        "<,<=,=",
209
        show_default=False,
210
        help=doc(
211
            """
212
        Assay activity relations allowed, comma-separated.
213
        If post-processing yourself, consider including all.
214
        Values are: <, <=, =, >, >=, ~.
215
        [default: <,<=,=]
216
        """
217
        ),
218
    )
219
220
    min_pchembl = typer.Option(
221
        6.0,
222
        min=0.0,
223
        show_default=False,
224
        help=doc(
225
            """
226
        Minimum pCHEMBL value, inclusive.
227
        If post-processing yourself, consider setting to 0.0.
228
        [default: 6.0]
229
        """
230
        ),
231
    )
232
233
    banned_flags = typer.Option(
234
        "@negative",
235
        show_default=False,
236
        help=doc(
237
            """
238
        Exclude activity annotations with data validity flags, comma-separated.
239
        It is rare to need to change this.
240
241
        Values are: {}.
242
243
        Special sets are:
244
245
          - @all (all flags are banned)
246
247
          - @negative ({})
248
249
          - @positive ({})
250
251
        [default: @negative]
252
        """.format(
253
                "; ".join([s.name for s in DataValidityComment]),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
254
                ", ".join([s.name for s in DataValidityComment.negative_comments()]),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
255
                ", ".join([s.name for s in DataValidityComment.positive_comments()]),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
256
            ),
257
        ),
258
    )
259
260
    test = typer.Option(False, help="Do not run searches; just check that the parameters are ok.")
261
262
    chembl_trial = typer.Option(
263
        3,
264
        show_default=False,
265
        help=doc(
266
            """
267
        Minimum phase of a clinical trial, inclusive.
268
        Values are: 0, 1, 2, 3.
269
        [default: 3]
270
        """
271
        ),
272
        min=0,
273
        max=3,
274
    )
275
276
277
class Entry(Generic[S], metaclass=abc.ABCMeta):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
278
    @classmethod
279
    def cmd(cls) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
280
        key = cls._get_default_key()
281
        if isinstance(key, typer.models.OptionInfo):
282
            key = key.default
283
        if key is None or not isinstance(key, str):
284
            raise AssertionError(f"Key for {cls.__name__} is {key}")
285
        return key
286
287
    @classmethod
288
    def run(cls, path: Path, **params) -> None:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
289
        raise NotImplementedError()
290
291
    @classmethod
292
    def get_search_type(cls) -> Type[S]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
293
        # noinspection PyTypeChecker
294
        return ReflectionUtils.get_generic_arg(cls, Search)
295
296
    @classmethod
297
    def test(cls, path: Path, **params) -> None:
0 ignored issues
show
Unused Code introduced by
The argument path seems to be unused.
Loading history...
introduced by
Missing function or method docstring
Loading history...
298
        params = dict(params)
299
        params["test"] = True
300
        cls.run(**params)
301
302
    @classmethod
303
    def _run(cls, built: S, path: Path, test: bool):
304
        searcher = Searcher([built], path)
305
        if not test:
306
            searcher.search()
307
        return searcher
308
309
    # @classmethod
310
    # def build(cls, path: Path, **params: Mapping[str, Union[int, float, str]]) -> Search:
311
    #    raise NotImplementedError()
312
313
    @classmethod
314
    def default_param_values(cls) -> Mapping[str, Union[str, float, int]]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
315
        return {
316
            param: value
317
            for param, value in ReflectionUtils.default_arg_values(cls.run).items()
318
            if param not in {"key", "path"}
319
        }
320
321
    @classmethod
322
    def _get_default_key(cls) -> str:
323
        vals = ReflectionUtils.default_arg_values(cls.run)
324
        try:
325
            return vals["key"]
326
        except KeyError:
327
            logger.error(f"key not in {vals.keys()} for {cls.__name__}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
328
            raise
329
330
331
class EntryChemblBinding(Entry[BindingSearch]):
0 ignored issues
show
introduced by
Value 'Entry' is unsubscriptable
Loading history...
introduced by
Missing class docstring
Loading history...
332
    @classmethod
333
    def run(
0 ignored issues
show
best-practice introduced by
Too many arguments (11/5)
Loading history...
334
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
335
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
336
        key: str = _Typer.key("chembl:binding"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
337
        taxa: Optional[str] = _Typer.taxa,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
338
        traversal=_Typer.traversal_strategy,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
339
        target_types=_Typer.target_types,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
340
        confidence=_Typer.min_confidence,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
341
        relations=_Typer.relations,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
342
        min_pchembl=_Typer.min_pchembl,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
343
        banned_flags=_Typer.banned_flags,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
344
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
345
    ) -> Searcher:
346
        """
347
        Binding data from ChEMBL.
348
        These are 'activity' annotations of the type 'B' that have a pCHEMBL value.
349
        There is extended documentation on this search; see:
350
351
        https://mandos-chem.readthedocs.io/en/latest/binding.html
352
353
        OBJECT: ChEMBL preferred target name
354
355
        PREDICATE: "binds"
356
        """
357
        built = BindingSearch(
358
            key=key,
359
            api=Chembl,
360
            taxa=Utils.get_taxa(taxa),
361
            traversal_strategy=traversal,
362
            allowed_target_types=Utils.get_target_types(target_types),
363
            min_confidence_score=confidence,
364
            allowed_relations=Utils.split(relations),
365
            min_pchembl=min_pchembl,
366
            banned_flags=Utils.get_flags(banned_flags),
367
        )
368
        return cls._run(built, path, test)
369
370
371
class EntryChemblMechanism(Entry[MechanismSearch]):
0 ignored issues
show
introduced by
Value 'Entry' is unsubscriptable
Loading history...
introduced by
Missing class docstring
Loading history...
372
    @classmethod
373
    def run(
0 ignored issues
show
best-practice introduced by
Too many arguments (8/5)
Loading history...
374
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
375
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
376
        key: str = _Typer.key("chembl:mechanism"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
377
        taxa: Optional[str] = _Typer.taxa,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
378
        traversal: str = _Typer.traversal_strategy,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
379
        target_types: str = _Typer.target_types,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
380
        min_confidence: Optional[int] = _Typer.min_confidence,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
381
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
382
    ) -> Searcher:
383
        """
384
        Mechanism of action (MoA) data from ChEMBL.
385
386
        OBJECT: ChEMBL preferred target name
387
388
        PREDICATE: Target action; e.g. "agonist" or "positive allosteric modulator"
389
        """
390
        built = MechanismSearch(
391
            key=key,
392
            api=Chembl,
393
            taxa=Utils.get_taxa(taxa),
394
            traversal_strategy=traversal,
395
            allowed_target_types=Utils.get_target_types(target_types),
396
            min_confidence_score=min_confidence,
397
        )
398
        return cls._run(built, path, test)
399
400
401
class EntryChemblTrials(Entry[IndicationSearch]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
introduced by
Value 'Entry' is unsubscriptable
Loading history...
402
    @classmethod
403
    def run(
404
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
405
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
406
        key: str = _Typer.key("chembl.trial"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
407
        min_phase: Optional[int] = _Typer.chembl_trial,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
408
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
409
    ) -> Searcher:
410
        """
411
        Diseases from clinical trials listed in ChEMBL.
412
413
        OBJECT: MeSH code
414
415
        PREDICATE: "phase <level> trial"
416
        """
417
        built = IndicationSearch(key=key, api=Chembl, min_phase=min_phase)
418
        return cls._run(built, path, test)
419
420
421
class EntryChemblAtc(Entry[AtcSearch]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
introduced by
Value 'Entry' is unsubscriptable
Loading history...
422
    @classmethod
423
    def run(
424
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
425
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
426
        key: str = _Typer.key("chembl.atc"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
427
        levels: str = typer.Option(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
428
            "1,2,3,4,5", min=1, max=5, help="""List of ATC levels, comma-separated."""
429
        ),
430
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
431
    ) -> Searcher:
432
        """
433
        ATC codes from ChEMBL.
434
435
        OBJECT: ATC Code
436
437
        PREDICATE: "ATC L<leveL> code"
438
        """
439
        built = AtcSearch(key=key, api=Chembl, levels={int(x.strip()) for x in levels.split(",")})
440
        return cls._run(built, path, test)
441
442
443
class _EntryChemblGo(Entry[GoSearch], metaclass=abc.ABCMeta):
444
    @classmethod
445
    def go_type(cls) -> GoType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
446
        raise NotImplementedError()
447
448
    @classmethod
449
    def cmd(cls) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
450
        return f"chembl:go.{cls.go_type().name.lower()}"
451
452
    @classmethod
453
    def run(
0 ignored issues
show
best-practice introduced by
Too many arguments (12/5)
Loading history...
454
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
455
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
456
        key: str = _Typer.key("<see above>"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
457
        taxa: Optional[str] = _Typer.taxa,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
458
        traversal_strategy: str = _Typer.traversal_strategy,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
459
        target_types: str = _Typer.target_types,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
460
        confidence: Optional[int] = _Typer.min_confidence,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
461
        relations: str = _Typer.relations,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
462
        min_pchembl: float = _Typer.min_pchembl,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
463
        banned_flags: Optional[str] = _Typer.banned_flags,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
464
        binding_search: Optional[str] = typer.Option(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
465
            None,
466
            help="""
467
            The fully qualified name of a class inheriting ``BindingSearch``.
468
            If specified, all parameters above are passed to its constructor.
469
            """,
470
        ),
471
        test=_Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
    ) -> Searcher:
473
        """
474
        GO terms associated with ChEMBL binding targets.
475
476
        OBJECT: GO Term name
477
478
        PREDICATE: "GO <Function/Process/Component> term"
479
480
        Note:
481
482
            By default, the key is the "chembl:go.function", "chembl:go.process", or "chembl:go.component".
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
483
        """
484
        if key is None:
485
            key = cls.cmd()
486
        api = ChemblApi.wrap(Chembl)
487
        if binding_search is None:
488
            binding_clazz = BindingSearch
489
        else:
490
            binding_clazz = ReflectionUtils.injection(binding_search, BindingSearch)
491
            logger.info(f"NOTICE: Passing parameters to {binding_clazz.__qualname__}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
492
        try:
493
            binding_search = binding_clazz(
494
                key=key,
495
                api=Chembl,
496
                taxa=Utils.get_taxa(taxa),
497
                traversal_strategy=traversal_strategy,
498
                allowed_target_types=Utils.get_target_types(target_types),
499
                min_confidence_score=confidence,
500
                allowed_relations=Utils.split(relations),
501
                min_pchembl=min_pchembl,
502
                banned_flags=Utils.get_flags(banned_flags),
503
            )
504
        except (TypeError, ValueError):
505
            raise InjectionError(f"Failed to build {binding_clazz.__qualname__}")
506
        built = GoSearch(key, api, cls.go_type(), binding_search)
507
        return cls._run(built, path, test)
508
509
510
class EntryGoFunction(_EntryChemblGo):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
511
    @classmethod
512
    def go_type(cls) -> GoType:
513
        return GoType.function
514
515
516
class EntryGoProcess(_EntryChemblGo):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
517
    @classmethod
518
    def go_type(cls) -> GoType:
519
        return GoType.process
520
521
522
class EntryGoComponent(_EntryChemblGo):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
523
    @classmethod
524
    def go_type(cls) -> GoType:
525
        return GoType.component
526
527
528
class EntryPubchemDisease(Entry[DiseaseSearch]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
introduced by
Value 'Entry' is unsubscriptable
Loading history...
529
    @classmethod
530
    def run(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
531
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
532
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
533
        key: str = _Typer.key("disease.ctd:mesh"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
534
        therapeutic: bool = typer.Option(True, help="Include annotations of type 'therapeutic'"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
535
        marker: bool = typer.Option(True, help="Include annotations of type 'marker/mechanism'"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
536
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
537
    ) -> Searcher:
538
        """
539
        Diseases in the Comparative Toxicogenomics Database (CTD).
540
541
        OBJECT: MeSH code of disease
542
543
        PREDICATE: "marker/mechanism" or "disease"
544
        """
545
        built = DiseaseSearch(key, Pubchem, therapeutic=therapeutic, marker=marker)
546
        return cls._run(built, path, test)
547
548
549
class _EntryPubchemCoOccurrence(Entry[U], metaclass=abc.ABCMeta):
550
    @classmethod
551
    def cmd(cls) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
552
        return f"lit.pubchem:{cls.get_cooccurrence_type().name.lower()}"
553
554
    @classmethod
555
    def get_cooccurrence_type(cls) -> CoOccurrenceType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
556
        s: CoOccurrenceSearch = cls.get_search_type()
0 ignored issues
show
Coding Style Naming introduced by
Variable name "s" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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.

Loading history...
557
        return s.cooccurrence_type()
558
559
    @classmethod
560
    def run(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
561
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
562
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
563
        key: str = _Typer.key("<see above>"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
564
        min_score: float = typer.Option(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
565
            0.0,
566
            help="Minimum enrichment score, inclusive. See docs for more info.",
567
            min=0.0,
568
        ),
569
        min_articles: int = typer.Option(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
570
            0,
571
            help="Minimum number of articles for both the compound and object, inclusive.",
572
            min=0,
573
        ),
574
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
575
    ) -> Searcher:
576
        """
577
        Co-occurrences from PubMed articles.
578
        There is extended documentation on this search.
579
        Also refer to https://pubchemdocs.ncbi.nlm.nih.gov/knowledge-panels
580
581
        OBJECT: Name of gene/chemical/disease
582
583
        PREDICATE: "<gene/chemical/disease> co-occurrence"
584
        """
585
        if key is None:
586
            key = cls.cmd()
587
        clazz = cls.get_search_type()
588
        built = clazz(key, Pubchem, min_score=min_score, min_articles=min_articles)
589
        return cls._run(built, path, test)
590
591
592
class EntryPubchemGeneCoOccurrence(_EntryPubchemCoOccurrence[GeneCoOccurrenceSearch]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
593
    """"""
594
595
596
class EntryPubchemDiseaseCoOccurrence(_EntryPubchemCoOccurrence[GeneCoOccurrenceSearch]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
597
    """"""
598
599
600
class EntryPubchemChemicalCoOccurrence(_EntryPubchemCoOccurrence[ChemicalCoOccurrenceSearch]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
601
    """"""
602
603
604
class EntryPubchemDgi(Entry[DgiSearch]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
introduced by
Value 'Entry' is unsubscriptable
Loading history...
605
    @classmethod
606
    def run(
607
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
608
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
609
        key: str = _Typer.key("interact.dgidb:gene"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
610
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
611
    ) -> Searcher:
612
        """
613
        Drug/gene interactions in the Drug Gene Interaction Database (DGIDB).
614
        Also see ``disease.dgidb:int``.
615
616
        OBJECT: Name of the gene
617
618
        PREDICATE: "drug/gene interaction"
619
        """
620
        built = DgiSearch(key, Pubchem)
621
        return cls._run(built, path, test)
622
623
624
class EntryPubchemCgi(Entry[CtdGeneSearch]):
0 ignored issues
show
introduced by
Value 'Entry' is unsubscriptable
Loading history...
introduced by
Missing class docstring
Loading history...
625
    @classmethod
626
    def run(
627
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
628
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
629
        key: str = _Typer.key("interact.ctd:gene"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
630
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
631
    ) -> Searcher:
632
        """
633
        Compound/gene interactions in the Drug Gene Interaction Database (DGIDB).
634
        Also see ``interact.dgidb:int``.
635
636
        OBJECT: Name of the gene
637
638
        PREDICATE: "compound/gene interaction"
639
640
        """
641
        built = CtdGeneSearch(key, Pubchem)
642
        return cls._run(built, path, test)
643
644
645
class EntryDrugbankTarget(Entry[DrugbankTargetSearch]):
0 ignored issues
show
introduced by
Value 'Entry' is unsubscriptable
Loading history...
introduced by
Missing class docstring
Loading history...
646
    @classmethod
647
    def run(
648
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
649
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
650
        key: str = _Typer.key("interact.drugbank:target"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
651
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
652
    ) -> Searcher:
653
        """
654
        Protein targets from DrugBank.
655
656
        OBJECT: Target name (e.g. "Solute carrier family 22 member 11") from DrugBank
657
658
        PREDICATE: Action (e.g. "binder", "downregulator", or "agonist")
659
        """
660
        built = DrugbankTargetSearch(key, Pubchem)
661
        return cls._run(built, path, test)
662
663
664
class EntryGeneralFunction(Entry[DrugbankGeneralFunctionSearch]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
introduced by
Value 'Entry' is unsubscriptable
Loading history...
665
    @classmethod
666
    def run(
667
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
668
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
669
        key: str = _Typer.key("interact.drugbank:function"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
670
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
671
    ) -> Searcher:
672
        """
673
        General functions from DrugBank targets.
674
675
        OBJECT: Name of the general function (e.g. "Toxic substance binding")
676
677
        PREDICATE: against on target (e.g. "binder", "downregulator", or "agonist").
678
        """
679
        built = DrugbankGeneralFunctionSearch(key, Pubchem)
680
        return cls._run(built, path, test)
681
682
683
class EntryDrugbankDdi(Entry[DrugbankDdiSearch]):
0 ignored issues
show
introduced by
Value 'Entry' is unsubscriptable
Loading history...
introduced by
Missing class docstring
Loading history...
684
    @classmethod
685
    def run(
686
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
687
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
688
        key: str = _Typer.key("interact.drugbank:ddi"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
689
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
690
    ) -> Searcher:
691
        """
692
        Drug/drug interactions listed by DrugBank.
693
694
        The 'description' column includes useful information about the interaction,
695
        such as diseases and whether a risk is increased or decreased.
696
697
        OBJECT: name of the drug (e.g. "ibuprofen")
698
699
        PREDICATE: "ddi"
700
        """
701
        built = DrugbankDdiSearch(key, Pubchem)
702
        return cls._run(built, path, test)
703
704
705
class EntryPubchemAssay(Entry[BioactivitySearch]):
0 ignored issues
show
introduced by
Value 'Entry' is unsubscriptable
Loading history...
introduced by
Missing class docstring
Loading history...
706
    @classmethod
707
    def run(
0 ignored issues
show
best-practice introduced by
Too many arguments (9/5)
Loading history...
708
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
709
        path: Path = _Typer.path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
710
        key: str = _Typer.key("assay.pubchem:activity"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
711
        confirmatory: bool = typer.Option(True, help="Include 'confirmatory' assays"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
712
        literature: bool = typer.Option(True, help="Include 'literature' assays"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
713
        other: bool = typer.Option(True, help="Include 'other' assays"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
714
        name_must_match: bool = typer.Option(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
715
            False,
716
            help=doc(
717
                """
718
            Require that the name of the compound(s) exactly matches the compound name on PubChem (case-insensitive)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
719
        """
720
            ),
721
        ),
722
        ban_sources: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument ban_sources seems to be unused.
Loading history...
723
        test: bool = _Typer.test,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
724
    ) -> Searcher:
725
        """
726
        PubChem bioactivity results.
727
728
        Note: The species name, if present, is taken from the target name.
729
        The taxon ID is what was curated in PubChem.
730
731
        OBJECT: Name of the target without species suffix (e.g. "Slc6a3 - solute carrier family 6 member 3")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
732
733
        PREDICATE: "active"/"inactive"/"inconclusive"/"undetermined"
734
        """
735
        assay_types = set()
736
        if literature:
737
            assay_types.add(AssayType.literature)
738
        if confirmatory:
739
            assay_types.add(AssayType.confirmatory)
740
        if other:
741
            assay_types.add(AssayType.other)
742
        built = BioactivitySearch(
743
            key, Pubchem, assay_types=assay_types, compound_name_must_match=name_must_match
744
        )
745
        return cls._run(built, path, test)
746
747
748
Entries = [
749
    EntryChemblBinding,
750
    EntryChemblMechanism,
751
    EntryChemblAtc,
752
    EntryChemblTrials,
753
    EntryGoFunction,
754
    EntryGoProcess,
755
    EntryGoComponent,
756
    EntryPubchemDisease,
757
    EntryPubchemGeneCoOccurrence,
758
    EntryPubchemDiseaseCoOccurrence,
759
    EntryPubchemChemicalCoOccurrence,
760
    EntryPubchemDgi,
761
    EntryPubchemCgi,
762
    EntryDrugbankTarget,
763
    EntryGeneralFunction,
764
    EntryDrugbankDdi,
765
    EntryPubchemAssay,
766
]
767