mandos.search.chembl.mechanism_search   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A MechanismSearch.should_include() 0 7 2
A MechanismSearch.query() 0 2 1
A MechanismSearch.to_hit() 0 19 1
A MechanismHit.predicate() 0 3 1
A MechanismSearch.default_traversal_strategy() 0 3 1
1
import logging
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from dataclasses import dataclass
3
from typing import Sequence
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 import ChemblCompound
8
from mandos.model.targets import Target
9
from mandos.search.chembl.protein_search import ProteinHit, ProteinSearch
10
from mandos.search.chembl.target_traversal_strategy import (
11
    TargetTraversalStrategy,
12
    TargetTraversalStrategies,
13
)
14
15
logger = logging.getLogger("mandos")
16
17
18
@dataclass(frozen=True, order=True, repr=True)
19
class MechanismHit(ProteinHit):
20
    """
21
    A mechanism entry for a compound.
22
    """
23
24
    action_type: str
25
    direct_interaction: bool
26
    description: str
27
    exact_target_id: str
28
29
    @property
30
    def predicate(self) -> str:
31
        return self.action_type.lower()
32
33
34
class MechanismSearch(ProteinSearch[MechanismHit]):
35
    """
36
    Search for ``mechanisms``.
37
    """
38
39
    @property
40
    def default_traversal_strategy(self) -> TargetTraversalStrategy:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
41
        return TargetTraversalStrategies.strategy0(self.api)
42
43
    def query(self, parent_form: ChemblCompound) -> Sequence[NestedDotDict]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
44
        return list(self.api.mechanism.filter(parent_molecule_chembl_id=parent_form.chid))
45
46
    def should_include(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
47
        self, lookup: str, compound: ChemblCompound, data: NestedDotDict, target: Target
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...
48
    ) -> bool:
49
        if target.type.name.lower() not in {s.lower() for s in self.config.allowed_target_types}:
50
            logger.warning(f"Excluding {target} with type {target.type}")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
51
            return False
52
        return True
53
54
    def to_hit(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
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...
55
        self, lookup: str, compound: ChemblCompound, data: NestedDotDict, target: Target
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
56
    ) -> Sequence[MechanismHit]:
57
        # these must match the constructor of the Hit,
58
        # EXCEPT for object_id and object_name, which come from traversal
59
        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...
60
            dict(
61
                record_id=data["mec_id"],
62
                compound_id=compound.chid,
63
                inchikey=compound.inchikey,
64
                compound_name=compound.name,
65
                compound_lookup=lookup,
66
                action_type=data["action_type"],
67
                direct_interaction=data["direct_interaction"],
68
                description=data["mechanism_of_action"],
69
                exact_target_id=data["target_chembl_id"],
70
            )
71
        )
72
        return [MechanismHit(**x, object_id=target.chembl, object_name=target.name)]
73
74
75
__all__ = ["MechanismHit", "MechanismSearch"]
76