Passed
Push — dependabot/pip/flake8-bugbear-... ( 93dece...8d4b2b )
by
unknown
01:27
created

l_strategy()   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
import logging
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from dataclasses import dataclass
3
from typing import Sequence, Set, Optional
4
5
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
6
7
from mandos.model.chembl_api import ChemblApi
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
11
from mandos.search.chembl._protein_search import ProteinHit, ProteinSearch
12
from mandos.search.chembl.target_traversal import TargetTraversalStrategy, TargetTraversalStrategies
0 ignored issues
show
Unused Code introduced by
Unused TargetTraversalStrategy imported from mandos.search.chembl.target_traversal
Loading history...
Unused Code introduced by
Unused TargetTraversalStrategies imported from mandos.search.chembl.target_traversal
Loading history...
13
14
logger = logging.getLogger("mandos")
15
16
17
@dataclass(frozen=True, order=True, repr=True)
18
class MechanismHit(ProteinHit):
19
    """
20
    A mechanism entry for a compound.
21
    """
22
23
    action_type: str
24
    direct_interaction: bool
25
    description: str
26
    exact_target_id: str
27
28
    @property
29
    def predicate(self) -> str:
30
        return self.action_type.lower()
31
32
33
class MechanismSearch(ProteinSearch[MechanismHit]):
34
    """
35
    Search for ``mechanisms``.
36
    """
37
38
    def __init__(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
39
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
40
        chembl_api: ChemblApi,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
41
        tax: Taxonomy,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
42
        traversal_strategy: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
43
        allowed_target_types: Set[str],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
44
        min_confidence_score: Optional[int],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
45
    ):
46
        super().__init__(chembl_api, tax, traversal_strategy)
47
        self.allowed_target_types = allowed_target_types
48
        self.min_confidence_score = min_confidence_score
49
50
    def query(self, parent_form: ChemblCompound) -> Sequence[NestedDotDict]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
51
        return list(self.api.mechanism.filter(parent_molecule_chembl_id=parent_form.chid))
52
53
    def should_include(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
54
        self, lookup: str, compound: ChemblCompound, data: NestedDotDict, target: ChemblTargetGraph
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument lookup 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 data seems to be unused.
Loading history...
55
    ) -> bool:
56
        if target.type.name.lower() not in {s.lower() for s in self.allowed_target_types}:
57
            logger.warning(f"Excluding {target} with type {target.type}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
58
            return False
59
        return True
60
61
    def to_hit(
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
introduced by
Missing function or method docstring
Loading history...
62
        self, lookup: str, compound: ChemblCompound, data: NestedDotDict, target: ChemblTargetGraph
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
63
    ) -> Sequence[MechanismHit]:
64
        # these must match the constructor of the Hit,
65
        # EXCEPT for object_id and object_name, which come from traversal
66
        x = NestedDotDict(
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...
67
            dict(
68
                record_id=data["mec_id"],
69
                compound_id=compound.chid,
70
                inchikey=compound.inchikey,
71
                compound_name=compound.name,
72
                compound_lookup=lookup,
73
                action_type=data["action_type"],
74
                direct_interaction=data["direct_interaction"],
75
                description=data["mechanism_of_action"],
76
                exact_target_id=data["target_chembl_id"],
77
            )
78
        )
79
        return [MechanismHit(**x, object_id=target.chembl, object_name=target.name)]
80
81
82
__all__ = ["MechanismHit", "MechanismSearch"]
83