Passed
Push — main ( 2e1b6b...3a0c28 )
by Douglas
02:06
created

AcuteEffectSearch.find()   B

Complexity

Conditions 5

Size

Total Lines 46
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 41
nop 2
dl 0
loc 46
rs 8.4293
c 0
b 0
f 0
1
from typing import Sequence
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import numpy as np
0 ignored issues
show
introduced by
Unable to import 'numpy'
Loading history...
Unused Code introduced by
Unused numpy imported as np
Loading history...
4
5
from mandos.model.apis.pubchem_api import PubchemApi
6
from mandos.model.concrete_hits import AcuteEffectHit, Ld50Hit
7
from mandos.model.utils.setup import logger
8
from mandos.search.pubchem import PubchemSearch
9
10
11
class AcuteEffectSearch(PubchemSearch[AcuteEffectHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
12
    """ """
13
14
    def __init__(self, key: str, api: PubchemApi, top_level: bool):
15
        super().__init__(key, api)
16
        self.top_level = top_level
17
18
    def find(self, inchikey: str) -> Sequence[AcuteEffectHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
19
        data = self.api.fetch_data(inchikey)
20
        results = []
21
        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...
22
            for effect in dd.effects:
23
                effect_name = effect.category.lower() if self.top_level else effect.lower()
24
                try:
25
                    weight = -dd.mg_per_kg
26
                except ValueError:
27
                    logger.error(f"Failed to parse {dd.dose} on {inchikey}")
28
                    logger.opt(exception=True).debug(
29
                        f"Failed to parse {dd.dose} on {inchikey}: {dd}"
30
                    )
31
                    continue
32
                source = self._format_source(
33
                    organism=dd.organism,
34
                    human=dd.organism.is_human,
35
                    route=dd.route,
36
                    test_type=dd.test_type,
37
                )
38
                predicate = self._format_predicate(
39
                    organism=dd.organism,
40
                    human=dd.organism.is_human,
41
                    route=dd.route,
42
                    test_type=dd.test_type,
43
                )
44
                results.append(
45
                    self._create_hit(
46
                        c_id=str(data.cid),
47
                        c_origin=inchikey,
48
                        c_matched=data.names_and_identifiers.inchikey,
49
                        c_name=data.name,
50
                        data_source=source,
51
                        predicate=predicate,
52
                        object_id=effect_name,
53
                        object_name=effect_name,
54
                        effect=effect.lower(),
55
                        organism=dd.organism,
56
                        human=dd.organism.is_human,
57
                        route=dd.route,
58
                        mg_per_kg=dd.mg_per_kg,
59
                        test_type=dd.test_type,
60
                        weight=weight,
61
                    )
62
                )
63
        return results
64
65
66
class Ld50Search(PubchemSearch[Ld50Hit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
67
    def find(self, inchikey: str) -> Sequence[Ld50Hit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
68
        data = self.api.fetch_data(inchikey)
69
        results = []
70
        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...
71
            if dd.test_type != "LD50":
72
                continue
73
            try:
74
                weight = -dd.mg_per_kg
75
            except ValueError:
76
                logger.error(f"Failed to parse {dd.dose} on {inchikey}")
77
                logger.opt(exception=True).debug(f"Failed to parse {dd.dose} on {inchikey}: {dd}")
78
                continue
79
            logger.trace(f"NLP: Weight {weight} from {dd.mg_per_kg}")
80
            source = self._format_source(
81
                organism=dd.organism,
82
                human=dd.organism.is_human,
83
                route=dd.route,
84
                test_type=dd.test_type,
85
            )
86
            predicate = self._format_predicate(
87
                organism=dd.organism,
88
                human=dd.organism.is_human,
89
                route=dd.route,
90
                test_type=dd.test_type,
91
            )
92
            results.append(
93
                self._create_hit(
94
                    inchikey=inchikey,
95
                    c_id=str(data.cid),
96
                    c_origin=inchikey,
97
                    c_matched=data.names_and_identifiers.inchikey,
98
                    c_name=data.name,
99
                    data_source=source,
100
                    predicate=predicate,
101
                    object_id=str(dd.mg_per_kg),
102
                    object_name=str(dd.mg_per_kg),
103
                    weight=weight,
104
                    organism=dd.organism,
105
                    human=dd.organism.is_human,
106
                    route=dd.route,
107
                    cache_date=data.names_and_identifiers.modify_date,
108
                )
109
            )
110
        return results
111
112
113
__all__ = ["AcuteEffectSearch", "Ld50Search"]
114