Passed
Push — dependabot/pip/flake8-bugbear-... ( 5c5892...6076c0 )
by
unknown
01:34
created

IndicationSearch.data_source()   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 __future__ import annotations
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import logging
0 ignored issues
show
Unused Code introduced by
The import logging seems to be unused.
Loading history...
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 import logger
0 ignored issues
show
Unused Code introduced by
Unused logger imported from mandos
Loading history...
10
from mandos.model.chembl_api import ChemblApi
11
from mandos.model.chembl_support import ChemblCompound
12
from mandos.model.chembl_support.chembl_utils import ChemblUtils
13
from mandos.search.chembl import ChemblHit, ChemblSearch
14
15
16
@dataclass(frozen=True, order=True, repr=True)
17
class IndicationHit(ChemblHit):
18
    """
19
    An indication with a MESH term.
20
    """
21
22
    max_phase: int
23
    first_approval_year: str
24
25
26
class IndicationSearch(ChemblSearch[IndicationHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
27
    """"""
28
29
    def __init__(self, key: str, api: ChemblApi, min_phase: int):
30
        super().__init__(key, api)
31
        self.min_phase = min_phase
32
33
    @property
34
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
35
        return "ChEMBL :: indications"
36
37
    def find(self, lookup: str) -> Sequence[IndicationHit]:
38
        """
39
40
        Args:
41
            lookup:
42
43
        Returns:
44
45
        """
46
        # 'atc_classifications': ['S01HA01', 'N01BC01', 'R02AD03', 'S02DA02']
47
        # 'indication_class': 'Anesthetic (topical)'
48
        ch = ChemblUtils(self.api).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...
49
        compound = ChemblUtils(self.api).compound_dot_dict_to_obj(ch)
50
        inds = self.api.drug_indication.filter(parent_molecule_chembl_id=compound.chid)
51
        hits = []
52
        for ind in inds:
53
            if ind.req_as("max_phase_for_ind", int) >= self.min_phase:
54
                hits.append(self.process(lookup, compound, ind))
55
        return hits
56
57
    def process(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
58
        self, lookup: str, compound: ChemblCompound, indication: NestedDotDict
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
59
    ) -> IndicationHit:
60
        phase = indication.req_as("max_phase_for_ind", int)
61
        return IndicationHit(
62
            record_id=indication.req_as("drugind_id", str),
63
            origin_inchikey=lookup,
64
            matched_inchikey=compound.inchikey,
65
            compound_id=compound.chid,
66
            compound_name=compound.name,
67
            predicate=f"used in a phase {phase} trial for",
68
            object_id=indication.req_as("mesh_id", str),
69
            object_name=indication.req_as("mesh_heading", str).strip("\n"),
70
            search_key=self.key,
71
            search_class=self.search_class,
72
            data_source=self.data_source + " :: " + indication.req_as("references", str),
73
            max_phase=phase,
74
            first_approval_year=indication.req_as("first_approval", str),
75
        )
76
77
78
__all__ = ["IndicationHit", "IndicationSearch"]
79