1
|
|
|
import logging |
|
|
|
|
2
|
|
|
from dataclasses import dataclass |
3
|
|
|
from typing import Sequence, Set, Optional |
|
|
|
|
4
|
|
|
|
5
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
6
|
|
|
|
7
|
|
|
from mandos import logger |
|
|
|
|
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: |
|
|
|
|
31
|
|
|
return "ChEMBL :: binding activity" |
32
|
|
|
|
33
|
|
|
@classmethod |
34
|
|
|
def allowed_assay_types(cls) -> Set[str]: |
|
|
|
|
35
|
|
|
return {"B"} |
36
|
|
|
|
37
|
|
|
def to_hit( |
|
|
|
|
38
|
|
|
self, |
|
|
|
|
39
|
|
|
lookup: str, |
|
|
|
|
40
|
|
|
compound: ChemblCompound, |
|
|
|
|
41
|
|
|
data: NestedDotDict, |
|
|
|
|
42
|
|
|
best_target: ChemblTargetGraph, |
|
|
|
|
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 |
|
|
|
|
51
|
|
|
and pchembl >= self.binds_cutoff |
|
|
|
|
52
|
|
|
and rel in {"=", "~", "<", "<="} |
|
|
|
|
53
|
|
|
): |
54
|
|
|
predicate = f"binds" |
|
|
|
|
55
|
|
|
elif ( |
56
|
|
|
self.does_not_bind_cutoff is not None |
|
|
|
|
57
|
|
|
and pchembl <= self.does_not_bind_cutoff |
|
|
|
|
58
|
|
|
and rel in {"=", "~", ">", ">="} |
|
|
|
|
59
|
|
|
): |
60
|
|
|
predicate = f"does not bind" |
|
|
|
|
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
|
|
|
|