Passed
Push — dependabot/pip/sphinx-autoapi-... ( 48fb62 )
by
unknown
04:13 queued 01:53
created

mandos.model.pubchem_support.pubchem_models   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 365
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 261
dl 0
loc 365
rs 10
c 0
b 0
f 0
wmc 23

13 Methods

Rating   Name   Duplication   Size   Complexity  
A AtcCode.parts() 0 5 1
A Codes.value() 0 3 1
A AtcCode.level() 0 3 1
A GhsCode.find() 0 11 1
A ClinicalTrial.known_phase() 0 10 1
A Code.of() 0 9 3
A ComputedProperty.req_is() 0 4 2
A CoOccurrenceType.id_name() 0 9 4
A Code.type_name() 0 3 1
A ComputedProperty.as_str() 0 3 1
A CoOccurrenceType.x_name() 0 9 4
A CoOccurrence.strip_pubs() 0 10 1
A GhsCode.level() 0 3 1
1
from __future__ import annotations
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
import enum
3
import re
4
from dataclasses import dataclass
5
from datetime import date
6
from typing import Union, Optional, FrozenSet, Sequence
7
8
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
9
10
from mandos import MandosResources
11
from mandos.model.pubchem_support._nav_fns import Mapx
12
13
hazards = {
14
    d["code"]: d for d in NestedDotDict.read_toml(MandosResources.path("hazards.toml"))["signals"]
15
}
16
17
18
@dataclass(frozen=True, repr=True, eq=True, order=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
19
class ComputedProperty:
20
    key: str
21
    value: Union[int, str, float, bool]
22
    unit: Optional[str]
23
    ref: str
24
25
    def req_is(self, type_) -> Union[int, str, float, bool]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
26
        if not isinstance(self.value, type_):
27
            raise TypeError(f"{self.key}->{self.value} has {type(self.value)}, not {type_}")
28
        return self.value
29
30
    @property
31
    def as_str(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
32
        return f"{self.value} {self.unit}"
33
34
35
class Code(str):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
36
    @property
37
    def type_name(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
38
        return self.__class__.__name__.lower()
39
40
    @classmethod
41
    def of(cls, value: Union[str, int, float]):
0 ignored issues
show
Coding Style Naming introduced by
Method name "of" 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...
introduced by
Missing function or method docstring
Loading history...
42
        if isinstance(value, float):
43
            try:
44
                value = int(value)
45
            except ArithmeticError:
46
                value = str(value)
47
        value = str(value).strip()
48
        return cls(value)
49
50
51
class Codes:
52
    """
53
    These turn out to be extremely useful for documenting return types.
54
    For example, ``DrugbankInteraction`` might have a ``gene`` field,
55
    which can be described as a ``GenecardSymbol`` if known.
56
    """
57
58
    class EcNumber(Code):
59
        """
60
        e.g. 'EC:4.6.1.1'
61
        """
62
63
    class GeneId(Code):
64
        """
65
        GeneCard, UniProt gene name, etc.
66
        e.g. 'slc1a2'
67
        """
68
69
    class GenecardSymbol(GeneId):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
70
        """"""
71
72
    class UniprotId(GeneId):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
73
        """"""
74
75
    class PubchemCompoundId(Code):
76
        """
77
        e.g. 2352
78
        """
79
80
        @property
81
        def value(self) -> int:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
82
            return int(self)
83
84
    class AtcCode(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
85
        """"""
86
87
    class PubmedId(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
88
        """"""
89
90
    class Doi(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
91
        """"""
92
93
    class MeshCode(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
94
        """"""
95
96
    class PdbId(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
97
        """"""
98
99
    class MeshHeading(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
100
        """"""
101
102
    class MeshSubheading(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
103
        """"""
104
105
    class DrugbankCompoundId(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
106
        """"""
107
108
    class DeaSchedule(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
109
        """"""
110
111
        @property
112
        def value(self) -> int:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
113
            return Mapx.roman_to_arabic(1, 5)(self)
114
115
    class GhsCode(Code):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
116
        """"""
117
118
119
class CoOccurrenceType(enum.Enum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
120
    chemical = enum.auto()
121
    gene = enum.auto()
122
    disease = enum.auto()
123
124
    @property
125
    def x_name(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
126
        if self is CoOccurrenceType.chemical:
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
127
            return "ChemicalNeighbor"
128
        elif self is CoOccurrenceType.gene:
129
            return "ChemicalGeneSymbolNeighbor"
130
        elif self is CoOccurrenceType.disease:
131
            return "ChemicalDiseaseNeighbor"
132
        raise AssertionError(f"{self} not found!!")
133
134
    @property
135
    def id_name(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
136
        if self is CoOccurrenceType.chemical:
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
137
            return "CID"
138
        elif self is CoOccurrenceType.gene:
139
            return "GeneSymbol"
140
        elif self is CoOccurrenceType.disease:
141
            return "MeSH"
142
        raise AssertionError(f"{self} not found!!")
143
144
145
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
146
class ClinicalTrial:
147
    title: str
148
    conditions: FrozenSet[str]
149
    phase: str
150
    status: str
151
    interventions: FrozenSet[str]
152
    cids: FrozenSet[Codes.PubchemCompoundId]
153
    source: str
154
155
    @property
156
    def known_phase(self) -> int:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
157
        return {
158
            "Phase 4": 4,
159
            "Phase 3": 3,
160
            "Phase 2": 2,
161
            "Phase 1": 1,
162
            "Early Phase 1": 1,
163
            "N/A": 0,
164
        }.get(self.status, 0)
165
166
167
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
168
class GhsCode:
169
    code: Codes.GhsCode
170
    statement: str
171
    clazz: str
172
    categories: FrozenSet[str]
173
    signal_word: str
174
    type: str
175
176
    @classmethod
177
    def find(cls, code: str) -> GhsCode:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
178
        h = hazards[code]
0 ignored issues
show
Coding Style Naming introduced by
Variable name "h" 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...
179
        cats = h["category"]  # TODO
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
180
        return GhsCode(
181
            code=Codes.GhsCode(code),
182
            statement=h["statement"],
183
            clazz=h["class"],
184
            categories=cats,
185
            signal_word=h["signal_word"],
186
            type=h["type"],
187
        )
188
189
    @property
190
    def level(self) -> int:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
191
        return int(self.code[1])
192
193
194
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
195
class AssociatedDisorder:
196
    disease: str
197
    evidence_type: str
198
    n_refs: int
199
200
201
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
202
class AtcCode:
203
    code: str
204
    name: str
205
206
    @property
207
    def level(self) -> int:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
208
        return len(self.parts)
209
210
    @property
211
    def parts(self) -> Sequence[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
212
        pat = re.compile(r"([A-Z])([0-9]{2})?([A-Z])?([A-Z])?([A-Z])?")
213
        match = pat.fullmatch(self.code)
214
        return [g for g in match.groups() if g is not None]
215
216
217
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
218
class DrugbankInteraction:
219
    gene_symbol: Codes.GeneId
220
    action: str
221
    target_name: str
222
    general_function: Sequence[str]
223
    specific_function: str
224
    pmids: FrozenSet[Codes.PubmedId]
225
    dois: FrozenSet[Codes.Doi]
226
227
228
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
229
class DrugbankDdi:
230
    drug_drugbank_id: Codes.DrugbankCompoundId
231
    drug_pubchem_id: Codes.PubchemCompoundId
232
    drug_drugbank_name: str
233
    description: str
234
235
236
class AssayType(enum.Enum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
237
    confirmatory = enum.auto()
238
    literature = enum.auto()
239
240
241
class Activity(enum.Enum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
242
    active = enum.auto()
243
    inactive = enum.auto()
244
    unspecified = enum.auto()
245
246
247
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
best-practice introduced by
Too many instance attributes (12/7)
Loading history...
248
class Bioactivity:
249
    assay_id: int
250
    assay_type: AssayType
251
    assay_ref: str
252
    assay_name: str
253
    assay_made_date: date
254
    gene_id: Optional[Codes.GeneId]
255
    tax_id: Optional[int]
256
    pmid: Optional[Codes.PubmedId]
257
    activity: Optional[Activity]
258
    activity_name: Optional[str]
259
    activity_value: float
260
    target_name: Optional[str]
261
262
263
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
best-practice introduced by
Too many instance attributes (9/7)
Loading history...
264
class PdbEntry:
265
    pdbid: Codes.PdbId
266
    title: str
267
    exp_method: str
268
    resolution: float
269
    lig_names: FrozenSet[str]
270
    cids: FrozenSet[Codes.PubchemCompoundId]
271
    uniprot_ids: FrozenSet[Codes.UniprotId]
272
    pmids: FrozenSet[Codes.PubmedId]
273
    dois: FrozenSet[Codes.Doi]
274
275
276
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
best-practice introduced by
Too many instance attributes (11/7)
Loading history...
277
class PubmedEntry:
278
    pmid: Codes.PubmedId
279
    article_type: str
280
    pmidsrcs: FrozenSet[str]
281
    mesh_headings: FrozenSet[Codes.MeshHeading]
282
    mesh_subheadings: FrozenSet[Codes.MeshSubheading]
283
    mesh_codes: FrozenSet[Codes.MeshCode]
284
    cids: FrozenSet[Codes.PubchemCompoundId]
285
    article_title: str
286
    article_abstract: str
287
    journal_name: str
288
    pub_date: date
289
290
291
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
292
class Publication:
293
    pmid: Codes.PubmedId
294
    pub_date: date
295
    is_review: bool
296
    title: str
297
    journal: str
298
    relevance_score: int
299
300
301
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
best-practice introduced by
Too many instance attributes (8/7)
Loading history...
302
class CoOccurrence:
303
    neighbor_id: str
304
    neighbor_name: str
305
    kind: CoOccurrenceType
306
    # https://pubchemdocs.ncbi.nlm.nih.gov/knowledge-panels
307
    article_count: int
308
    query_article_count: int
309
    neighbor_article_count: int
310
    score: int
311
    publications: FrozenSet[Publication]
312
313
    def strip_pubs(self) -> CoOccurrence:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
314
        return CoOccurrence(
315
            self.neighbor_id,
316
            self.neighbor_name,
317
            self.kind,
318
            self.article_count,
319
            self.query_article_count,
320
            self.neighbor_article_count,
321
            self.score,
322
            frozenset({}),
323
        )
324
325
326
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
327
class DrugGeneInteraction:
328
    """"""
329
330
    gene_name: Optional[str]
331
    gene_claim_id: Optional[str]
332
    source: str
333
    interactions: FrozenSet[str]
334
    pmids: FrozenSet[Codes.PubmedId]
335
    dois: FrozenSet[Codes.Doi]
336
337
338
@dataclass(frozen=True, repr=True, eq=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
339
class CompoundGeneInteraction:
340
    gene_name: Optional[Codes.GeneId]
341
    interactions: FrozenSet[str]
342
    tax_name: Optional[str]
343
    pmids: FrozenSet[Codes.PubmedId]
344
345
346
__all__ = [
347
    "ClinicalTrial",
348
    "AssociatedDisorder",
349
    "AtcCode",
350
    "AssayType",
351
    "DrugbankInteraction",
352
    "DrugbankDdi",
353
    "Bioactivity",
354
    "Activity",
355
    "DrugGeneInteraction",
356
    "CompoundGeneInteraction",
357
    "GhsCode",
358
    "PubmedEntry",
359
    "Code",
360
    "Codes",
361
    "CoOccurrenceType",
362
    "CoOccurrence",
363
    "Publication",
364
    "ComputedProperty",
365
]
366