Passed
Push — main ( 9cce85...686e96 )
by Douglas
02:52
created

ource()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
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...
4
5
from mandos.model.apis.pubchem_api import PubchemApi
6
from mandos.search.pubchem import PubchemSearch
7
from mandos.model.concrete_hits import AcuteEffectHit, Ld50Hit
8
9
10
class AcuteEffectSearch(PubchemSearch[AcuteEffectHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
11
    """ """
12
13
    def __init__(self, key: str, api: PubchemApi, top_level: bool):
14
        super().__init__(key, api)
15
        self.top_level = top_level
16
17
    def find(self, inchikey: str) -> Sequence[AcuteEffectHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
18
        data = self.api.fetch_data(inchikey)
19
        results = []
20
        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...
21
            for effect in dd.effects:
22
                effect_name = effect.category.lower() if self.top_level else effect.lower()
23
                weight = -np.log10(dd.mg_per_kg)
24
                source = self._format_source(
25
                    organism=dd.organism,
26
                    human=dd.organism.is_human,
27
                    route=dd.route,
28
                    test_type=dd.test_type,
29
                )
30
                predicate = self._format_predicate(
31
                    organism=dd.organism,
32
                    human=dd.organism.is_human,
33
                    route=dd.route,
34
                    test_type=dd.test_type,
35
                )
36
                results.append(
37
                    self._create_hit(
38
                        inchikey=inchikey,
39
                        c_id=str(data.cid),
40
                        c_origin=inchikey,
41
                        c_matched=data.names_and_identifiers.inchikey,
42
                        c_name=data.name,
43
                        data_source=source,
44
                        predicate=predicate,
45
                        object_id=effect_name,
46
                        object_name=effect_name,
47
                        effect=effect.lower(),
48
                        organism=dd.organism,
49
                        human=dd.organism.is_human,
50
                        route=dd.route,
51
                        mg_per_kg=dd.mg_per_kg,
52
                        test_type=dd.test_type,
53
                        weight=weight,
54
                    )
55
                )
56
        return results
57
58
59
class Ld50Search(PubchemSearch[Ld50Hit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
60
    def find(self, inchikey: str) -> Sequence[Ld50Hit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
61
        data = self.api.fetch_data(inchikey)
62
        results = []
63
        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...
64
            if dd.test_type != "LD50":
65
                continue
66
            weight = -np.log10(dd.mg_per_kg)
67
            results.append(
68
                self._create_hit(
69
                    inchikey=inchikey,
70
                    c_id=str(data.cid),
71
                    c_origin=inchikey,
72
                    c_matched=data.names_and_identifiers.inchikey,
73
                    c_name=data.name,
74
                    data_source="ChemIDplus",
75
                    predicate="has LD50",
76
                    object_id=str(dd.mg_per_kg),
77
                    object_name=str(dd.mg_per_kg),
78
                    weight=weight,
79
                    organism=dd.organism,
80
                    human=dd.organism.is_human,
81
                    route=dd.route,
82
                )
83
            )
84
        return results
85
86
87
__all__ = ["AcuteEffectSearch", "Ld50Search"]
88