|
1
|
|
|
from typing import Sequence |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
import numpy as np |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
from mandos.model.apis.pubchem_api import PubchemApi |
|
6
|
|
|
from mandos.search.pubchem import PubchemSearch |
|
7
|
|
|
from mandos.model.concrete_hits import AcuteEffectHit, Ld50Hit |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class AcuteEffectSearch(PubchemSearch[AcuteEffectHit]): |
|
|
|
|
|
|
11
|
|
|
""" """ |
|
12
|
|
|
|
|
13
|
|
|
def __init__(self, key: str, api: PubchemApi, top_level: bool): |
|
14
|
|
|
super().__init__(key, api) |
|
15
|
|
|
self.top_level = top_level |
|
16
|
|
|
|
|
17
|
|
|
def find(self, inchikey: str) -> Sequence[AcuteEffectHit]: |
|
|
|
|
|
|
18
|
|
|
data = self.api.fetch_data(inchikey) |
|
19
|
|
|
results = [] |
|
20
|
|
|
for dd in data.toxicity.acute_effects: |
|
|
|
|
|
|
21
|
|
|
for effect in dd.effects: |
|
22
|
|
|
effect_name = effect.category.lower() if self.top_level else effect.lower() |
|
23
|
|
|
weight = -np.log10(dd.mg_per_kg) |
|
24
|
|
|
source = self._format_source( |
|
25
|
|
|
organism=dd.organism, |
|
26
|
|
|
human=dd.organism.is_human, |
|
27
|
|
|
route=dd.route, |
|
28
|
|
|
test_type=dd.test_type, |
|
29
|
|
|
) |
|
30
|
|
|
predicate = self._format_predicate( |
|
31
|
|
|
organism=dd.organism, |
|
32
|
|
|
human=dd.organism.is_human, |
|
33
|
|
|
route=dd.route, |
|
34
|
|
|
test_type=dd.test_type, |
|
35
|
|
|
) |
|
36
|
|
|
results.append( |
|
37
|
|
|
self._create_hit( |
|
38
|
|
|
inchikey=inchikey, |
|
39
|
|
|
c_id=str(data.cid), |
|
40
|
|
|
c_origin=inchikey, |
|
41
|
|
|
c_matched=data.names_and_identifiers.inchikey, |
|
42
|
|
|
c_name=data.name, |
|
43
|
|
|
data_source=source, |
|
44
|
|
|
predicate=predicate, |
|
45
|
|
|
object_id=effect_name, |
|
46
|
|
|
object_name=effect_name, |
|
47
|
|
|
effect=effect.lower(), |
|
48
|
|
|
organism=dd.organism, |
|
49
|
|
|
human=dd.organism.is_human, |
|
50
|
|
|
route=dd.route, |
|
51
|
|
|
mg_per_kg=dd.mg_per_kg, |
|
52
|
|
|
test_type=dd.test_type, |
|
53
|
|
|
weight=weight, |
|
54
|
|
|
) |
|
55
|
|
|
) |
|
56
|
|
|
return results |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
class Ld50Search(PubchemSearch[Ld50Hit]): |
|
|
|
|
|
|
60
|
|
|
def find(self, inchikey: str) -> Sequence[Ld50Hit]: |
|
|
|
|
|
|
61
|
|
|
data = self.api.fetch_data(inchikey) |
|
62
|
|
|
results = [] |
|
63
|
|
|
for dd in data.toxicity.acute_effects: |
|
|
|
|
|
|
64
|
|
|
if dd.test_type != "LD50": |
|
65
|
|
|
continue |
|
66
|
|
|
weight = -np.log10(dd.mg_per_kg) |
|
67
|
|
|
results.append( |
|
68
|
|
|
self._create_hit( |
|
69
|
|
|
inchikey=inchikey, |
|
70
|
|
|
c_id=str(data.cid), |
|
71
|
|
|
c_origin=inchikey, |
|
72
|
|
|
c_matched=data.names_and_identifiers.inchikey, |
|
73
|
|
|
c_name=data.name, |
|
74
|
|
|
data_source="ChemIDplus", |
|
75
|
|
|
predicate="has LD50", |
|
76
|
|
|
object_id=str(dd.mg_per_kg), |
|
77
|
|
|
object_name=str(dd.mg_per_kg), |
|
78
|
|
|
weight=weight, |
|
79
|
|
|
organism=dd.organism, |
|
80
|
|
|
human=dd.organism.is_human, |
|
81
|
|
|
route=dd.route, |
|
82
|
|
|
) |
|
83
|
|
|
) |
|
84
|
|
|
return results |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
__all__ = ["AcuteEffectSearch", "Ld50Search"] |
|
88
|
|
|
|