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

FunctionalSearch.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
import enum
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
Unused Code introduced by
The import enum seems to be unused.
Loading history...
2
import logging
0 ignored issues
show
Unused Code introduced by
The import logging seems to be unused.
Loading history...
3
from dataclasses import dataclass
4
from typing import Sequence, Optional, Set
5
6
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
7
8
from mandos import logger
0 ignored issues
show
Unused Code introduced by
Unused logger imported from mandos
Loading history...
9
from mandos.search.chembl._activity_search import _ActivitySearch, _ActivityHit
10
from mandos.model.chembl_support import ChemblCompound, AssayType
0 ignored issues
show
Unused Code introduced by
Unused AssayType imported from mandos.model.chembl_support
Loading history...
11
from mandos.model.chembl_support.chembl_target_graphs import ChemblTargetGraph
12
13
14
@dataclass(frozen=True, order=True, repr=True)
15
class FunctionalHit(_ActivityHit):
16
    """
17
    An "activity" hit of type "F" for a compound.
18
    """
19
20
    tissue: Optional[str]
21
    cell_type: Optional[str]
22
    subcellular_region: Optional[str]
23
24
25
class FunctionalSearch(_ActivitySearch[FunctionalHit]):
26
    """
27
    Search for ``activity`` of type "F".
28
    """
29
30
    @property
31
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
32
        return "ChEMBL :: functional activity"
33
34
    @classmethod
35
    def allowed_assay_types(cls) -> Set[str]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
36
        return {"F"}
37
38
    def to_hit(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
39
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
40
        lookup: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
41
        compound: ChemblCompound,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
42
        data: NestedDotDict,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
43
        best_target: ChemblTargetGraph,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
44
    ) -> Sequence[FunctionalHit]:
45
        # these must match the constructor of the Hit,
46
        # EXCEPT for object_id and object_name, which come from traversal
47
        from_super = self._extract(lookup, compound, data)
48
        hit = FunctionalHit(
49
            record_id=from_super.req_as("activity_id", str),
50
            origin_inchikey=lookup,
51
            matched_inchikey=compound.inchikey,
52
            compound_id=compound.chid,
53
            compound_name=compound.name,
54
            predicate="has functional activity for",
55
            object_id=best_target.chembl,
56
            object_name=best_target.name,
57
            search_key=self.key,
58
            search_class=self.search_class,
59
            data_source=self.data_source,
60
            exact_target_id=from_super.req_as("target_chembl_id", str),
61
            taxon_id=from_super.get("taxon_id"),
62
            taxon_name=from_super.get("taxon_name"),
63
            src_id=from_super.req_as("src_id", str),
64
            tissue=from_super.get_as("tissue", str),
65
            cell_type=from_super.get_as("cell_type", str),
66
            subcellular_region=from_super.get("subcellular_region", str),
67
        )
68
        return [hit]
69
70
71
__all__ = ["FunctionalHit", "FunctionalSearch"]
72