Passed
Push — main ( 2e1b6b...3a0c28 )
by Douglas
02:06
created

_DrugbankInteractionSearch.find()   B

Complexity

Conditions 5

Size

Total Lines 31
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 28
nop 2
dl 0
loc 31
rs 8.7413
c 0
b 0
f 0
1
from typing import Optional, Sequence, Set, TypeVar
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
from mandos.model.apis.pubchem_api import PubchemApi
4
from mandos.model.apis.pubchem_support.pubchem_models import (
5
    DrugbankInteraction,
6
    DrugbankTargetType,
7
)
8
9
# noinspection PyProtectedMember
10
from mandos.model.concrete_hits import (
11
    DrugbankGeneralFunctionHit,
12
    DrugbankTargetHit,
13
    _DrugbankInteractionHit,
14
)
15
from mandos.search.pubchem import PubchemSearch
16
17
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...
18
19
20
# noinspection PyAbstractClass
21
class _DrugbankInteractionSearch(PubchemSearch[T]):
22
    def __init__(self, key: str, api: PubchemApi, target_types: Set[DrugbankTargetType]):
23
        super().__init__(key, api)
24
        self.target_types = target_types
25
26
    @classmethod
27
    def _get_obj(cls, dd: DrugbankInteraction) -> Optional[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...
28
        raise NotImplementedError()
29
30
    def find(self, inchikey: str) -> Sequence[T]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
31
        data = self.api.fetch_data(inchikey)
32
        results = []
33
        for dd in data.biomolecular_interactions_and_pathways.drugbank_interactions:
0 ignored issues
show
Coding Style Naming introduced by
Variable 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...
34
            if dd.target_type in self.target_types:
35
                source = self._format_source(type=dd.target_type.name)
36
                predicate = self._format_predicate(
37
                    type=dd.target_type.name,
38
                    action="generic" if dd.action is None else dd.action,
39
                )
40
                obj = self._get_obj(dd)
41
                if obj is not None:
42
                    results.append(
43
                        self._create_hit(
44
                            c_id=str(data.cid),
45
                            c_origin=inchikey,
46
                            c_matched=data.names_and_identifiers.inchikey,
47
                            c_name=data.name,
48
                            data_source=source,
49
                            predicate=predicate,
50
                            object_id=obj,
51
                            object_name=obj,
52
                            gene_symbol=dd.gene_symbol,
53
                            protein_id=dd.protein_id,
54
                            target_type=dd.target_type.name,
55
                            target_name=dd.target_name,
56
                            general_function=dd.general_function,
57
                            cache_date=data.names_and_identifiers.modify_date,
58
                        )
59
                    )
60
        return results
61
62
63
class DrugbankTargetSearch(_DrugbankInteractionSearch[DrugbankTargetHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
64
    """ """
65
66
    @classmethod
67
    def _get_obj(cls, dd: DrugbankInteraction) -> Optional[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...
68
        return dd.target_name
69
70
71
class DrugbankGeneralFunctionSearch(_DrugbankInteractionSearch[DrugbankGeneralFunctionHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
72
    """ """
73
74
    @classmethod
75
    def _get_obj(cls, dd: DrugbankInteraction) -> Optional[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...
76
        return dd.general_function  # might be None
77
78
79
__all__ = [
80
    "DrugbankTargetSearch",
81
    "DrugbankGeneralFunctionSearch",
82
]
83