Passed
Push — dependabot/pip/flake8-bugbear-... ( 5c5892...6076c0 )
by
unknown
01:34
created

_DrugbankInteractionSearch.data_source()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
from dataclasses import dataclass
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from typing import Sequence, TypeVar, Set
3
4
from mandos.model.pubchem_api import PubchemApi
5
from mandos.model.pubchem_support.pubchem_models import DrugbankTargetType, DrugbankInteraction
6
from mandos.search.pubchem import PubchemHit, PubchemSearch
7
8
9
@dataclass(frozen=True, order=True, repr=True)
10
class _DrugbankInteractionHit(PubchemHit):
11
    """"""
12
13
    gene_symbol: str
14
    protein_id: str
15
    target_type: str
16
    target_name: str
17
    general_function: str
18
19
20
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
21
class DrugbankTargetHit(_DrugbankInteractionHit):
22
    """"""
23
24
25
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
26
class DrugbankGeneralFunctionHit(_DrugbankInteractionHit):
27
    """"""
28
29
30
T = TypeVar("T", bound=_DrugbankInteractionHit, covariant=True)
0 ignored issues
show
Coding Style Naming introduced by
Class name "T" 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...
31
32
33
class _DrugbankInteractionSearch(PubchemSearch[T]):
34
    def __init__(self, key: str, api: PubchemApi, target_types: Set[DrugbankTargetType]):
35
        super().__init__(key, api)
36
        self.target_types = target_types
37
38
    """"""
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...
39
40
    @classmethod
41
    def _get_obj(cls, dd: DrugbankInteraction) -> str:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" 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...
42
        raise NotImplementedError()
43
44
    @classmethod
45
    def _get_predicate(cls, dd: DrugbankInteraction) -> str:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" 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...
46
        raise NotImplementedError()
47
48
    def find(self, inchikey: str) -> Sequence[T]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
49
        data = self.api.fetch_data(inchikey)
50
        # noinspection PyPep8Naming
51
        H = self.__class__.get_h()
0 ignored issues
show
Coding Style Naming introduced by
Variable name "H" 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...
52
        return [
53
            H(
54
                record_id=dd.record_id,
55
                origin_inchikey=inchikey,
56
                matched_inchikey=data.names_and_identifiers.inchikey,
57
                compound_id=str(data.cid),
58
                compound_name=data.name,
59
                predicate=self._get_predicate(dd),
60
                object_id=self._get_obj(dd),
61
                object_name=self._get_obj(dd),
62
                search_key=self.key,
63
                search_class=self.search_class,
64
                data_source=self.data_source,
65
                gene_symbol=dd.gene_symbol,
66
                protein_id=dd.protein_id,
67
                target_type=dd.target_type.name,
68
                target_name=dd.target_name,
69
                general_function=dd.general_function,
70
            )
71
            for dd in data.biomolecular_interactions_and_pathways.drugbank_interactions
72
            if dd.target_type in self.target_types
73
        ]
74
75
76
class DrugbankTargetSearch(_DrugbankInteractionSearch[_DrugbankInteractionHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
77
    """"""
78
79
    @property
80
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
81
        return "DrugBank :: target interactions"
82
83
    @classmethod
84
    def _get_obj(cls, dd: DrugbankInteraction) -> str:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" 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...
85
        return dd.target_name
86
87
    @classmethod
88
    def _get_predicate(cls, dd: DrugbankInteraction) -> str:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" 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...
89
        return dd.target_type.name + ("" if dd.action is None else (" :: " + dd.action) + " on")
90
91
92
class DrugbankGeneralFunctionSearch(_DrugbankInteractionSearch[_DrugbankInteractionHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
93
    """"""
94
95
    @property
96
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
97
        return "DrugBank :: non-target interactions"
98
99
    @classmethod
100
    def _get_obj(cls, dd: DrugbankInteraction) -> str:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" 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...
101
        return dd.target_name if dd.general_function is None else dd.general_function
102
103
    @classmethod
104
    def _get_predicate(cls, dd: DrugbankInteraction) -> str:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" 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...
105
        return ("action" if dd.action is None else dd.action) + " on"
106
107
108
__all__ = [
109
    "DrugbankTargetHit",
110
    "DrugbankGeneralFunctionHit",
111
    "DrugbankTargetSearch",
112
    "DrugbankGeneralFunctionSearch",
113
]
114