mandos.search.chembl.go_search.GoHit.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
5
import logging
6
from dataclasses import dataclass
7
from typing import Sequence, Type, 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.model import AbstractHit, Search
12
from mandos.search.chembl.protein_search import ProteinHit, ProteinSearch
13
14
logger = logging.getLogger("mandos")
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(AbstractHit, metaclass=abc.ABCMeta):
31
    """
32
    A mechanism entry for a compound.
33
    """
34
35
    go_type: str
36
    protein_hit: ProteinHit
37
38
    @property
39
    def predicate(self) -> str:
40
        return f"has GO {self.go_type} term"
41
42
43
class GoSearch(Search[GoHit], metaclass=abc.ABCMeta):
44
    """
45
    Search for GO terms.
46
    """
47
48
    @property
49
    def go_type(self) -> GoType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
50
        raise NotImplementedError()
51
52
    @property
53
    def protein_search(self) -> Type[ProteinSearch]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
54
        raise NotImplementedError()
55
56
    def find(self, compound: str) -> Sequence[GoHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
57
        matches = self.protein_search(self.api, self.config, self.tax).find(compound)
58
        terms = []
59
        for match in matches:
60
            target = self.api.target.get(match.object_id)
61
            terms.extend(self._process(match, target))
62
        return terms
63
64
    def _process(self, match: ProteinHit, target: NestedDotDict) -> Sequence[GoHit]:
65
        terms = set()
66
        if target.get("target_components") is not None:
67
            for comp in target["target_components"]:
68
                if comp.get("target_component_xrefs") is not None:
69
                    for xref in comp["target_component_xrefs"]:
70
                        if xref["xref_src_db"] == f"Go{self.go_type.name.capitalize()}":
71
                            terms.add((xref["xref_id"], xref["xref_name"]))
72
        hits = []
73
        for xref_id, xref_name in terms:
74
            hits.append(
75
                GoHit(
76
                    None,
77
                    compound_id=match.compound_id,
78
                    inchikey=match.inchikey,
79
                    compound_lookup=match.compound_lookup,
80
                    compound_name=match.compound_name,
81
                    object_id=xref_id,
82
                    object_name=xref_name,
83
                    go_type=self.go_type.name,
84
                    protein_hit=match,
85
                )
86
            )
87
        return hits
88
89
90
class GoSearchFactory:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
91
    @classmethod
92
    def create(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
93
        cls, go_type: Union[str, GoType], protein_search: Type[ProteinSearch]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
94
    ) -> Type[GoSearch]:
95
        go_type = GoType.of(go_type)
96
97
        class X(GoSearch):
0 ignored issues
show
Coding Style Naming introduced by
Class name "X" 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...
introduced by
Missing class docstring
Loading history...
98
            @property
99
            def go_type(self) -> GoType:
100
                return go_type
101
102
            @property
103
            def protein_search(self) -> Type[ProteinSearch]:
104
                return protein_search
105
106
        X.__name__ = f"Go{go_type.name.capitalize()}From{protein_search.search_name}Search"
107
        return X
108
109
110
__all__ = ["GoHit", "GoSearch", "GoSearchFactory", "GoType"]
111