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.model.chembl_api import ChemblApi |
|
|
|
|
8
|
|
|
from mandos.model.chembl_support import ChemblCompound |
9
|
|
|
from mandos.model.chembl_support.chembl_target_graphs import ChemblTargetGraph |
10
|
|
|
from mandos.model.taxonomy import Taxonomy |
|
|
|
|
11
|
|
|
from mandos.search.chembl._activity_search import _ActivitySearch, _ActivityHit |
12
|
|
|
from mandos.search.chembl._protein_search import ProteinHit, ProteinSearch |
|
|
|
|
13
|
|
|
|
14
|
|
|
logger = logging.getLogger("mandos") |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
18
|
|
|
class BindingHit(_ActivityHit): |
19
|
|
|
""" |
20
|
|
|
An "activity" hit for a compound. |
21
|
|
|
""" |
22
|
|
|
|
23
|
|
|
pchembl: float |
24
|
|
|
std_type: str |
25
|
|
|
standard_relation: str |
26
|
|
|
|
27
|
|
|
@property |
28
|
|
|
def predicate(self) -> str: |
|
|
|
|
29
|
|
|
return "activity" |
30
|
|
|
|
31
|
|
|
|
32
|
|
View Code Duplication |
class BindingSearch(_ActivitySearch[BindingHit]): |
|
|
|
|
33
|
|
|
""" |
34
|
|
|
Search for ``activity`` of type "B". |
35
|
|
|
""" |
36
|
|
|
|
37
|
|
|
@classmethod |
38
|
|
|
def allowed_assay_types(cls) -> Set[str]: |
|
|
|
|
39
|
|
|
return {"B"} |
40
|
|
|
|
41
|
|
|
def to_hit( |
|
|
|
|
42
|
|
|
self, |
|
|
|
|
43
|
|
|
lookup: str, |
|
|
|
|
44
|
|
|
compound: ChemblCompound, |
|
|
|
|
45
|
|
|
data: NestedDotDict, |
|
|
|
|
46
|
|
|
best_target: ChemblTargetGraph, |
|
|
|
|
47
|
|
|
) -> Sequence[BindingHit]: |
48
|
|
|
# these must match the constructor of the Hit, |
49
|
|
|
# EXCEPT for object_id and object_name, which come from traversal |
50
|
|
|
from_super = self._extract(lookup, compound, data) |
51
|
|
|
hit = BindingHit( |
52
|
|
|
record_id=from_super.req_as("activity_id", str), |
53
|
|
|
origin_inchikey=lookup, |
54
|
|
|
matched_inchikey=compound.inchikey, |
55
|
|
|
compound_id=compound.chid, |
56
|
|
|
compound_name=compound.name, |
57
|
|
|
predicate="binds", |
58
|
|
|
object_id=best_target.chembl, |
59
|
|
|
object_name=best_target.name, |
60
|
|
|
search_key=self.key, |
61
|
|
|
search_class=self.search_class, |
62
|
|
|
data_source=self.data_source, |
63
|
|
|
exact_target_id=from_super.req_as("target_chembl_id", str), |
64
|
|
|
taxon_id=from_super.get("taxon_id"), |
65
|
|
|
taxon_name=from_super.get("taxon_name"), |
66
|
|
|
src_id=from_super.req_as("src_id", str), |
67
|
|
|
pchembl=from_super.req_as("pchembl_value", float), |
68
|
|
|
std_type=from_super.req_as("standard_type", str), |
69
|
|
|
standard_relation=from_super.req_as("standard_relation", str), |
70
|
|
|
) |
71
|
|
|
return [hit] |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
__all__ = ["BindingHit", "BindingSearch"] |
75
|
|
|
|