mandos.search.chembl.atc_search   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A AtcSearch._code() 0 11 1
A AtcSearch.find() 0 18 3
A AtcSearch.process() 0 13 1
A AtcHit.predicate() 0 3 1
1
from __future__ import annotations
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import logging
4
from dataclasses import dataclass
5
from typing import Sequence
6
7
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
8
9
from mandos.model import AbstractHit, ChemblCompound, Search
10
11
logger = logging.getLogger("mandos")
12
13
14
@dataclass(frozen=True, order=True, repr=True)
15
class AtcHit(AbstractHit):
16
    """
17
    An ATC code found for a compound.
18
    """
19
20
    level: int
21
22
    @property
23
    def predicate(self) -> str:
24
        return f"has ATC L-{self.level} code"
25
26
27
class AtcSearch(Search[AtcHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
introduced by
Value 'Search' is unsubscriptable
Loading history...
28
    """"""
29
30
    def find(self, lookup: str) -> Sequence[AtcHit]:
31
        """
32
33
        Args:
34
            lookup:
35
36
        Returns:
37
38
        """
39
        # 'atc_classifications': ['S01HA01', 'N01BC01', 'R02AD03', 'S02DA02']
40
        # 'indication_class': 'Anesthetic (topical)'
41
        ch = self.get_compound_dot_dict(lookup)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ch" 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...
42
        compound = self.compound_dot_dict_to_obj(ch)
43
        hits = []
44
        if "atc_classifications" in ch:
45
            for atc in ch["atc_classifications"]:
46
                hits.extend(self.process(lookup, compound, atc))
47
        return hits
48
49
    def process(self, lookup: str, compound: ChemblCompound, atc: str) -> Sequence[AtcHit]:
50
        """
51
52
        Args:
53
            lookup:
54
            compound:
55
            atc:
56
57
        Returns:
58
59
        """
60
        dots = NestedDotDict(self.api.atc_class.get(atc))
61
        return [self._code(lookup, compound, dots, 3), self._code(lookup, compound, dots, 4)]
62
63
    def _code(self, lookup: str, compound: ChemblCompound, dots: NestedDotDict, level: int):
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...
64
        # 'level1': 'N', 'level1_description': 'NERVOUS SYSTEM', 'level2': 'N05', ...
65
        return AtcHit(
66
            None,
67
            compound.chid,
68
            compound.inchikey,
69
            lookup,
70
            compound.name,
71
            object_id=dots.get(f"level{level}"),
72
            object_name=dots.get(f"level{level}_description"),
73
            level=level,
74
        )
75
76
77
__all__ = ["AtcHit", "AtcSearch"]
78