1
|
|
|
from __future__ import annotations |
|
|
|
|
2
|
|
|
import enum |
3
|
|
|
from dataclasses import dataclass |
4
|
|
|
from typing import Set, Union |
5
|
|
|
|
6
|
|
|
from mandos.model import CleverEnum, CompoundNotFoundError |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class ChemblCompoundLookupError(CompoundNotFoundError): |
|
|
|
|
10
|
|
|
"""""" |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class ActivityRelation(CleverEnum): |
|
|
|
|
14
|
|
|
lt = enum.auto() |
15
|
|
|
gt = enum.auto() |
16
|
|
|
le = enum.auto() |
17
|
|
|
ge = enum.auto() |
18
|
|
|
eq = enum.auto() |
19
|
|
|
approx = enum.auto() |
20
|
|
|
|
21
|
|
|
@classmethod |
22
|
|
|
def of(cls, name: Union[int, str]) -> CleverEnum: |
|
|
|
|
23
|
|
|
return super().of( |
24
|
|
|
{ |
25
|
|
|
"<": "lt", |
26
|
|
|
">": "gt", |
27
|
|
|
"=": "eq", |
28
|
|
|
"~": "approx", |
29
|
|
|
"<=": "le", |
30
|
|
|
">=": "ge", |
31
|
|
|
}.get(name, name) |
32
|
|
|
) |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class DataValidityComment(CleverEnum): |
|
|
|
|
36
|
|
|
potential_missing_data = enum.auto() |
37
|
|
|
potential_author_error = enum.auto() |
38
|
|
|
manually_validated = enum.auto() |
39
|
|
|
outside_typical_range = enum.auto() |
40
|
|
|
non_standard_unit_for_type = enum.auto() |
41
|
|
|
author_confirmed_error = enum.auto() |
42
|
|
|
|
43
|
|
|
@classmethod |
44
|
|
|
def resolve(cls, st: str) -> Set[DataValidityComment]: |
|
|
|
|
45
|
|
|
found = set() |
46
|
|
|
for s in st.lower().split(","): |
|
|
|
|
47
|
|
|
s = s.strip() |
|
|
|
|
48
|
|
|
if s == "@all": |
49
|
|
|
return set(cls) |
50
|
|
|
if s == "@negative": |
51
|
|
|
match = DataValidityComment.negative_comments() |
52
|
|
|
elif s == "@positive": |
53
|
|
|
match = DataValidityComment.positive_comments() |
54
|
|
|
else: |
55
|
|
|
match = {DataValidityComment.of(s)} |
56
|
|
|
for m in match: |
|
|
|
|
57
|
|
|
found.add(m) |
58
|
|
|
return found |
59
|
|
|
|
60
|
|
|
@property |
61
|
|
|
def is_positive(self) -> bool: |
|
|
|
|
62
|
|
|
return self in DataValidityComment.positive_comments() |
63
|
|
|
|
64
|
|
|
@property |
65
|
|
|
def is_negative(self) -> bool: |
|
|
|
|
66
|
|
|
return self in DataValidityComment.negative_comments() |
67
|
|
|
|
68
|
|
|
@classmethod |
69
|
|
|
def positive_comments(cls) -> Set[DataValidityComment]: |
|
|
|
|
70
|
|
|
return {DataValidityComment.manually_validated} |
71
|
|
|
|
72
|
|
|
@classmethod |
73
|
|
|
def negative_comments(cls) -> Set[DataValidityComment]: |
|
|
|
|
74
|
|
|
return { |
75
|
|
|
DataValidityComment.potential_missing_data, |
76
|
|
|
DataValidityComment.potential_author_error, |
77
|
|
|
DataValidityComment.outside_typical_range, |
78
|
|
|
DataValidityComment.non_standard_unit_for_type, |
79
|
|
|
DataValidityComment.author_confirmed_error, |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
84
|
|
|
class ChemblCompound: |
85
|
|
|
"""""" |
86
|
|
|
|
87
|
|
|
chid: str |
88
|
|
|
inchikey: str |
89
|
|
|
name: str |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
class AssayType(enum.Enum): |
|
|
|
|
93
|
|
|
binding = enum.auto() |
94
|
|
|
functional = enum.auto() |
95
|
|
|
adme = enum.auto() |
96
|
|
|
physicochemical = enum.auto() |
97
|
|
|
|
98
|
|
|
@property |
99
|
|
|
def character(self) -> str: |
|
|
|
|
100
|
|
|
return { |
101
|
|
|
AssayType.binding: "B", |
102
|
|
|
AssayType.functional: "F", |
103
|
|
|
AssayType.adme: "A", |
104
|
|
|
AssayType.physicochemical: "P", |
105
|
|
|
}[self] |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
__all__ = [ |
109
|
|
|
"ChemblCompound", |
110
|
|
|
"ChemblCompoundLookupError", |
111
|
|
|
"DataValidityComment", |
112
|
|
|
"ActivityRelation", |
113
|
|
|
"AssayType", |
114
|
|
|
] |
115
|
|
|
|