1
|
|
|
import enum |
|
|
|
|
2
|
|
|
import logging |
|
|
|
|
3
|
|
|
from dataclasses import dataclass |
4
|
|
|
from typing import Sequence, Optional, Set |
5
|
|
|
|
6
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
7
|
|
|
|
8
|
|
|
from mandos import logger |
|
|
|
|
9
|
|
|
from mandos.search.chembl._activity_search import _ActivitySearch, _ActivityHit |
10
|
|
|
from mandos.model.chembl_support import ChemblCompound, AssayType |
|
|
|
|
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: |
|
|
|
|
32
|
|
|
return "ChEMBL :: functional activity" |
33
|
|
|
|
34
|
|
|
@classmethod |
35
|
|
|
def allowed_assay_types(cls) -> Set[str]: |
|
|
|
|
36
|
|
|
return {"F"} |
37
|
|
|
|
38
|
|
|
def to_hit( |
|
|
|
|
39
|
|
|
self, |
|
|
|
|
40
|
|
|
lookup: str, |
|
|
|
|
41
|
|
|
compound: ChemblCompound, |
|
|
|
|
42
|
|
|
data: NestedDotDict, |
|
|
|
|
43
|
|
|
best_target: ChemblTargetGraph, |
|
|
|
|
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
|
|
|
|