Passed
Push — main ( 9ff912...d08a4e )
by Douglas
03:54
created

mandos.search.chembl.functional_search.FunctionalSearch._extract()   A

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

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