PubchemClassHit.predicate()   A
last analyzed

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 abc
4
import enum
0 ignored issues
show
Unused Code introduced by
The import enum seems to be unused.
Loading history...
5
import logging
0 ignored issues
show
Unused Code introduced by
The import logging seems to be unused.
Loading history...
6
import re
7
from dataclasses import dataclass
8
from typing import Sequence, Type, Union, FrozenSet, Optional, TypeVar, Any
0 ignored issues
show
Unused Code introduced by
Unused Union imported from typing
Loading history...
Unused Code introduced by
Unused FrozenSet imported from typing
Loading history...
Unused Code introduced by
Unused Any imported from typing
Loading history...
9
10
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
Unused Code introduced by
Unused NestedDotDict imported from pocketutils.core.dot_dict
Loading history...
11
12
from mandos.model import AbstractHit, Search
13
from mandos.chembl_api import ChemblApi
14
from mandos.model.settings import Settings
15
from mandos.model.taxonomy import Taxonomy
16
from mandos.pubchem_api import (
0 ignored issues
show
Bug introduced by
The name TitleAndSummary does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name RelatedRecords does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name ChemicalAndPhysicalProperties does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name DrugAndMedicationInformation does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name PharmacologyAndBiochemistry does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name SafetyAndHazards does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name Toxicity does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name AssociatedDisordersAndDiseases does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name Literature does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name BiomolecularInteractionsAndPathways does not seem to exist in module mandos.pubchem_api.
Loading history...
Bug introduced by
The name Classification does not seem to exist in module mandos.pubchem_api.
Loading history...
Unused Code introduced by
Unused TitleAndSummary imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused RelatedRecords imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused ChemicalAndPhysicalProperties imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused PharmacologyAndBiochemistry imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused SafetyAndHazards imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused Toxicity imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused AssociatedDisordersAndDiseases imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused Literature imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused BiomolecularInteractionsAndPathways imported from mandos.pubchem_api
Loading history...
Unused Code introduced by
Unused Classification imported from mandos.pubchem_api
Loading history...
17
    CachingPubchemApi,
18
    QueryingPubchemApi,
19
    PubchemData,
20
    TitleAndSummary,
21
    RelatedRecords,
22
    ChemicalAndPhysicalProperties,
23
    DrugAndMedicationInformation,
24
    PharmacologyAndBiochemistry,
25
    SafetyAndHazards,
26
    Toxicity,
27
    AssociatedDisordersAndDiseases,
28
    Literature,
29
    BiomolecularInteractionsAndPathways,
30
    Classification,
31
)
32
33
34
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
35
class PubchemClassHit(AbstractHit):
36
    @property
37
    def predicate(self) -> str:
38
        return "is in"
39
40
41
H = TypeVar("H", bound=AbstractHit, covariant=True)
0 ignored issues
show
Coding Style Naming introduced by
Class name "H" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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
43
44
class PubchemSearch(Search[H], metaclass=abc.ABCMeta):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
45
    def __init__(self, chembl_api: ChemblApi, config: Settings, tax: Taxonomy):
46
        super().__init__(chembl_api, config, tax)
47
        self.pubchem_api = CachingPubchemApi(config.cache_path, QueryingPubchemApi(), compress=True)
48
49
    def find(self, lookup: str) -> Sequence[H]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
50
        data = self.pubchem_api.fetch_data(lookup)
51
        return self.process(lookup, data)
52
53
    def process(self, lookup: str, data: PubchemData) -> Sequence[H]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
54
        raise NotImplementedError()
55
56
57
class PubchemSearchFactory:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
58
59
    pattern = re.compile(r"(?<!^)(?=[A-Z])")
60
61
    @classmethod
62
    def cat(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
63
        cls, full_field, name: Optional[str] = None, object_field: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
64
    ) -> Type[PubchemSearch]:
65
        clazz_name, field_name = str(full_field).split(" ", 3)[-2].split(".")
66
        clazz_name = PubchemSearchFactory.pattern.sub("_", clazz_name.__name__).lower()
67
        if name is None:
68
            name = field_name.replace("_", " ")
69
70
        class MyClassSearch(PubchemSearch[PubchemClassHit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
71
            def process(self, lookup: str, data: PubchemData) -> Sequence[PubchemClassHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
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...
72
                values = getattr(getattr(data, clazz_name), field_name)
73
                if object_field is not None:
74
                    values = frozenset([getattr(x, object_field) for x in values])
75
                if not isinstance(values, frozenset):
76
                    values = frozenset({values})
77
                hits = []
78
                for value in values:
79
                    """
80
                    record_id: Optional[str]
81
                    compound_id: str
82
                    inchikey: str
83
                    compound_lookup: str
84
                    compound_name: str
85
                    object_id: str
86
                    object_name: str
87
                    """
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...
88
                    hit = PubchemClassHit(
0 ignored issues
show
Unused Code introduced by
The variable hit seems to be unused.
Loading history...
89
                        record_id=None,
90
                        compound_id=str(data.cid),
91
                        inchikey=data.chemical_and_physical_properties.inchikey,
92
                        compound_lookup=lookup,
93
                        compound_name=data.name,
94
                        object_id=str(value),
95
                        object_name=str(value),
96
                    )
97
                return hits
98
99
        MyClassSearch.__name__ = name
100
        return MyClassSearch
101
102
103
F = PubchemSearchFactory
0 ignored issues
show
Coding Style Naming introduced by
Class name "F" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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...
104
P = PubchemData
0 ignored issues
show
Coding Style Naming introduced by
Class name "P" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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...
105
106
DeaClassSearch = F.cat(DrugAndMedicationInformation.dea_class)
107
DeaScheduleSearch = F.cat(DrugAndMedicationInformation.dea_schedule)
108
HsdbUsesSearch = F.cat(DrugAndMedicationInformation.hsdb_uses)
109
ClinicalTrialsSearch = F.cat(DrugAndMedicationInformation.clinical_trials)
110