1
|
|
|
from datetime import date |
|
|
|
|
2
|
|
|
|
3
|
|
|
import pytest |
|
|
|
|
4
|
|
|
|
5
|
|
|
from mandos.model.apis.caching_pubchem_api import CachingPubchemApi |
6
|
|
|
from mandos.model.apis.pubchem_support.pubchem_models import ( |
7
|
|
|
Activity, |
8
|
|
|
AcuteEffectEntry, |
9
|
|
|
AtcCode, |
10
|
|
|
Bioactivity, |
11
|
|
|
ChemicalGeneInteraction, |
12
|
|
|
Codes, |
13
|
|
|
CoOccurrence, |
14
|
|
|
CoOccurrenceType, |
15
|
|
|
DrugbankDdi, |
16
|
|
|
DrugGeneInteraction, |
17
|
|
|
) |
18
|
|
|
from tests import get_test_resource |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class TestPubchemData: |
|
|
|
|
22
|
|
|
def test(self): |
|
|
|
|
23
|
|
|
pass # nav = PubchemData() |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class TestPubchemApi: |
|
|
|
|
27
|
|
|
def test(self): |
|
|
|
|
28
|
|
|
path = get_test_resource("pchem_store") |
29
|
|
|
querier = CachingPubchemApi(path, None, compress=False) |
30
|
|
|
x = querier.fetch_data("PIQVDUKEQYOJNR-VZXSFKIWSA-N") |
|
|
|
|
31
|
|
|
assert x.cid == 446220 |
32
|
|
|
assert x.parent_or_self == 446220 |
33
|
|
|
title = x.title_and_summary |
34
|
|
|
assert title.safety is not None |
35
|
|
|
assert title.safety == {"Irritant", "Acute Toxic"} |
36
|
|
|
props = x.chemical_and_physical_properties |
37
|
|
|
assert props.computed is not None |
38
|
|
|
assert 0 < len(props.computed) < 40 |
39
|
|
|
drug = x.drug_and_medication_information |
40
|
|
|
assert drug.indication_summary_drugbank == "Cocaine has indications." |
41
|
|
|
assert drug.livertox_classes == {"Central Nervous System Stimulants"} |
42
|
|
|
assert drug.indication_summary_livertox == "Cocaine is a benzoid acid ester." |
43
|
|
|
# assert drug.clinical_trials == set() |
44
|
|
|
pharm = x.pharmacology_and_biochemistry |
45
|
|
|
assert ( |
46
|
|
|
pharm.summary_drugbank_text |
47
|
|
|
== "From DrugBank Pharmacology: Cocaine is a local anesthetic." |
48
|
|
|
) |
49
|
|
|
assert pharm.summary_ncit_text == "From NCIt: Cocaine is a tropane alkaloid." |
50
|
|
|
assert pharm.summary_ncit_links == frozenset({"cocaineish", "somencitthing"}) |
51
|
|
|
assert pharm.mesh == frozenset( |
52
|
|
|
{"Dopamine Uptake Inhibitors", "Anesthetics, Local", "Vasoconstrictor Agents"} |
53
|
|
|
) |
54
|
|
|
assert pharm.atc == frozenset( |
55
|
|
|
{ |
56
|
|
|
AtcCode(code="S02D", name="Other otologicals"), |
57
|
|
|
AtcCode(code="R02A", name="Throat preparations"), |
58
|
|
|
AtcCode(code="N01BC01", name="Cocaine"), |
59
|
|
|
AtcCode(code="R", name="Respiratory system"), |
60
|
|
|
AtcCode(code="R02AD", name="Anesthetics, local"), |
61
|
|
|
AtcCode(code="R02", name="Throat preparations"), |
62
|
|
|
AtcCode(code="R02AD03", name="Cocaine"), |
63
|
|
|
AtcCode(code="S01", name="Ophthalmologicals"), |
64
|
|
|
AtcCode(code="S02DA", name="Analgesics and anesthetics"), |
65
|
|
|
AtcCode(code="N01B", name="Anesthetics, local"), |
66
|
|
|
AtcCode(code="S01HA", name="Local anesthetics"), |
67
|
|
|
AtcCode(code="N01BC", name="Esters of benzoic acid"), |
68
|
|
|
AtcCode(code="S02DA02", name="Cocaine"), |
69
|
|
|
AtcCode(code="N", name="Nervous system"), |
70
|
|
|
AtcCode(code="S01HA01", name="Cocaine"), |
71
|
|
|
AtcCode(code="S", name="Sensory organs"), |
72
|
|
|
AtcCode(code="S02", name="Otologicals"), |
73
|
|
|
AtcCode(code="S01H", name="Local anesthetics"), |
74
|
|
|
AtcCode(code="N01", name="Anesthetics"), |
75
|
|
|
} |
76
|
|
|
) |
77
|
|
|
assert pharm.moa_summary_drugbank_links == frozenset({"drugbankmoacocaine"}) |
78
|
|
|
assert pharm.moa_summary_drugbank_text == "From DrugBank MOA: Cocaine anesthesia." |
79
|
|
|
assert pharm.moa_summary_hsdb_links == frozenset( |
80
|
|
|
{"fromhsdb:jwh133", "fromhsdb: hydrochloride"} |
81
|
|
|
) |
82
|
|
|
assert ( |
83
|
|
|
pharm.moa_summary_hsdb_text |
84
|
|
|
== "From HSDB / lit: Cocaine is something. /// And something else." |
85
|
|
|
) |
86
|
|
|
assert pharm.biochem_reactions == frozenset({"Metabolism", "Biological oxidations"}) |
87
|
|
|
safety = x.safety_and_hazards |
88
|
|
|
assert {g.code for g in safety.ghs_codes} == {"H311", "H301"} |
89
|
|
|
tox = x.toxicity |
90
|
|
|
acute_effects = sorted(list(tox.acute_effects), key=lambda e: e.gid) |
91
|
|
|
assert acute_effects == [ |
92
|
|
|
AcuteEffectEntry( |
93
|
|
|
gid=67674952, |
94
|
|
|
effects=frozenset(), |
95
|
|
|
organism=Codes.ChemIdPlusOrganism("mouse"), |
96
|
|
|
test_type="LD50", |
97
|
|
|
route="subcutaneous", |
98
|
|
|
dose="250 mg/kg (250 mg/kg)", |
99
|
|
|
), |
100
|
|
|
AcuteEffectEntry( |
101
|
|
|
gid=67674953, |
102
|
|
|
effects=frozenset({Codes.ChemIdPlusEffect("an effect: a sub-effect")}), |
103
|
|
|
organism=Codes.ChemIdPlusOrganism("infant"), |
104
|
|
|
test_type="LD50", |
105
|
|
|
route="intravenous", |
106
|
|
|
dose="17500 ug/kg (17.5 mg/kg)", |
107
|
|
|
), |
108
|
|
|
AcuteEffectEntry( |
109
|
|
|
gid=67674954, |
110
|
|
|
effects=frozenset( |
111
|
|
|
{ |
112
|
|
|
Codes.ChemIdPlusEffect("BEHAVIORAL: EXCITEMENT"), |
113
|
|
|
Codes.ChemIdPlusEffect( |
114
|
|
|
"BEHAVIORAL: CONVULSIONS OR EFFECT ON SEIZURE THRESHOLD" |
115
|
|
|
), |
116
|
|
|
} |
117
|
|
|
), |
118
|
|
|
organism=Codes.ChemIdPlusOrganism("women"), |
119
|
|
|
test_type="LD50", |
120
|
|
|
route="oral", |
121
|
|
|
dose="99 mg/kg (99 mg/kg)", |
122
|
|
|
), |
123
|
|
|
] |
124
|
|
|
assert acute_effects[0].mg_per_kg == 250.0 |
125
|
|
|
assert acute_effects[1].mg_per_kg == 17.5 |
126
|
|
|
assert acute_effects[2].mg_per_kg == 99.0 |
127
|
|
|
effect2_codes = list(sorted(acute_effects[2].effects)) |
128
|
|
|
assert effect2_codes[0].category == "BEHAVIORAL" |
129
|
|
|
assert effect2_codes[0].subcategory == "CONVULSIONS OR EFFECT ON SEIZURE THRESHOLD" |
130
|
|
|
assert effect2_codes[1].category == "BEHAVIORAL" |
131
|
|
|
assert effect2_codes[1].subcategory == "EXCITEMENT" |
132
|
|
|
assert not acute_effects[0].organism.is_human |
133
|
|
|
assert acute_effects[1].organism.is_human # "infant" |
134
|
|
|
assert acute_effects[2].organism.is_human # "women" |
135
|
|
|
lit = x.literature |
136
|
|
|
chem_co = lit.chemical_cooccurrences |
137
|
|
|
assert frozenset([c.strip_pubs() for c in chem_co]) == frozenset( |
138
|
|
|
{ |
139
|
|
|
CoOccurrence( |
140
|
|
|
neighbor_id="681", |
141
|
|
|
neighbor_name="Dopamine", |
142
|
|
|
kind=CoOccurrenceType.chemical, |
143
|
|
|
article_count=4991, |
144
|
|
|
query_article_count=37869, |
145
|
|
|
neighbor_article_count=104868, |
146
|
|
|
score=144197, |
147
|
|
|
publications=frozenset(), |
148
|
|
|
) |
149
|
|
|
} |
150
|
|
|
) |
151
|
|
|
# TODO: test pubs |
|
|
|
|
152
|
|
|
gene_co = lit.gene_cooccurrences |
153
|
|
|
assert frozenset([c.strip_pubs() for c in gene_co]) == frozenset( |
154
|
|
|
{ |
155
|
|
|
CoOccurrence( |
156
|
|
|
neighbor_id="slc6a3", |
157
|
|
|
neighbor_name="solute carrier family 6 member 3", |
158
|
|
|
kind=CoOccurrenceType.gene, |
159
|
|
|
article_count=1142, |
160
|
|
|
query_article_count=9031, |
161
|
|
|
neighbor_article_count=6295, |
162
|
|
|
score=49087, |
163
|
|
|
publications=frozenset(), |
164
|
|
|
) |
165
|
|
|
} |
166
|
|
|
) |
167
|
|
|
disease_co = lit.disease_cooccurrences |
168
|
|
|
assert frozenset([c.strip_pubs() for c in disease_co]) == frozenset( |
169
|
|
|
{ |
170
|
|
|
CoOccurrence( |
171
|
|
|
neighbor_id="D010146", |
172
|
|
|
neighbor_name="Pain", |
173
|
|
|
kind=CoOccurrenceType.disease, |
174
|
|
|
article_count=524, |
175
|
|
|
query_article_count=24423, |
176
|
|
|
neighbor_article_count=159582, |
177
|
|
|
score=12499, |
178
|
|
|
publications=frozenset(), |
179
|
|
|
), |
180
|
|
|
CoOccurrence( |
181
|
|
|
neighbor_id="D019966", |
182
|
|
|
neighbor_name="Substance-Related Disorders", |
183
|
|
|
kind=CoOccurrenceType.disease, |
184
|
|
|
article_count=8944, |
185
|
|
|
query_article_count=24423, |
186
|
|
|
neighbor_article_count=43314, |
187
|
|
|
score=287471, |
188
|
|
|
publications=frozenset(), |
189
|
|
|
), |
190
|
|
|
} |
191
|
|
|
) |
192
|
|
|
bio = x.biomolecular_interactions_and_pathways |
193
|
|
|
assert bio.drug_gene_interactions == frozenset( |
194
|
|
|
{ |
195
|
|
|
DrugGeneInteraction( |
196
|
|
|
gene_name="OPRK1", |
197
|
|
|
gene_claim_id="P41145", |
198
|
|
|
source="TdgClinicalTrial", |
199
|
|
|
interactions=frozenset(), |
200
|
|
|
pmids=frozenset(), |
201
|
|
|
dois=frozenset(), |
202
|
|
|
), |
203
|
|
|
DrugGeneInteraction( |
204
|
|
|
gene_name="DRD3", |
205
|
|
|
gene_claim_id="P35462", |
206
|
|
|
source="TEND", |
207
|
|
|
interactions=frozenset(), |
208
|
|
|
pmids=frozenset(), |
209
|
|
|
dois=frozenset(), |
210
|
|
|
), |
211
|
|
|
DrugGeneInteraction( |
212
|
|
|
gene_name="SCN1A", |
213
|
|
|
gene_claim_id="BE0004901", |
214
|
|
|
source="DrugBank", |
215
|
|
|
interactions=frozenset({"inhibitor"}), |
216
|
|
|
pmids=frozenset({Codes.PubmedId("9876137"), Codes.PubmedId("2155033")}), |
217
|
|
|
dois=frozenset( |
218
|
|
|
{ |
219
|
|
|
Codes.Doi("10.1016/s0006-3495(90)82574-1"), |
220
|
|
|
Codes.Doi("10.1016/s0006-3495(99)77192-4"), |
221
|
|
|
} |
222
|
|
|
), |
223
|
|
|
), |
224
|
|
|
DrugGeneInteraction( |
225
|
|
|
gene_name="CNR1", |
226
|
|
|
gene_claim_id="CNR1", |
227
|
|
|
source="PharmGKB", |
228
|
|
|
interactions=frozenset(), |
229
|
|
|
pmids=frozenset(), |
230
|
|
|
dois=frozenset(), |
231
|
|
|
), |
232
|
|
|
} |
233
|
|
|
) |
234
|
|
|
assert bio.chemical_gene_interactions == frozenset( |
235
|
|
|
{ |
236
|
|
|
ChemicalGeneInteraction( |
237
|
|
|
gene_name=Codes.GeneId("CHRNB2"), |
238
|
|
|
interactions=frozenset( |
239
|
|
|
{"CHRNB2 protein results in increased susceptibility to Cocaine"} |
240
|
|
|
), |
241
|
|
|
tax_id=10090, |
242
|
|
|
tax_name="Mus musculus", |
243
|
|
|
pmids=frozenset(), |
244
|
|
|
), |
245
|
|
|
ChemicalGeneInteraction( |
246
|
|
|
gene_name=Codes.GeneId("CHURC1"), |
247
|
|
|
interactions=frozenset( |
248
|
|
|
{"Cocaine results in decreased expression of CHURC1 mRNA"} |
249
|
|
|
), |
250
|
|
|
tax_id=9606, |
251
|
|
|
tax_name="Homo sapiens", |
252
|
|
|
pmids=frozenset({Codes.PubmedId("16710320"), Codes.PubmedId("15009677")}), |
253
|
|
|
), |
254
|
|
|
} |
255
|
|
|
) |
256
|
|
|
assert bio.drugbank_legal_groups == frozenset({"approved", "illicit"}) |
257
|
|
|
assert bio.drugbank_ddis == frozenset( |
258
|
|
|
{ |
259
|
|
|
DrugbankDdi( |
260
|
|
|
drug_drugbank_id=Codes.DrugbankCompoundId("DB00007"), |
261
|
|
|
drug_pubchem_id=Codes.PubchemCompoundId("657181"), |
262
|
|
|
drug_drugbank_name="Leuprolide", |
263
|
|
|
description="The risk or severity of QTc prolongation.", |
264
|
|
|
) |
265
|
|
|
} |
266
|
|
|
) |
267
|
|
|
test = x.biological_test_results |
268
|
|
|
assert test.bioactivity == frozenset( |
269
|
|
|
{ |
270
|
|
|
Bioactivity( |
271
|
|
|
assay_id=127361, |
272
|
|
|
assay_type="confirmatory", |
273
|
|
|
assay_ref="ChEMBL", |
274
|
|
|
assay_name="Binding affinity towards human monoclonal antibody 2E2 using [3H]cocaine", |
|
|
|
|
275
|
|
|
assay_made_date=date(2018, 9, 8), |
276
|
|
|
gene_id=None, |
277
|
|
|
tax_id=None, |
278
|
|
|
pmid=Codes.PubmedId("14695827"), |
279
|
|
|
activity=Activity.active, |
280
|
|
|
activity_name="Ki", |
281
|
|
|
activity_value=0.0035, |
282
|
|
|
target_name=None, |
283
|
|
|
compound_name="Cocaine", |
284
|
|
|
), |
285
|
|
|
Bioactivity( |
286
|
|
|
assay_id=127359, |
287
|
|
|
assay_type="confirmatory", |
288
|
|
|
assay_ref="ChEMBL", |
289
|
|
|
assay_name="Dissociation Constant for human monoclonal antibody 2E2 with [3H]cocaine", |
|
|
|
|
290
|
|
|
assay_made_date=date(2018, 9, 8), |
291
|
|
|
gene_id=None, |
292
|
|
|
tax_id=None, |
293
|
|
|
pmid=Codes.PubmedId("14695827"), |
294
|
|
|
activity=Activity.active, |
295
|
|
|
activity_name="Kd", |
296
|
|
|
activity_value=0.0044, |
297
|
|
|
target_name=None, |
298
|
|
|
compound_name="Cocaine", |
299
|
|
|
), |
300
|
|
|
} |
301
|
|
|
) |
302
|
|
|
|
303
|
|
|
|
304
|
|
|
if __name__ == "__main__": |
305
|
|
|
pytest.main() |
306
|
|
|
|