Passed
Push — dependabot/pip/flake8-bugbear-... ( 82a4d5...16d864 )
by
unknown
02:18
created

mandos.search.chembl.binding_search.BindingSearch._extract()   B

Complexity

Conditions 5

Size

Total Lines 23
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 21
nop 4
dl 0
loc 23
rs 8.9093
c 0
b 0
f 0
1
import logging
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from dataclasses import dataclass
3
from typing import Sequence, Set, Optional
0 ignored issues
show
Unused Code introduced by
Unused Optional imported from typing
Loading history...
4
5
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
6
7
from mandos.model.chembl_api import ChemblApi
0 ignored issues
show
Unused Code introduced by
Unused ChemblApi imported from mandos.model.chembl_api
Loading history...
8
from mandos.model.chembl_support import ChemblCompound
9
from mandos.model.chembl_support.chembl_target_graphs import ChemblTargetGraph
10
from mandos.model.taxonomy import Taxonomy
0 ignored issues
show
Unused Code introduced by
Unused Taxonomy imported from mandos.model.taxonomy
Loading history...
11
from mandos.search.chembl._activity_search import _ActivitySearch, _ActivityHit
12
from mandos.search.chembl._protein_search import ProteinHit, ProteinSearch
0 ignored issues
show
Unused Code introduced by
Unused ProteinHit imported from mandos.search.chembl._protein_search
Loading history...
Unused Code introduced by
Unused ProteinSearch imported from mandos.search.chembl._protein_search
Loading history...
13
14
logger = logging.getLogger("mandos")
15
16
17
@dataclass(frozen=True, order=True, repr=True)
18
class BindingHit(_ActivityHit):
19
    """
20
    An "activity" hit for a compound.
21
    """
22
23
    pchembl: float
24
    std_type: str
25
    standard_relation: str
26
27
    @property
28
    def predicate(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
29
        return "activity"
30
31
32 View Code Duplication
class BindingSearch(_ActivitySearch[BindingHit]):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
33
    """
34
    Search for ``activity`` of type "B".
35
    """
36
37
    @classmethod
38
    def allowed_assay_types(cls) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
39
        return {"B"}
40
41
    def to_hit(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
42
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
43
        lookup: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
44
        compound: ChemblCompound,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
45
        data: NestedDotDict,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
46
        best_target: ChemblTargetGraph,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
47
    ) -> Sequence[BindingHit]:
48
        # these must match the constructor of the Hit,
49
        # EXCEPT for object_id and object_name, which come from traversal
50
        from_super = self._extract(lookup, compound, data)
51
        hit = BindingHit(
52
            record_id=from_super.req_as("activity_id", str),
53
            origin_inchikey=lookup,
54
            matched_inchikey=compound.inchikey,
55
            compound_id=compound.chid,
56
            compound_name=compound.name,
57
            predicate="binds",
58
            object_id=best_target.chembl,
59
            object_name=best_target.name,
60
            search_key=self.key,
61
            search_class=self.search_class,
62
            data_source=self.data_source,
63
            exact_target_id=from_super.req_as("target_chembl_id", str),
64
            taxon_id=from_super.get("taxon_id"),
65
            taxon_name=from_super.get("taxon_name"),
66
            src_id=from_super.req_as("src_id", str),
67
            pchembl=from_super.req_as("pchembl_value", float),
68
            std_type=from_super.req_as("standard_type", str),
69
            standard_relation=from_super.req_as("standard_relation", str),
70
        )
71
        return [hit]
72
73
74
__all__ = ["BindingHit", "BindingSearch"]
75