1
|
|
|
from dataclasses import dataclass |
|
|
|
|
2
|
|
|
from typing import Sequence, Set, Optional |
|
|
|
|
3
|
|
|
|
4
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
5
|
|
|
|
6
|
|
|
from mandos import logger |
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._protein_search import ProteinHit, ProteinSearch |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
15
|
|
|
class MechanismHit(ProteinHit): |
16
|
|
|
""" |
17
|
|
|
A mechanism entry for a compound. |
18
|
|
|
""" |
19
|
|
|
|
20
|
|
|
action_type: str |
21
|
|
|
direct_interaction: bool |
22
|
|
|
description: str |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
class MechanismSearch(ProteinSearch[MechanismHit]): |
26
|
|
|
""" |
27
|
|
|
Search for ``mechanisms``. |
28
|
|
|
""" |
29
|
|
|
|
30
|
|
|
@property |
31
|
|
|
def data_source(self) -> str: |
|
|
|
|
32
|
|
|
return "ChEMBL :: mechanisms" |
33
|
|
|
|
34
|
|
|
def query(self, parent_form: ChemblCompound) -> Sequence[NestedDotDict]: |
|
|
|
|
35
|
|
|
return list(self.api.mechanism.filter(parent_molecule_chembl_id=parent_form.chid)) |
36
|
|
|
|
37
|
|
|
def should_include( |
|
|
|
|
38
|
|
|
self, lookup: str, compound: ChemblCompound, data: NestedDotDict, target: ChemblTargetGraph |
|
|
|
|
39
|
|
|
) -> bool: |
40
|
|
|
if target.type.name.lower() not in {s.lower() for s in self.allowed_target_types}: |
41
|
|
|
logger.warning(f"Excluding {target.name} with type {target.type}") |
42
|
|
|
return False |
43
|
|
|
return True |
44
|
|
|
|
45
|
|
|
def to_hit( |
|
|
|
|
46
|
|
|
self, |
|
|
|
|
47
|
|
|
lookup: str, |
|
|
|
|
48
|
|
|
compound: ChemblCompound, |
|
|
|
|
49
|
|
|
data: NestedDotDict, |
|
|
|
|
50
|
|
|
best_target: ChemblTargetGraph, |
|
|
|
|
51
|
|
|
) -> Sequence[MechanismHit]: |
52
|
|
|
# these must match the constructor of the Hit, |
53
|
|
|
# EXCEPT for object_id and object_name, which come from traversal |
54
|
|
|
predicate = data.req_as("action_type", str) + " of" |
55
|
|
|
x = MechanismHit( |
|
|
|
|
56
|
|
|
record_id=data["mec_id"], |
57
|
|
|
origin_inchikey=lookup, |
58
|
|
|
matched_inchikey=compound.inchikey, |
59
|
|
|
compound_id=compound.chid, |
60
|
|
|
compound_name=compound.name, |
61
|
|
|
predicate=predicate, |
62
|
|
|
object_id=best_target.chembl, |
63
|
|
|
object_name=best_target.name, |
64
|
|
|
search_key=self.key, |
65
|
|
|
search_class=self.search_class, |
66
|
|
|
data_source=self.data_source, |
67
|
|
|
exact_target_id=data.req_as("target_chembl_id", str), |
68
|
|
|
action_type=data.req_as("action_type", str), |
69
|
|
|
direct_interaction=data.req_as("direct_interaction", bool), |
70
|
|
|
description=data.req_as("mechanism_of_action", str), |
71
|
|
|
) |
72
|
|
|
return [x] |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
__all__ = ["MechanismHit", "MechanismSearch"] |
76
|
|
|
|