1
|
|
|
import pytest |
|
|
|
|
2
|
|
|
|
3
|
|
|
from mandos.chembl_api import ChemblApi, ChemblEntrypoint |
4
|
|
|
from mandos.model.targets import Target, TargetFactory, TargetRelationshipType, TargetType |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class TestTargets: |
|
|
|
|
8
|
|
|
def test_find(self): |
|
|
|
|
9
|
|
|
dat = dict( |
10
|
|
|
target_chembl_id="CHEMBL4444", |
11
|
|
|
pref_name="dopamine transporter", |
12
|
|
|
target_type="SINGLE_PROTEIN", |
13
|
|
|
) |
14
|
|
|
api = ChemblApi.mock({"target": ChemblEntrypoint.mock({"DAT": dat})}) |
15
|
|
|
target = TargetFactory.find("DAT", api) |
16
|
|
|
assert isinstance(target, Target) |
17
|
|
|
assert target.type == TargetType.single_protein |
18
|
|
|
assert target.name == "dopamine transporter" |
19
|
|
|
assert target.chembl == "CHEMBL4444" |
20
|
|
|
|
21
|
|
|
def test_parents(self): |
|
|
|
|
22
|
|
|
dat = dict( |
23
|
|
|
target_chembl_id="CHEMBL4444", |
24
|
|
|
pref_name="dopamine transporter", |
25
|
|
|
target_type="SINGLE_PROTEIN", |
26
|
|
|
) |
27
|
|
|
monoamine = dict( |
28
|
|
|
target_chembl_id="CHEMBL1111", |
29
|
|
|
pref_name="monoamine transporter", |
30
|
|
|
target_type="SINGLE_PROTEIN", |
31
|
|
|
) |
32
|
|
|
receptor = dict( |
33
|
|
|
target_chembl_id="CHEMBL0000", pref_name="receptor", target_type="PROTEIN_COMPLEX" |
34
|
|
|
) |
35
|
|
|
relations = [ |
36
|
|
|
dict(relationship="SUBSET OF", related_target_chembl_id="CHEMBL1111"), |
37
|
|
|
dict(relationship="SUBSET OF", related_target_chembl_id="CHEMBL0000"), |
38
|
|
|
] |
39
|
|
|
get_target = { |
40
|
|
|
"DAT": dat, |
41
|
|
|
"CHEMBL4444": dat, |
42
|
|
|
"CHEMBL1111": monoamine, |
43
|
|
|
"CHEMBL0000": receptor, |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
def filter_targets(kwargs): |
|
|
|
|
47
|
|
|
x = kwargs["target_chembl_id"] |
|
|
|
|
48
|
|
|
if x == "CHEMBL4444": |
|
|
|
|
49
|
|
|
return [dat] |
50
|
|
|
elif x == "CHEMBL1111": |
51
|
|
|
return [monoamine] |
52
|
|
|
elif x == "CHEMBL0000": |
53
|
|
|
return [receptor] |
54
|
|
|
|
55
|
|
|
def filter_relations(kwargs): |
|
|
|
|
56
|
|
|
return relations |
57
|
|
|
|
58
|
|
|
api = ChemblApi.mock( |
59
|
|
|
{ |
60
|
|
|
"target": ChemblEntrypoint.mock(get_target, filter_targets), |
61
|
|
|
"target_relation": ChemblEntrypoint.mock({}, filter_relations), |
62
|
|
|
} |
63
|
|
|
) |
64
|
|
|
target = TargetFactory.find("CHEMBL4444", api) |
65
|
|
|
assert len(target.links({TargetRelationshipType.subset_of})) == 2 |
66
|
|
|
# should sort by CHEMBL ID first, so 0000 will be first |
67
|
|
|
parent, link_type = target.links({TargetRelationshipType.subset_of})[0] |
|
|
|
|
68
|
|
|
assert parent.name == "receptor" |
69
|
|
|
assert parent.chembl == "CHEMBL0000" |
70
|
|
|
parent, link_type = target.links({TargetRelationshipType.subset_of})[1] |
71
|
|
|
assert parent.name == "monoamine transporter" |
72
|
|
|
assert parent.chembl == "CHEMBL1111" |
73
|
|
|
|
74
|
|
|
def test_traverse_gabaa(self): |
|
|
|
|
75
|
|
|
x = dict( |
|
|
|
|
76
|
|
|
target_chembl_id="CHEMBL5112", |
77
|
|
|
pref_name="GABA receptor alpha-5 subunit", |
78
|
|
|
target_type="SINGLE PROTEIN", |
79
|
|
|
) |
80
|
|
|
x_row1 = dict( |
81
|
|
|
target_chembl_id="CHEMBL2093872", |
82
|
|
|
pref_name="GABA-A receptor; anion channel", |
83
|
|
|
target_type="PROTEIN COMPLEX GROUP", |
84
|
|
|
) |
85
|
|
|
x_row1_superset = dict( |
|
|
|
|
86
|
|
|
target_chembl_id="CHEMBL1111", pref_name="supergroup", target_type="SELECTIVITY FILTER" |
87
|
|
|
) |
88
|
|
|
x_row2 = dict( |
|
|
|
|
89
|
|
|
target_chembl_id="CHEMBL2094122", |
90
|
|
|
pref_name="GABA-A receptor; alpha-5/beta-3/gamma-2", |
91
|
|
|
target_type="PROTEIN COMPLEX", |
92
|
|
|
) |
93
|
|
|
x_row3 = dict( |
|
|
|
|
94
|
|
|
target_chembl_id="CHEMBL2109243", |
95
|
|
|
pref_name="GABA-A receptor; benzodiazepine site", |
96
|
|
|
target_type="PROTEIN COMPLEX GROUP", |
97
|
|
|
) |
98
|
|
|
x_row4 = dict( |
99
|
|
|
target_chembl_id="CHEMBL2109244", |
100
|
|
|
pref_name="GABA-A receptor; agonist GABA site", |
101
|
|
|
target_type="PROTEIN COMPLEX GROUP", |
102
|
|
|
) |
103
|
|
|
x_row5 = dict( |
|
|
|
|
104
|
|
|
target_chembl_id="CHEMBL3885576", |
105
|
|
|
pref_name="Gamma-aminobutyric acid receptor subunit alpha-5/beta-2", |
106
|
|
|
target_type="PROTEIN COMPLEX", |
107
|
|
|
) |
108
|
|
|
x_row6 = dict( |
|
|
|
|
109
|
|
|
target_chembl_id="CHEMBL3885577", |
110
|
|
|
pref_name="Gamma-aminobutyric acid receptor subunit alpha-5/beta-3/gamma-3", |
111
|
|
|
target_type="PROTEIN COMPLEX", |
112
|
|
|
) |
113
|
|
|
x_row7 = dict( |
|
|
|
|
114
|
|
|
target_chembl_id="CHEMBL4296057", |
115
|
|
|
pref_name="Gamma-aminobutyric acid receptor subunit alpha-5/beta-3", |
116
|
|
|
target_type="PROTEIN COMPLEX", |
117
|
|
|
) |
118
|
|
|
xrow2_row2 = x_row1 |
|
|
|
|
119
|
|
|
xrow3_row3 = x_row1 |
|
|
|
|
120
|
|
|
xrow4_row5 = x_row1 |
|
|
|
|
121
|
|
|
xrow5_row3 = x_row1 |
|
|
|
|
122
|
|
|
xrow5_row7 = x_row4 |
|
|
|
|
123
|
|
|
relations = [ |
|
|
|
|
124
|
|
|
dict(relationship="SUBSET OF", related_target_chembl_id="CHEMBL1111"), |
125
|
|
|
dict(relationship="SUBSET OF", related_target_chembl_id="CHEMBL0000"), |
126
|
|
|
] |
127
|
|
|
# TODO |
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
if __name__ == "__main__": |
131
|
|
|
pytest.main() |
132
|
|
|
|