1
|
|
|
import re |
|
|
|
|
2
|
|
|
from dataclasses import dataclass |
3
|
|
|
from typing import Sequence, Optional |
4
|
|
|
|
5
|
|
|
from mandos.search.pubchem import PubchemHit, PubchemSearch |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
9
|
|
|
class DrugbankDdiHit(PubchemHit): |
10
|
|
|
"""""" |
11
|
|
|
|
12
|
|
|
type: str |
13
|
|
|
effect_target: Optional[str] |
14
|
|
|
change: Optional[str] |
15
|
|
|
description: str |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class DrugbankDdiSearch(PubchemSearch[DrugbankDdiHit]): |
|
|
|
|
19
|
|
|
"""""" |
20
|
|
|
|
21
|
|
|
@property |
22
|
|
|
def data_source(self) -> str: |
|
|
|
|
23
|
|
|
return "DrugBank" |
24
|
|
|
|
25
|
|
|
def find(self, inchikey: str) -> Sequence[DrugbankDdiHit]: |
|
|
|
|
26
|
|
|
data = self.api.fetch_data(inchikey) |
27
|
|
|
hits = [] |
28
|
|
|
for dd in data.biomolecular_interactions_and_pathways.drugbank_ddis: |
|
|
|
|
29
|
|
|
kind = self._guess_type(dd.description) |
30
|
|
|
up_or_down = self._guess_up_down(dd.description) |
31
|
|
|
spec = None |
32
|
|
|
if kind == "risk": |
33
|
|
|
spec = self._guess_adverse(dd.description) |
34
|
|
|
elif kind == "activity": |
35
|
|
|
spec = self._guess_activity(dd.description) |
36
|
|
|
elif kind == "PK": |
37
|
|
|
spec = self._guess_pk(dd.description) |
38
|
|
|
elif kind == "efficacy": |
39
|
|
|
spec = self._guess_efficacy(dd.description) |
40
|
|
|
hits.append( |
41
|
|
|
DrugbankDdiHit( |
42
|
|
|
record_id=None, |
43
|
|
|
origin_inchikey=inchikey, |
44
|
|
|
matched_inchikey=data.names_and_identifiers.inchikey, |
45
|
|
|
compound_id=str(data.cid), |
46
|
|
|
compound_name=data.name, |
47
|
|
|
predicate="has DDI with", |
48
|
|
|
object_id=dd.drug_drugbank_id, |
49
|
|
|
object_name=dd.drug_drugbank_id, |
50
|
|
|
search_key=self.key, |
51
|
|
|
search_class=self.search_class, |
52
|
|
|
data_source=self.data_source, |
53
|
|
|
type=kind, |
54
|
|
|
effect_target=spec, |
55
|
|
|
change=up_or_down, |
56
|
|
|
description=dd.description, |
57
|
|
|
) |
58
|
|
|
) |
59
|
|
|
return hits |
60
|
|
|
|
61
|
|
|
def _guess_up_down(self, desc: str) -> str: |
|
|
|
|
62
|
|
|
if "increase" in desc: |
|
|
|
|
63
|
|
|
return "increase" |
64
|
|
|
elif "decrease" in desc: |
65
|
|
|
return "decrease" |
66
|
|
|
return "unknown" |
67
|
|
|
|
68
|
|
|
def _guess_efficacy(self, desc: str) -> Optional[str]: |
|
|
|
|
69
|
|
|
match = re.compile("efficacy of (.+)").search(desc) |
70
|
|
|
if match is None or match.group(1) is None: |
71
|
|
|
return None |
72
|
|
|
split = match.group(1).split(" can") |
73
|
|
|
if len(split) != 2: |
74
|
|
|
return None |
75
|
|
|
return split[0].strip() |
76
|
|
|
|
77
|
|
View Code Duplication |
def _guess_activity(self, desc: str) -> Optional[str]: |
|
|
|
|
78
|
|
|
match = re.compile("may increase the (.+)").search(desc) |
79
|
|
|
if match is None or match.group(1) is None: |
80
|
|
|
match = re.compile("may decrease the (.+)").search(desc) |
81
|
|
|
if match is None or match.group(1) is None: |
82
|
|
|
return None |
83
|
|
|
split = re.compile("activities").split(match.group(1)) |
84
|
|
|
if len(split) != 2: |
85
|
|
|
return None |
86
|
|
|
return split[0].strip() |
87
|
|
|
|
88
|
|
View Code Duplication |
def _guess_adverse(self, desc: str) -> Optional[str]: |
|
|
|
|
89
|
|
|
match = re.compile(" risk or severity of (.+)").search(desc) |
90
|
|
|
if match is None or match.group(1) is None: |
91
|
|
|
match = re.compile(" risk of (.+)").search(desc) |
92
|
|
|
if match is None or match.group(1) is None: |
93
|
|
|
return None |
94
|
|
|
split = re.compile(" (?:can)|(?:may) be").split(match.group(1)) |
95
|
|
|
if len(split) != 2: |
96
|
|
|
return None |
97
|
|
|
return split[0].strip() |
98
|
|
|
|
99
|
|
|
def _guess_pk(self, desc: str) -> Optional[str]: |
|
|
|
|
100
|
|
|
match = re.compile("^The (.+)").search(desc) |
101
|
|
|
if match is not None and match.group(1) is not None: |
102
|
|
|
split = re.compile("can be").split(match.group(1)) |
103
|
|
|
if len(split) == 2: |
104
|
|
|
return split[0].strip() |
105
|
|
|
# try another way |
106
|
|
|
match = re.compile("may increase the (.+)").search(desc) |
107
|
|
|
if match is None or match.group(1) is None: |
108
|
|
|
match = re.compile("may decrease the (.+)").search(desc) |
109
|
|
|
if match is None or match.group(1) is None: |
110
|
|
|
return None |
111
|
|
|
split = re.compile("which").split(match.group(1)) |
112
|
|
|
if len(split) != 2: |
113
|
|
|
return None |
114
|
|
|
return split[0].strip() |
115
|
|
|
|
116
|
|
|
def _guess_type(self, desc: str) -> str: |
|
|
|
|
117
|
|
|
for k, v in { |
|
|
|
|
118
|
|
|
"serum concentration": "PK", |
|
|
|
|
119
|
|
|
"metabolism": "PK", |
|
|
|
|
120
|
|
|
"absorption": "PK", |
|
|
|
|
121
|
|
|
"excretion": "PK", |
|
|
|
|
122
|
|
|
"risk": "risk", |
|
|
|
|
123
|
|
|
"severity": "risk", |
|
|
|
|
124
|
|
|
"adverse": "risk", |
|
|
|
|
125
|
|
|
"activities": "activity", |
|
|
|
|
126
|
|
|
"activity": "activity", |
|
|
|
|
127
|
|
|
"efficacy": "efficacy", |
|
|
|
|
128
|
|
|
}.items(): |
129
|
|
|
if k in desc: |
130
|
|
|
return v |
131
|
|
|
return "unknown" |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
__all__ = ["DrugbankDdiHit", "DrugbankDdiSearch"] |
135
|
|
|
|