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

MechanismSearch.__init__()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nop 7
dl 0
loc 11
rs 9.9
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, Set, Optional
0 ignored issues
show
Unused Code introduced by
Unused Optional imported from typing
Loading history...
Unused Code introduced by
Unused Set imported from typing
Loading history...
3
4
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
5
6
from mandos import logger
7
from mandos.model.chembl_api import ChemblApi
0 ignored issues
show
Unused Code introduced by
Unused ChemblApi imported from mandos.model.chembl_api
Loading history...
8
from mandos.model.chembl_support import ChemblCompound
9
from mandos.model.chembl_support.chembl_target_graphs import ChemblTargetGraph
10
from mandos.model.taxonomy import Taxonomy
0 ignored issues
show
Unused Code introduced by
Unused Taxonomy imported from mandos.model.taxonomy
Loading history...
11
from mandos.search.chembl._protein_search import ProteinHit, ProteinSearch
12
13
14
@dataclass(frozen=True, order=True, repr=True)
15
class MechanismHit(ProteinHit):
16
    """
17
    A mechanism entry for a compound.
18
    """
19
20
    action_type: str
21
    direct_interaction: bool
22
    description: str
23
24
25
class MechanismSearch(ProteinSearch[MechanismHit]):
26
    """
27
    Search for ``mechanisms``.
28
    """
29
30
    @property
31
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
32
        return "ChEMBL :: mechanisms"
33
34
    def query(self, parent_form: ChemblCompound) -> Sequence[NestedDotDict]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
35
        return list(self.api.mechanism.filter(parent_molecule_chembl_id=parent_form.chid))
36
37
    def should_include(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
38
        self, lookup: str, compound: ChemblCompound, data: NestedDotDict, target: ChemblTargetGraph
0 ignored issues
show
Unused Code introduced by
The argument data seems to be unused.
Loading history...
Unused Code introduced by
The argument compound seems to be unused.
Loading history...
Unused Code introduced by
The argument lookup seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
39
    ) -> bool:
40
        if target.type.name.lower() not in {s.lower() for s in self.allowed_target_types}:
41
            logger.warning(f"Excluding {target.name} with type {target.type}")
42
            return False
43
        return True
44
45
    def to_hit(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
46
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
47
        lookup: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
48
        compound: ChemblCompound,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
49
        data: NestedDotDict,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
50
        best_target: ChemblTargetGraph,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
51
    ) -> Sequence[MechanismHit]:
52
        # these must match the constructor of the Hit,
53
        # EXCEPT for object_id and object_name, which come from traversal
54
        predicate = data.req_as("action_type", str) + " of"
55
        x = MechanismHit(
0 ignored issues
show
Coding Style Naming introduced by
Variable name "x" 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...
56
            record_id=data["mec_id"],
57
            origin_inchikey=lookup,
58
            matched_inchikey=compound.inchikey,
59
            compound_id=compound.chid,
60
            compound_name=compound.name,
61
            predicate=predicate,
62
            object_id=best_target.chembl,
63
            object_name=best_target.name,
64
            search_key=self.key,
65
            search_class=self.search_class,
66
            data_source=self.data_source,
67
            exact_target_id=data.req_as("target_chembl_id", str),
68
            action_type=data.req_as("action_type", str),
69
            direct_interaction=data.req_as("direct_interaction", bool),
70
            description=data.req_as("mechanism_of_action", str),
71
        )
72
        return [x]
73
74
75
__all__ = ["MechanismHit", "MechanismSearch"]
76