|
1
|
|
|
from dataclasses import dataclass |
|
|
|
|
|
|
2
|
|
|
from typing import Sequence, Optional |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
from mandos.model.pubchem_api import PubchemApi |
|
5
|
|
|
from mandos.search.pubchem import PubchemHit, PubchemSearch |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
|
|
9
|
|
|
class AcuteEffectHit(PubchemHit): |
|
10
|
|
|
"""""" |
|
11
|
|
|
|
|
12
|
|
|
organism: str |
|
13
|
|
|
human: bool |
|
14
|
|
|
test_type: str |
|
15
|
|
|
route: str |
|
16
|
|
|
effect: str |
|
17
|
|
|
mg_per_kg: float |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
|
|
21
|
|
|
class Ld50Hit(PubchemHit): |
|
22
|
|
|
"""""" |
|
23
|
|
|
|
|
24
|
|
|
organism: str |
|
25
|
|
|
human: bool |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class AcuteEffectSearch(PubchemSearch[AcuteEffectHit]): |
|
|
|
|
|
|
29
|
|
|
"""""" |
|
30
|
|
|
|
|
31
|
|
|
def __init__(self, key: str, api: PubchemApi, top_level: bool): |
|
32
|
|
|
super().__init__(key, api) |
|
33
|
|
|
self.top_level = top_level |
|
34
|
|
|
|
|
35
|
|
|
@property |
|
36
|
|
|
def data_source(self) -> str: |
|
|
|
|
|
|
37
|
|
|
return "ChemIDplus" |
|
38
|
|
|
|
|
39
|
|
|
def find(self, inchikey: str) -> Sequence[AcuteEffectHit]: |
|
|
|
|
|
|
40
|
|
|
data = self.api.fetch_data(inchikey) |
|
41
|
|
|
results = [] |
|
42
|
|
|
for dd in data.toxicity.acute_effects: |
|
|
|
|
|
|
43
|
|
|
for effect in dd.effects: |
|
44
|
|
|
effect_name = effect.category.lower() if self.top_level else effect.lower() |
|
45
|
|
|
results.append( |
|
46
|
|
|
AcuteEffectHit( |
|
47
|
|
|
record_id=str(dd.gid), |
|
48
|
|
|
origin_inchikey=inchikey, |
|
49
|
|
|
matched_inchikey=data.names_and_identifiers.inchikey, |
|
50
|
|
|
compound_id=str(data.cid), |
|
51
|
|
|
compound_name=data.name, |
|
52
|
|
|
predicate="causes acute effect", |
|
53
|
|
|
object_id=effect_name, |
|
54
|
|
|
object_name=effect_name, |
|
55
|
|
|
search_key=self.key, |
|
56
|
|
|
search_class=self.search_class, |
|
57
|
|
|
data_source=self.data_source, |
|
58
|
|
|
effect=effect.lower(), |
|
59
|
|
|
organism=dd.organism, |
|
60
|
|
|
human=dd.organism.is_human, |
|
61
|
|
|
route=dd.route, |
|
62
|
|
|
mg_per_kg=dd.mg_per_kg, |
|
63
|
|
|
test_type=dd.test_type, |
|
64
|
|
|
) |
|
65
|
|
|
) |
|
66
|
|
|
return results |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
class Ld50Search(PubchemSearch[Ld50Hit]): |
|
|
|
|
|
|
70
|
|
|
@property |
|
71
|
|
|
def data_source(self) -> str: |
|
|
|
|
|
|
72
|
|
|
return "ChemIDplus" |
|
73
|
|
|
|
|
74
|
|
|
def find(self, inchikey: str) -> Sequence[Ld50Hit]: |
|
|
|
|
|
|
75
|
|
|
data = self.api.fetch_data(inchikey) |
|
76
|
|
|
results = [] |
|
77
|
|
|
for dd in data.toxicity.acute_effects: |
|
|
|
|
|
|
78
|
|
|
if dd.test_type != "LD50": |
|
79
|
|
|
continue |
|
80
|
|
|
results.append( |
|
81
|
|
|
Ld50Hit( |
|
82
|
|
|
record_id=str(dd.gid), |
|
83
|
|
|
origin_inchikey=inchikey, |
|
84
|
|
|
matched_inchikey=data.names_and_identifiers.inchikey, |
|
85
|
|
|
compound_id=str(data.cid), |
|
86
|
|
|
compound_name=data.name, |
|
87
|
|
|
predicate="has LD50 for " + dd.organism, |
|
88
|
|
|
object_id=str(dd.mg_per_kg), |
|
89
|
|
|
object_name=str(dd.mg_per_kg), |
|
90
|
|
|
search_key=self.key, |
|
91
|
|
|
search_class=self.search_class, |
|
92
|
|
|
data_source=self.data_source, |
|
93
|
|
|
organism=dd.organism, |
|
94
|
|
|
human=dd.organism.is_human, |
|
95
|
|
|
) |
|
96
|
|
|
) |
|
97
|
|
|
return results |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
__all__ = ["AcuteEffectHit", "AcuteEffectSearch", "Ld50Hit", "Ld50Search"] |
|
101
|
|
|
|