Passed
Push — dependabot/pip/flake8-bugbear-... ( 16d864...b4f9fc )
by
unknown
01:45
created

AcuteEffectSearch.find()   A

Complexity

Conditions 4

Size

Total Lines 28
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 26
nop 2
dl 0
loc 28
rs 9.256
c 0
b 0
f 0
1
from dataclasses import dataclass
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from typing import Sequence, Optional
0 ignored issues
show
Unused Code introduced by
Unused Optional imported from typing
Loading history...
3
4
from mandos.model.pubchem_api import PubchemApi
5
from mandos.search.pubchem import PubchemHit, PubchemSearch
6
7
8
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
9
class AcuteEffectHit(PubchemHit):
10
    """"""
11
12
    organism: str
13
    human: bool
14
    test_type: str
15
    route: str
16
    effect: str
17
    mg_per_kg: float
18
19
20
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
21
class Ld50Hit(PubchemHit):
22
    """"""
23
24
    organism: str
25
    human: bool
26
27
28
class AcuteEffectSearch(PubchemSearch[AcuteEffectHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
29
    """"""
30
31
    def __init__(self, key: str, api: PubchemApi, top_level: bool):
32
        super().__init__(key, api)
33
        self.top_level = top_level
34
35
    @property
36
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
37
        return "ChemIDplus"
38
39
    def find(self, inchikey: str) -> Sequence[AcuteEffectHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
40
        data = self.api.fetch_data(inchikey)
41
        results = []
42
        for dd in data.toxicity.acute_effects:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "dd" 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...
43
            for effect in dd.effects:
44
                effect_name = effect.category.lower() if self.top_level else effect.lower()
45
                results.append(
46
                    AcuteEffectHit(
47
                        record_id=str(dd.gid),
48
                        origin_inchikey=inchikey,
49
                        matched_inchikey=data.names_and_identifiers.inchikey,
50
                        compound_id=str(data.cid),
51
                        compound_name=data.name,
52
                        predicate="causes acute effect",
53
                        object_id=effect_name,
54
                        object_name=effect_name,
55
                        search_key=self.key,
56
                        search_class=self.search_class,
57
                        data_source=self.data_source,
58
                        effect=effect.lower(),
59
                        organism=dd.organism,
60
                        human=dd.organism.is_human,
61
                        route=dd.route,
62
                        mg_per_kg=dd.mg_per_kg,
63
                        test_type=dd.test_type,
64
                    )
65
                )
66
        return results
67
68
69
class Ld50Search(PubchemSearch[Ld50Hit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
70
    @property
71
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
72
        return "ChemIDplus"
73
74
    def find(self, inchikey: str) -> Sequence[Ld50Hit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
75
        data = self.api.fetch_data(inchikey)
76
        results = []
77
        for dd in data.toxicity.acute_effects:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "dd" 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...
78
            if dd.test_type != "LD50":
79
                continue
80
            results.append(
81
                Ld50Hit(
82
                    record_id=str(dd.gid),
83
                    origin_inchikey=inchikey,
84
                    matched_inchikey=data.names_and_identifiers.inchikey,
85
                    compound_id=str(data.cid),
86
                    compound_name=data.name,
87
                    predicate="has LD50 for " + dd.organism,
88
                    object_id=str(dd.mg_per_kg),
89
                    object_name=str(dd.mg_per_kg),
90
                    search_key=self.key,
91
                    search_class=self.search_class,
92
                    data_source=self.data_source,
93
                    organism=dd.organism,
94
                    human=dd.organism.is_human,
95
                )
96
            )
97
        return results
98
99
100
__all__ = ["AcuteEffectHit", "AcuteEffectSearch", "Ld50Hit", "Ld50Search"]
101