1
|
|
|
from typing import Optional, Sequence, Set, TypeVar |
|
|
|
|
2
|
|
|
|
3
|
|
|
from mandos.model.apis.pubchem_api import PubchemApi |
4
|
|
|
from mandos.model.apis.pubchem_support.pubchem_models import ( |
5
|
|
|
DrugbankInteraction, |
6
|
|
|
DrugbankTargetType, |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
# noinspection PyProtectedMember |
10
|
|
|
from mandos.model.concrete_hits import ( |
11
|
|
|
DrugbankGeneralFunctionHit, |
12
|
|
|
DrugbankTargetHit, |
13
|
|
|
_DrugbankInteractionHit, |
14
|
|
|
) |
15
|
|
|
from mandos.search.pubchem import PubchemSearch |
16
|
|
|
|
17
|
|
|
T = TypeVar("T", bound=_DrugbankInteractionHit, covariant=True) |
|
|
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
|
# noinspection PyAbstractClass |
21
|
|
|
class _DrugbankInteractionSearch(PubchemSearch[T]): |
22
|
|
|
def __init__(self, key: str, api: PubchemApi, target_types: Set[DrugbankTargetType]): |
23
|
|
|
super().__init__(key, api) |
24
|
|
|
self.target_types = target_types |
25
|
|
|
|
26
|
|
|
@classmethod |
27
|
|
|
def _get_obj(cls, dd: DrugbankInteraction) -> Optional[str]: |
|
|
|
|
28
|
|
|
raise NotImplementedError() |
29
|
|
|
|
30
|
|
|
def find(self, inchikey: str) -> Sequence[T]: |
|
|
|
|
31
|
|
|
data = self.api.fetch_data(inchikey) |
32
|
|
|
results = [] |
33
|
|
|
for dd in data.biomolecular_interactions_and_pathways.drugbank_interactions: |
|
|
|
|
34
|
|
|
if dd.target_type in self.target_types: |
35
|
|
|
source = self._format_source(type=dd.target_type.name) |
36
|
|
|
predicate = self._format_predicate( |
37
|
|
|
type=dd.target_type.name, |
38
|
|
|
action="generic" if dd.action is None else dd.action, |
39
|
|
|
) |
40
|
|
|
obj = self._get_obj(dd) |
41
|
|
|
if obj is not None: |
42
|
|
|
results.append( |
43
|
|
|
self._create_hit( |
44
|
|
|
c_id=str(data.cid), |
45
|
|
|
c_origin=inchikey, |
46
|
|
|
c_matched=data.names_and_identifiers.inchikey, |
47
|
|
|
c_name=data.name, |
48
|
|
|
data_source=source, |
49
|
|
|
predicate=predicate, |
50
|
|
|
object_id=obj, |
51
|
|
|
object_name=obj, |
52
|
|
|
gene_symbol=dd.gene_symbol, |
53
|
|
|
protein_id=dd.protein_id, |
54
|
|
|
target_type=dd.target_type.name, |
55
|
|
|
target_name=dd.target_name, |
56
|
|
|
general_function=dd.general_function, |
57
|
|
|
cache_date=data.names_and_identifiers.modify_date, |
58
|
|
|
) |
59
|
|
|
) |
60
|
|
|
return results |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
class DrugbankTargetSearch(_DrugbankInteractionSearch[DrugbankTargetHit]): |
|
|
|
|
64
|
|
|
""" """ |
65
|
|
|
|
66
|
|
|
@classmethod |
67
|
|
|
def _get_obj(cls, dd: DrugbankInteraction) -> Optional[str]: |
|
|
|
|
68
|
|
|
return dd.target_name |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
class DrugbankGeneralFunctionSearch(_DrugbankInteractionSearch[DrugbankGeneralFunctionHit]): |
|
|
|
|
72
|
|
|
""" """ |
73
|
|
|
|
74
|
|
|
@classmethod |
75
|
|
|
def _get_obj(cls, dd: DrugbankInteraction) -> Optional[str]: |
|
|
|
|
76
|
|
|
return dd.general_function # might be None |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
__all__ = [ |
80
|
|
|
"DrugbankTargetSearch", |
81
|
|
|
"DrugbankGeneralFunctionSearch", |
82
|
|
|
] |
83
|
|
|
|