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

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