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

mandos.search.pubchem.computed_property_search   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ComputedPropertySearch.__init__() 0 5 1
A ComputedPropertySearch.data_source() 0 3 1
A ComputedPropertySearch.find() 0 24 3
A ComputedPropertySearch._standardize_key() 0 2 1
1
import abc
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
Unused Code introduced by
The import abc seems to be unused.
Loading history...
2
from dataclasses import dataclass
3
from typing import Sequence, Set, Optional
0 ignored issues
show
Unused Code introduced by
Unused Optional imported from typing
Loading history...
4
5
from pocketutils.tools.common_tools import CommonTools
0 ignored issues
show
introduced by
Unable to import 'pocketutils.tools.common_tools'
Loading history...
Unused Code introduced by
Unused CommonTools imported from pocketutils.tools.common_tools
Loading history...
6
7
from mandos.model.pubchem_api import PubchemApi
8
from mandos.model.pubchem_support.pubchem_models import ClinicalTrialsGovUtils
0 ignored issues
show
Unused Code introduced by
Unused ClinicalTrialsGovUtils imported from mandos.model.pubchem_support.pubchem_models
Loading history...
9
from mandos.search.pubchem import PubchemHit, PubchemSearch
10
11
12
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
13
class ComputedPropertyHit(PubchemHit):
14
    pass
15
16
17
class ComputedPropertySearch(PubchemSearch[ComputedPropertyHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
18
    """"""
19
20
    def __init__(self, key: str, api: PubchemApi, descriptors: Set[str], source: str):
21
        super().__init__(key, api)
22
        self.api = api
23
        self.descriptors = descriptors
24
        self.source = source
25
26
    @property
27
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
28
        return self.source
29
30
    def find(self, inchikey: str) -> Sequence[ComputedPropertyHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
31
        data = self.api.fetch_data(inchikey)
32
        results = []
33
        # we're really not going to have a case where there are two keys --
34
        # one with different capitalization or punctuation
35
        descriptors = {self._standardize_key(s) for s in self.descriptors}
36
        for dd in data.chemical_and_physical_properties.computed:
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...
37
            if self._standardize_key(dd.key) in descriptors:
38
                results.append(
39
                    ComputedPropertyHit(
40
                        record_id=None,
41
                        compound_id=str(data.cid),
42
                        origin_inchikey=inchikey,
43
                        matched_inchikey=data.names_and_identifiers.inchikey,
44
                        compound_name=data.name,
45
                        predicate="has " + dd.key.lower(),
46
                        object_id=dd.value,
47
                        object_name=dd.value,
48
                        search_key=self.key,
49
                        search_class=self.search_class,
50
                        data_source=self.data_source,
51
                    )
52
                )
53
        return results
54
55
    def _standardize_key(self, key: str) -> str:
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...
56
        return key.replace(" ", "").replace("-", "").replace("_", "").replace(".", "").lower()
57
58
59
__all__ = ["ComputedPropertyHit", "ComputedPropertySearch"]
60