1
|
|
|
from typing import Sequence, Set |
|
|
|
|
2
|
|
|
|
3
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
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]: |
|
|
|
|
18
|
|
|
return {"B"} |
19
|
|
|
|
20
|
|
|
def to_hit( |
|
|
|
|
21
|
|
|
self, |
|
|
|
|
22
|
|
|
lookup: str, |
|
|
|
|
23
|
|
|
compound: ChemblCompound, |
|
|
|
|
24
|
|
|
data: NestedDotDict, |
|
|
|
|
25
|
|
|
best_target: ChemblTargetGraph, |
|
|
|
|
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 ( |
|
|
|
|
67
|
|
|
self.binds_cutoff is not None |
|
|
|
|
68
|
|
|
and pchembl >= self.binds_cutoff |
|
|
|
|
69
|
|
|
and rel in {"=", "~", "<", "<="} |
|
|
|
|
70
|
|
|
): |
71
|
|
|
return "yes" |
72
|
|
|
elif ( |
73
|
|
|
self.does_not_bind_cutoff is not None |
|
|
|
|
74
|
|
|
and pchembl <= self.does_not_bind_cutoff |
|
|
|
|
75
|
|
|
and rel in {"=", "~", ">", ">="} |
|
|
|
|
76
|
|
|
): |
77
|
|
|
return "no" |
78
|
|
|
return rel |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
__all__ = ["BindingSearch"] |
82
|
|
|
|