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