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

GoSearch.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 abc
4
import enum
5
import logging
0 ignored issues
show
Unused Code introduced by
The import logging seems to be unused.
Loading history...
6
from dataclasses import dataclass
7
from typing import Sequence, Union
8
9
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
10
11
from mandos import logger
0 ignored issues
show
Unused Code introduced by
Unused logger imported from mandos
Loading history...
12
from mandos.model.chembl_api import ChemblApi
13
from mandos.search.chembl import ChemblHit, ChemblSearch
14
from mandos.search.chembl.binding_search import BindingSearch, BindingHit
15
16
17
class GoType(enum.Enum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
18
    component = enum.auto()
19
    function = enum.auto()
20
    process = enum.auto()
21
22
    @classmethod
23
    def of(cls, s: Union[str, GoType]) -> GoType:
0 ignored issues
show
Coding Style Naming introduced by
Method name "of" 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...
Coding Style Naming introduced by
Argument name "s" 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...
introduced by
Missing function or method docstring
Loading history...
24
        if isinstance(s, GoType):
25
            return s
26
        return GoType[s.lower()]
27
28
29
@dataclass(frozen=True, order=True, repr=True)
30
class GoHit(ChemblHit, metaclass=abc.ABCMeta):
31
    """
32
    A mechanism entry for a compound.
33
    """
34
35
    go_type: str
36
    binding: BindingHit
37
38
39
class GoSearch(ChemblSearch[GoHit]):
40
    """
41
    Search for GO terms.
42
    """
43
44
    def __init__(self, key: str, api: ChemblApi, go_type: GoType, binding_search: BindingSearch):
45
        super().__init__(key, api)
46
        self.go_type = go_type
47
        self.binding_search = binding_search
48
49
    @property
50
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
51
        return "ChEMBL :: GO terms"
52
53
    def find(self, compound: str) -> Sequence[GoHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
54
        matches = self.binding_search.find(compound)
55
        terms = []
56
        for match in matches:
57
            target = self.api.target.get(match.object_id)
58
            terms.extend(self._process(compound, match, target))
59
        return terms
60
61
    def _process(self, lookup: str, match: BindingHit, target: NestedDotDict) -> Sequence[GoHit]:
62
        terms = set()
63
        if target.get("target_components") is not None:
64
            for comp in target["target_components"]:
65
                if comp.get("target_component_xrefs") is not None:
66
                    for xref in comp["target_component_xrefs"]:
67
                        if xref["xref_src_db"] == f"Go{self.go_type.name.capitalize()}":
68
                            terms.add((xref["xref_id"], xref["xref_name"]))
69
        hits = []
70
        for xref_id, xref_name in terms:
71
            hits.append(
72
                GoHit(
73
                    None,
74
                    origin_inchikey=lookup,
75
                    matched_inchikey=match.matched_inchikey,
76
                    compound_id=match.compound_id,
77
                    compound_name=match.compound_name,
78
                    predicate=f"is associated with {self.go_type.name} term",
79
                    object_id=xref_id,
80
                    object_name=xref_name,
81
                    search_key=self.key,
82
                    search_class=self.search_class,
83
                    data_source=self.data_source,
84
                    go_type=self.go_type.name,
85
                    binding=match,
86
                )
87
            )
88
        return hits
89
90
91
__all__ = ["GoHit", "GoSearch", "GoType"]
92