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