1
|
|
|
from dataclasses import dataclass |
|
|
|
|
2
|
|
|
from typing import Sequence, Optional, Set |
3
|
|
|
|
4
|
|
|
from mandos.model.pubchem_api import PubchemApi |
5
|
|
|
from mandos.model.pubchem_support.pubchem_data import PubchemData |
6
|
|
|
from mandos.model.pubchem_support.pubchem_models import Activity, AssayType, Bioactivity |
7
|
|
|
from mandos.search.pubchem import PubchemHit, PubchemSearch |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
11
|
|
|
class BioactivityHit(PubchemHit): |
12
|
|
|
"""""" |
13
|
|
|
|
14
|
|
|
activity: str |
15
|
|
|
confirmatory: bool |
16
|
|
|
micromolar: float |
17
|
|
|
relation: str |
18
|
|
|
compound_name_in_assay: str |
19
|
|
|
referrer: str |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class BioactivitySearch(PubchemSearch[BioactivityHit]): |
|
|
|
|
23
|
|
|
"""""" |
24
|
|
|
|
25
|
|
|
def __init__( |
|
|
|
|
26
|
|
|
self, |
|
|
|
|
27
|
|
|
key: str, |
|
|
|
|
28
|
|
|
api: PubchemApi, |
|
|
|
|
29
|
|
|
answers: Set[Activity], |
|
|
|
|
30
|
|
|
assay_types: Set[AssayType], |
|
|
|
|
31
|
|
|
min_micromolar: Optional[float], |
|
|
|
|
32
|
|
|
max_micromolar: Optional[float], |
|
|
|
|
33
|
|
|
relations: Set[str], |
|
|
|
|
34
|
|
|
compound_name_must_match: bool, |
|
|
|
|
35
|
|
|
): |
36
|
|
|
super().__init__(key, api) |
37
|
|
|
self.answers = answers |
38
|
|
|
self.assay_types = assay_types |
39
|
|
|
self.min_micromolar, self.max_micromolar = min_micromolar, max_micromolar |
40
|
|
|
self.relations = relations |
41
|
|
|
self.compound_name_must_match = compound_name_must_match |
42
|
|
|
|
43
|
|
|
@property |
44
|
|
|
def data_source(self) -> str: |
|
|
|
|
45
|
|
|
return "PubChem" |
46
|
|
|
|
47
|
|
|
def find(self, inchikey: str) -> Sequence[BioactivityHit]: |
|
|
|
|
48
|
|
|
data = self.api.fetch_data(inchikey) |
49
|
|
|
results = [] |
50
|
|
|
for dd in data.biological_test_results.bioactivity: |
|
|
|
|
51
|
|
|
results.append(self.process(inchikey, data, dd)) |
52
|
|
|
return results |
53
|
|
|
|
54
|
|
|
def process(self, inchikey: str, data: PubchemData, dd: Bioactivity) -> BioactivityHit: |
|
|
|
|
55
|
|
|
return BioactivityHit( |
56
|
|
|
record_id=None, |
57
|
|
|
origin_inchikey=inchikey, |
58
|
|
|
matched_inchikey=data.names_and_identifiers.inchikey, |
59
|
|
|
compound_id=str(data.cid), |
60
|
|
|
compound_name=data.name, |
61
|
|
|
predicate=f"bioactivity", |
|
|
|
|
62
|
|
|
object_id=dd.gene_id, |
63
|
|
|
object_name=dd.target_name, |
64
|
|
|
search_key=self.key, |
65
|
|
|
search_class=self.search_class, |
66
|
|
|
data_source=self.data_source + " : " + dd.assay_ref, |
67
|
|
|
activity=dd.activity.name.lower(), |
68
|
|
|
confirmatory=dd.assay_type is AssayType.confirmatory, |
69
|
|
|
micromolar=dd.activity_value, |
70
|
|
|
relation=dd.activity_name, |
71
|
|
|
compound_name_in_assay=dd.compound_name, |
72
|
|
|
referrer=dd.assay_ref, |
73
|
|
|
) |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
__all__ = ["BioactivityHit", "BioactivitySearch"] |
77
|
|
|
|