Passed
Push — main ( bfa577...eb6882 )
by Douglas
04:37
created

tests.model.test_pubchem_api.TestPubchemApi.test()   B

Complexity

Conditions 1

Size

Total Lines 230
Code Lines 192

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 192
nop 1
dl 0
loc 230
rs 7
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
from datetime import date
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from pathlib import Path
3
4
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
5
6
from mandos.model.pubchem_api import CachingPubchemApi
7
from mandos.model.pubchem_support.pubchem_models import (
8
    Codes,
9
    CoOccurrenceType,
10
    AtcCode,
11
    CompoundGeneInteraction,
12
    DrugbankDdi,
13
    DrugGeneInteraction,
14
    CoOccurrence,
15
    Activity,
16
    AssayType,
17
    Bioactivity,
18
)
19
20
21
class TestPubchemData:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
22
    def test(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
23
        pass  # nav = PubchemData()
24
25
26
class TestPubchemApi:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
27
    def test(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
introduced by
Missing function or method docstring
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
28
        path = Path(__file__).parent / "resources" / "pchem_store"
29
        querier = CachingPubchemApi(path, None, compress=False)
30
        x = querier.fetch_data("PIQVDUKEQYOJNR-VZXSFKIWSA-N")
0 ignored issues
show
Coding Style Naming introduced by
Variable name "x" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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
        assert tox.acute_effects == frozenset(
91
            {
92
                "an effect",
93
                "behavioral: convulsions or effect on seizure threshold",
94
                "behavioral: excitement",
95
            }
96
        )
97
        lit = x.literature
98
        chem_co = lit.chemical_cooccurrences
99
        assert frozenset([c.strip_pubs() for c in chem_co]) == frozenset(
100
            {
101
                CoOccurrence(
102
                    neighbor_id="681",
103
                    neighbor_name="Dopamine",
104
                    kind=CoOccurrenceType.chemical,
105
                    article_count=4991,
106
                    query_article_count=37869,
107
                    neighbor_article_count=104868,
108
                    score=144197,
109
                    publications=frozenset(),
110
                )
111
            }
112
        )
113
        # TODO: test pubs
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
114
        gene_co = lit.gene_cooccurrences
115
        assert frozenset([c.strip_pubs() for c in gene_co]) == frozenset(
116
            {
117
                CoOccurrence(
118
                    neighbor_id="slc6a3",
119
                    neighbor_name="solute carrier family 6 member 3",
120
                    kind=CoOccurrenceType.gene,
121
                    article_count=1142,
122
                    query_article_count=9031,
123
                    neighbor_article_count=6295,
124
                    score=49087,
125
                    publications=frozenset(),
126
                )
127
            }
128
        )
129
        disease_co = lit.disease_cooccurrences
130
        assert frozenset([c.strip_pubs() for c in disease_co]) == frozenset(
131
            {
132
                CoOccurrence(
133
                    neighbor_id="D010146",
134
                    neighbor_name="Pain",
135
                    kind=CoOccurrenceType.disease,
136
                    article_count=524,
137
                    query_article_count=24423,
138
                    neighbor_article_count=159582,
139
                    score=12499,
140
                    publications=frozenset(),
141
                ),
142
                CoOccurrence(
143
                    neighbor_id="D019966",
144
                    neighbor_name="Substance-Related Disorders",
145
                    kind=CoOccurrenceType.disease,
146
                    article_count=8944,
147
                    query_article_count=24423,
148
                    neighbor_article_count=43314,
149
                    score=287471,
150
                    publications=frozenset(),
151
                ),
152
            }
153
        )
154
        bio = x.biomolecular_interactions_and_pathways
155
        assert bio.drug_gene_interactions == frozenset(
156
            {
157
                DrugGeneInteraction(
158
                    gene_name="OPRK1",
159
                    gene_claim_id="P41145",
160
                    source="TdgClinicalTrial",
161
                    interactions=frozenset(),
162
                    pmids=frozenset(),
163
                    dois=frozenset(),
164
                ),
165
                DrugGeneInteraction(
166
                    gene_name="DRD3",
167
                    gene_claim_id="P35462",
168
                    source="TEND",
169
                    interactions=frozenset(),
170
                    pmids=frozenset(),
171
                    dois=frozenset(),
172
                ),
173
                DrugGeneInteraction(
174
                    gene_name="SCN1A",
175
                    gene_claim_id="BE0004901",
176
                    source="DrugBank",
177
                    interactions=frozenset({"inhibitor"}),
178
                    pmids=frozenset({Codes.PubmedId("9876137"), Codes.PubmedId("2155033")}),
179
                    dois=frozenset(
180
                        {
181
                            Codes.Doi("10.1016/s0006-3495(90)82574-1"),
182
                            Codes.Doi("10.1016/s0006-3495(99)77192-4"),
183
                        }
184
                    ),
185
                ),
186
                DrugGeneInteraction(
187
                    gene_name="CNR1",
188
                    gene_claim_id="CNR1",
189
                    source="PharmGKB",
190
                    interactions=frozenset(),
191
                    pmids=frozenset(),
192
                    dois=frozenset(),
193
                ),
194
            }
195
        )
196
        assert bio.compound_gene_interactions == frozenset(
197
            {
198
                CompoundGeneInteraction(
199
                    gene_name=Codes.GeneId("CHRNB2"),
200
                    interactions=frozenset(
201
                        {"CHRNB2 protein results in increased susceptibility to Cocaine"}
202
                    ),
203
                    tax_name="Mus musculus",
204
                    pmids=frozenset(),
205
                ),
206
                CompoundGeneInteraction(
207
                    gene_name=Codes.GeneId("CHURC1"),
208
                    interactions=frozenset(
209
                        {"Cocaine results in decreased expression of CHURC1 mRNA"}
210
                    ),
211
                    tax_name="Homo sapiens",
212
                    pmids=frozenset({Codes.PubmedId("16710320"), Codes.PubmedId("15009677")}),
213
                ),
214
            }
215
        )
216
        assert bio.drugbank_legal_groups == frozenset({"approved", "illicit"})
217
        assert bio.drugbank_ddis == frozenset(
218
            {
219
                DrugbankDdi(
220
                    drug_drugbank_id=Codes.DrugbankCompoundId("DB00007"),
221
                    drug_pubchem_id=Codes.PubchemCompoundId("657181"),
222
                    drug_drugbank_name="Leuprolide",
223
                    description="The risk or severity of QTc prolongation.",
224
                )
225
            }
226
        )
227
        test = x.biological_test_results
228
        assert test.bioactivity == frozenset(
229
            {
230
                Bioactivity(
231
                    assay_id=127361,
232
                    assay_type=AssayType.confirmatory,
233
                    assay_ref="ChEMBL",
234
                    assay_name="Binding affinity towards human monoclonal antibody 2E2 using [3H]cocaine",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
235
                    assay_made_date=date(2018, 9, 8),
236
                    gene_id=None,
237
                    tax_id=None,
238
                    pmid=Codes.PubmedId("14695827"),
239
                    activity=Activity.active,
240
                    activity_name="Ki",
241
                    activity_value=0.0035,
242
                    target_name=None,
243
                ),
244
                Bioactivity(
245
                    assay_id=127359,
246
                    assay_type=AssayType.confirmatory,
247
                    assay_ref="ChEMBL",
248
                    assay_name="Dissociation Constant for human monoclonal antibody 2E2 with [3H]cocaine",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
249
                    assay_made_date=date(2018, 9, 8),
250
                    gene_id=None,
251
                    tax_id=None,
252
                    pmid=Codes.PubmedId("14695827"),
253
                    activity=Activity.active,
254
                    activity_name="Kd",
255
                    activity_value=0.0044,
256
                    target_name=None,
257
                ),
258
            }
259
        )
260
261
262
if __name__ == "__main__":
263
    pytest.main()
264