Passed
Push — dependabot/pip/pyarrow-4.0.1 ( ca09ce...b2836e )
by
unknown
02:18 queued 20s
created

BindingSearch._predicate()   B

Complexity

Conditions 7

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nop 3
dl 0
loc 14
rs 8
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 Optional, Sequence, Set, Tuple
0 ignored issues
show
Unused Code introduced by
Unused Optional 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.model import MiscUtils
0 ignored issues
show
Unused Code introduced by
Unused MiscUtils imported from mandos.model
Loading history...
7
from mandos.model.apis.chembl_support import ChemblCompound
8
from mandos.model.apis.chembl_support.chembl_target_graphs import ChemblTargetGraph
9
from mandos.search.chembl._activity_search import _ActivityHit, _ActivitySearch
10
11
12
@dataclass(frozen=True, order=True, repr=True)
13
class BindingHit(_ActivityHit):
14
    """
15
    An "activity" hit for a compound.
16
    """
17
18
    pchembl: float
19
    std_type: str
20
    standard_relation: str
21
22
23
class BindingSearch(_ActivitySearch[BindingHit]):
24
    """
25
    Search for ``activity`` of type "B".
26
    """
27
28
    @property
29
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
30
        return "ChEMBL :: binding activity"
31
32
    @classmethod
33
    def allowed_assay_types(cls) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
34
        return {"B"}
35
36
    def to_hit(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
37
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
38
        lookup: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
39
        compound: ChemblCompound,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
40
        data: NestedDotDict,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
41
        best_target: ChemblTargetGraph,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
42
    ) -> Sequence[BindingHit]:
43
        # these must match the constructor of the Hit,
44
        # EXCEPT for object_id and object_name, which come from traversal
45
        from_super = self._extract(lookup, compound, data)
46
        rel = from_super.req_as("standard_relation", str)
47
        pchembl = from_super.req_as("pchembl_value", float)
48
        predicate, statement = self._predicate(pchembl, rel)
49
        hit = self._create_hit(
50
            c_origin=lookup,
51
            c_matched=compound.inchikey,
52
            c_id=compound.chid,
53
            c_name=compound.name,
54
            predicate=predicate,
55
            statement=statement,
56
            object_id=best_target.chembl,
57
            object_name=best_target.name,
58
            record_id=from_super.req_as("activity_id", str),
59
            exact_target_id=from_super.req_as("target_chembl_id", str),
60
            taxon_id=from_super.get("taxon_id"),
61
            taxon_name=from_super.get("taxon_name"),
62
            src_id=from_super.req_as("src_id", str),
63
            pchembl=pchembl,
64
            std_type=from_super.req_as("standard_type", str),
65
            standard_relation=rel,
66
        )
67
        return [hit]
68
69
    def _predicate(self, pchembl: float, rel: str) -> Tuple[str, str]:
70
        if (
71
            self.binds_cutoff is not None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
72
            and pchembl >= self.binds_cutoff
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
73
            and rel in {"=", "~", "<", "<="}
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
74
        ):
75
            return "binding:yes", "binds"
76
        if (
77
            self.does_not_bind_cutoff is not None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
78
            and pchembl <= self.does_not_bind_cutoff
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
79
            and rel in {"=", "~", ">", ">="}
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
80
        ):
81
            return "binding:no", "does not bind"
82
        return f"binding:{rel}", f"binding {rel}"
83
84
85
__all__ = ["BindingHit", "BindingSearch"]
86