1
|
|
|
from dataclasses import dataclass |
|
|
|
|
2
|
|
|
from typing import Optional, Sequence, Set, Tuple |
|
|
|
|
3
|
|
|
|
4
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
5
|
|
|
|
6
|
|
|
from mandos.model import MiscUtils |
|
|
|
|
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: |
|
|
|
|
30
|
|
|
return "ChEMBL :: binding activity" |
31
|
|
|
|
32
|
|
|
@classmethod |
33
|
|
|
def allowed_assay_types(cls) -> Set[str]: |
|
|
|
|
34
|
|
|
return {"B"} |
35
|
|
|
|
36
|
|
|
def to_hit( |
|
|
|
|
37
|
|
|
self, |
|
|
|
|
38
|
|
|
lookup: str, |
|
|
|
|
39
|
|
|
compound: ChemblCompound, |
|
|
|
|
40
|
|
|
data: NestedDotDict, |
|
|
|
|
41
|
|
|
best_target: ChemblTargetGraph, |
|
|
|
|
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 |
|
|
|
|
72
|
|
|
and pchembl >= self.binds_cutoff |
|
|
|
|
73
|
|
|
and rel in {"=", "~", "<", "<="} |
|
|
|
|
74
|
|
|
): |
75
|
|
|
return "binding:yes", "binds" |
76
|
|
|
if ( |
77
|
|
|
self.does_not_bind_cutoff is not None |
|
|
|
|
78
|
|
|
and pchembl <= self.does_not_bind_cutoff |
|
|
|
|
79
|
|
|
and rel in {"=", "~", ">", ">="} |
|
|
|
|
80
|
|
|
): |
81
|
|
|
return "binding:no", "does not bind" |
82
|
|
|
return f"binding:{rel}", f"binding {rel}" |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
__all__ = ["BindingHit", "BindingSearch"] |
86
|
|
|
|