1
|
|
|
from typing import Sequence |
|
|
|
|
2
|
|
|
|
3
|
|
|
from mandos.model.apis.pubchem_api import PubchemApi |
4
|
|
|
from mandos.model.apis.pubchem_support.pubchem_data import PubchemData |
5
|
|
|
from mandos.model.apis.pubchem_support.pubchem_models import Bioactivity |
6
|
|
|
from mandos.search.pubchem import PubchemSearch |
7
|
|
|
from mandos.model.concrete_hits import BioactivityHit |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class BioactivitySearch(PubchemSearch[BioactivityHit]): |
|
|
|
|
11
|
|
|
""" """ |
12
|
|
|
|
13
|
|
|
def __init__( |
14
|
|
|
self, |
|
|
|
|
15
|
|
|
key: str, |
|
|
|
|
16
|
|
|
api: PubchemApi, |
|
|
|
|
17
|
|
|
compound_name_must_match: bool, |
|
|
|
|
18
|
|
|
): |
19
|
|
|
super().__init__(key, api) |
20
|
|
|
self.compound_name_must_match = compound_name_must_match |
21
|
|
|
|
22
|
|
|
def find(self, inchikey: str) -> Sequence[BioactivityHit]: |
|
|
|
|
23
|
|
|
data = self.api.fetch_data(inchikey) |
24
|
|
|
results = [] |
25
|
|
|
for dd in data.biological_test_results.bioactivity: |
|
|
|
|
26
|
|
|
if not self.compound_name_must_match or dd.compound_name.lower() == data.name.lower(): |
27
|
|
|
results.append(self.process(inchikey, data, dd)) |
28
|
|
|
return results |
29
|
|
|
|
30
|
|
|
def process(self, inchikey: str, data: PubchemData, dd: Bioactivity) -> BioactivityHit: |
|
|
|
|
31
|
|
|
target_name, target_abbrev, species = dd.target_name_abbrev_species |
32
|
|
|
action = dd.activity.name.lower() |
33
|
|
|
source = self._format_source( |
34
|
|
|
assay_type=dd.assay_type, |
35
|
|
|
species=species, |
36
|
|
|
) |
37
|
|
|
predicate = self._format_predicate( |
38
|
|
|
action=action, |
39
|
|
|
assay_type=dd.assay_type, |
40
|
|
|
species=species, |
41
|
|
|
) |
42
|
|
|
return self._create_hit( |
43
|
|
|
inchikey=inchikey, |
44
|
|
|
c_id=str(data.cid), |
45
|
|
|
c_origin=inchikey, |
46
|
|
|
c_matched=data.names_and_identifiers.inchikey, |
47
|
|
|
c_name=data.name, |
48
|
|
|
data_source=source, |
49
|
|
|
predicate=predicate, |
50
|
|
|
object_id=dd.gene_id, |
51
|
|
|
object_name=target_name, |
52
|
|
|
target_abbrev=target_abbrev, |
53
|
|
|
activity=action, |
54
|
|
|
assay_type=dd.assay_type, |
55
|
|
|
micromolar=dd.activity_value, |
56
|
|
|
relation=dd.activity_name, |
57
|
|
|
species=species, |
58
|
|
|
compound_name_in_assay=dd.compound_name, |
59
|
|
|
referrer=dd.assay_ref, |
60
|
|
|
) |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
__all__ = ["BioactivitySearch"] |
64
|
|
|
|