Passed
Push — main ( a07aa0...748456 )
by Douglas
01:55
created

_DrugbankInteractionSearch.find()   A

Complexity

Conditions 1

Size

Total Lines 22
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
nop 2
dl 0
loc 22
rs 9.376
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
3
4
from mandos.model.pubchem_api import PubchemApi
0 ignored issues
show
Unused Code introduced by
Unused PubchemApi imported from mandos.model.pubchem_api
Loading history...
5
from mandos.search.pubchem import PubchemHit, PubchemSearch
6
7
8
@dataclass(frozen=True, order=True, repr=True)
9
class _DrugbankInteractionHit(PubchemHit):
10
    """"""
11
12
    gene_symbol: str
13
    protein_id: str
14
    target_name: str
15
    general_function: str
16
    specific_function: str
17
18
19
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
20
class DrugbankTargetHit(_DrugbankInteractionHit):
21
    """"""
22
23
24
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
25
class DrugbankGeneralFunctionHit(_DrugbankInteractionHit):
26
    """"""
27
28
29
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...
30
31
32
class _DrugbankInteractionSearch(PubchemSearch[T]):
33
    """"""
34
35
    @property
36
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
37
        return "DrugBank"
38
39
    @classmethod
40
    def _attr(cls):
41
        raise NotImplementedError()
42
43
    def find(self, inchikey: str) -> Sequence[T]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
44
        data = self.api.fetch_data(inchikey)
45
        return [
46
            self.__class__.get_h()(
47
                record_id=dd.record_id,
48
                origin_inchikey=inchikey,
49
                matched_inchikey=data.names_and_identifiers.inchikey,
50
                compound_id=str(data.cid),
51
                compound_name=data.name,
52
                predicate=dd.action,
53
                object_id=dd.protein_id,
54
                object_name=getattr(dd, self.__class__._attr()),
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _attr was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
55
                search_key=self.key,
56
                search_class=self.search_class,
57
                data_source=self.data_source,
58
                gene_symbol=dd.gene_symbol,
59
                protein_id=dd.protein_id,
60
                target_name=dd.target_name,
61
                general_function=dd.general_function,
62
                specific_function=dd.specific_function,
63
            )
64
            for dd in data.biomolecular_interactions_and_pathways.drugbank_interactions
65
        ]
66
67
68
class DrugbankTargetSearch(_DrugbankInteractionSearch[_DrugbankInteractionHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
69
    """"""
70
71
    @classmethod
72
    def _attr(cls):
73
        return "targetname"
74
75
76
class DrugbankGeneralFunctionSearch(_DrugbankInteractionSearch[_DrugbankInteractionHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
77
    """"""
78
79
    @classmethod
80
    def _attr(cls):
81
        return "generalfunction"
82
83
84
__all__ = [
85
    "DrugbankTargetHit",
86
    "DrugbankGeneralFunctionHit",
87
    "DrugbankTargetSearch",
88
    "DrugbankGeneralFunctionSearch",
89
]
90