Passed
Push — main ( cee75c...37036d )
by Douglas
02:08
created

BindingSearch._truth()   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 typing import Sequence, Set
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
4
5
from mandos.model.apis.chembl_support import ChemblCompound
6
from mandos.model.apis.chembl_support.chembl_target_graphs import ChemblTargetGraph
7
from mandos.search.chembl._activity_search import _ActivitySearch
8
from mandos.model.concrete_hits import BindingHit
9
10
11
class BindingSearch(_ActivitySearch[BindingHit]):
12
    """
13
    Search for ``activity`` of type "B".
14
    """
15
16
    @classmethod
17
    def allowed_assay_types(cls) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
18
        return {"B"}
19
20
    def to_hit(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
21
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
22
        lookup: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
23
        compound: ChemblCompound,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
24
        data: NestedDotDict,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
25
        best_target: ChemblTargetGraph,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
26
    ) -> Sequence[BindingHit]:
27
        # these must match the constructor of the Hit,
28
        # EXCEPT for object_id and object_name, which come from traversal
29
        from_super = self._extract(lookup, compound, data)
30
        rel = from_super.req_as("standard_relation", str)
31
        pchembl = from_super.req_as("pchembl_value", float)
32
        truth = self._truth(pchembl, rel)
33
        source = self._format_source(
34
            src_id=from_super.req_as("src_id", str),
35
            taxon_id=from_super.get("taxon_id"),
36
            taxon_name=from_super.get("taxon_name"),
37
        )
38
        predicate = self._format_predicate(
39
            src_id=from_super.req_as("src_id", str),
40
            taxon_id=from_super.get("taxon_id"),
41
            taxon_name=from_super.get("taxon_name"),
42
            truth=truth,
43
            rel=rel,
44
        )
45
        hit = self._create_hit(
46
            c_origin=lookup,
47
            c_matched=compound.inchikey,
48
            c_id=compound.chid,
49
            c_name=compound.name,
50
            data_source=source,
51
            predicate=predicate,
52
            object_id=best_target.chembl,
53
            object_name=best_target.name,
54
            record_id=from_super.req_as("activity_id", str),
55
            exact_target_id=from_super.req_as("target_chembl_id", str),
56
            taxon_id=from_super.get("taxon_id"),
57
            taxon_name=from_super.get("taxon_name"),
58
            src_id=from_super.req_as("src_id", str),
59
            pchembl=pchembl,
60
            std_type=from_super.req_as("standard_type", str),
61
            standard_relation=rel,
62
        )
63
        return [hit]
64
65
    def _truth(self, pchembl: float, rel: str) -> str:
66
        if (
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
67
            self.binds_cutoff is not None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
68
            and pchembl >= self.binds_cutoff
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
69
            and rel in {"=", "~", "<", "<="}
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
70
        ):
71
            return "yes"
72
        elif (
73
            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...
74
            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...
75
            and rel in {"=", "~", ">", ">="}
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
76
        ):
77
            return "no"
78
        return rel
79
80
81
__all__ = ["BindingSearch"]
82