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

mandos.search.chembl.functional_search.FunctionalSearch.should_include()   B

Complexity

Conditions 6

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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