|
1
|
|
|
from typing import Mapping |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
import pytest |
|
|
|
|
|
|
4
|
|
|
from chembl_webresource_client.new_client import new_client as Chembl |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
from mandos.chembl_api import ChemblApi, ChemblEntrypoint |
|
|
|
|
|
|
7
|
|
|
from mandos.model.targets import ( |
|
|
|
|
|
|
8
|
|
|
DagTarget, |
|
9
|
|
|
DagTargetLinkType, |
|
10
|
|
|
Target, |
|
11
|
|
|
TargetFactory, |
|
12
|
|
|
TargetRelationshipType, |
|
13
|
|
|
TargetType, |
|
14
|
|
|
) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class TestTargets: |
|
|
|
|
|
|
18
|
|
|
def test_traverse_gabaa_up(self): |
|
|
|
|
|
|
19
|
|
|
target = TargetFactory.find("CHEMBL2109243", Chembl) |
|
20
|
|
|
assert target.chembl == "CHEMBL2109243" |
|
21
|
|
|
link_types = DagTargetLinkType.cross( |
|
22
|
|
|
TargetType.protein_types(), |
|
23
|
|
|
{TargetRelationshipType.subset_of}, |
|
24
|
|
|
TargetType.protein_types(), |
|
25
|
|
|
) |
|
26
|
|
|
accepted = target.traverse(link_types) |
|
27
|
|
|
assert {t.target.chembl for t in accepted} == {"CHEMBL2109243", "CHEMBL2093872"} |
|
28
|
|
|
|
|
29
|
|
|
def test_traverse_gabaa_up_mouse(self): |
|
|
|
|
|
|
30
|
|
|
# a single protein |
|
31
|
|
|
# branches to GABA A channel complex group CHEMBL2094133 |
|
32
|
|
|
# but also to complexes CHEMBL4296058 and CHEMBL4296059 |
|
33
|
|
|
# weirdly, CHEMBL4296058 then joins up with CHEMBL2094133 |
|
34
|
|
|
# but CHEMBL4296059 does not (it only joins through an OVERLAPS WITH rel) |
|
35
|
|
|
# so that one SHOULD be an "end" (which wouldn't be true in a real traversal strategy, hopefully) |
|
|
|
|
|
|
36
|
|
|
target = TargetFactory.find("CHEMBL3139", Chembl) |
|
37
|
|
|
assert target.chembl == "CHEMBL3139" |
|
38
|
|
|
link_types = DagTargetLinkType.cross( |
|
39
|
|
|
TargetType.protein_types(), |
|
40
|
|
|
{TargetRelationshipType.subset_of}, |
|
41
|
|
|
TargetType.protein_types(), |
|
42
|
|
|
) |
|
43
|
|
|
accepted = target.traverse(link_types) |
|
44
|
|
|
vals: Mapping[str, DagTarget] = {a.target.chembl: a for a in accepted} |
|
45
|
|
|
assert {t.target.chembl for t in accepted} == { |
|
46
|
|
|
"CHEMBL2094133", |
|
47
|
|
|
"CHEMBL3139", |
|
48
|
|
|
"CHEMBL4296058", |
|
49
|
|
|
"CHEMBL4296059", |
|
50
|
|
|
} |
|
51
|
|
|
assert not vals["CHEMBL3139"].is_end |
|
52
|
|
|
assert vals["CHEMBL2094133"].is_end |
|
53
|
|
|
assert not vals["CHEMBL4296058"].is_end |
|
54
|
|
|
assert vals["CHEMBL4296059"].is_end |
|
55
|
|
|
assert vals["CHEMBL3139"].depth == 0 |
|
56
|
|
|
assert vals["CHEMBL2094133"].depth == 1 # breadth-first! |
|
57
|
|
|
assert vals["CHEMBL2094133"].depth == 1 |
|
58
|
|
|
assert vals["CHEMBL4296058"].depth == 1 |
|
59
|
|
|
assert vals["CHEMBL3139"].link_type is None |
|
60
|
|
|
assert vals["CHEMBL2094133"].link_type == DagTargetLinkType( |
|
61
|
|
|
TargetType.single_protein, |
|
62
|
|
|
TargetRelationshipType.subset_of, |
|
63
|
|
|
TargetType.protein_complex_group, |
|
64
|
|
|
) |
|
65
|
|
|
assert vals["CHEMBL4296058"].link_type == DagTargetLinkType( |
|
66
|
|
|
TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex |
|
67
|
|
|
) |
|
68
|
|
|
assert vals["CHEMBL4296059"].link_type == DagTargetLinkType( |
|
69
|
|
|
TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex |
|
70
|
|
|
) |
|
71
|
|
|
|
|
72
|
|
|
def test_traverse_gabaa_up_mouse_2(self): |
|
|
|
|
|
|
73
|
|
|
# this is about the same, but now we'll allow that OVERLAPS WITH rel |
|
74
|
|
|
# so we won't find them here |
|
75
|
|
|
target = TargetFactory.find("CHEMBL3139", Chembl) |
|
76
|
|
|
assert target.chembl == "CHEMBL3139" |
|
77
|
|
|
link_types = DagTargetLinkType.cross( |
|
78
|
|
|
TargetType.protein_types(), |
|
79
|
|
|
{TargetRelationshipType.subset_of}, |
|
80
|
|
|
TargetType.protein_types(), |
|
81
|
|
|
) |
|
82
|
|
|
link_types.add( |
|
83
|
|
|
DagTargetLinkType( |
|
84
|
|
|
TargetType.protein_complex, |
|
85
|
|
|
TargetRelationshipType.overlaps_with, |
|
86
|
|
|
TargetType.protein_complex_group, |
|
87
|
|
|
) |
|
88
|
|
|
) |
|
89
|
|
|
accepted = target.traverse(link_types) |
|
90
|
|
|
vals: Mapping[str, DagTarget] = {a.target.chembl: a for a in accepted} |
|
91
|
|
|
assert {t.target.chembl for t in accepted} == { |
|
92
|
|
|
"CHEMBL2094133", |
|
93
|
|
|
"CHEMBL3139", |
|
94
|
|
|
"CHEMBL4296058", |
|
95
|
|
|
"CHEMBL4296059", |
|
96
|
|
|
} |
|
97
|
|
|
assert not vals["CHEMBL3139"].is_end |
|
98
|
|
|
assert vals["CHEMBL2094133"].is_end |
|
99
|
|
|
assert not vals["CHEMBL4296058"].is_end |
|
100
|
|
|
# here's the difference: |
|
101
|
|
|
# by adding the OVERLAPS WITH rel, it now knows it's not at the end |
|
102
|
|
|
assert not vals["CHEMBL4296059"].is_end |
|
103
|
|
|
assert vals["CHEMBL3139"].depth == 0 |
|
104
|
|
|
assert vals["CHEMBL2094133"].depth == 1 # breadth-first! |
|
105
|
|
|
assert vals["CHEMBL2094133"].depth == 1 |
|
106
|
|
|
assert vals["CHEMBL4296058"].depth == 1 |
|
107
|
|
|
assert vals["CHEMBL3139"].link_type is None |
|
108
|
|
|
assert vals["CHEMBL2094133"].link_type == DagTargetLinkType( |
|
109
|
|
|
TargetType.single_protein, |
|
110
|
|
|
TargetRelationshipType.subset_of, |
|
111
|
|
|
TargetType.protein_complex_group, |
|
112
|
|
|
) |
|
113
|
|
|
assert vals["CHEMBL4296058"].link_type == DagTargetLinkType( |
|
114
|
|
|
TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex |
|
115
|
|
|
) |
|
116
|
|
|
assert vals["CHEMBL4296059"].link_type == DagTargetLinkType( |
|
117
|
|
|
TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex |
|
118
|
|
|
) |
|
119
|
|
|
|
|
120
|
|
|
def test_traverse_gabaa_up_and_down(self): |
|
|
|
|
|
|
121
|
|
|
target = TargetFactory.find("CHEMBL2109243", Chembl) |
|
122
|
|
|
link_types = DagTargetLinkType.cross( |
|
123
|
|
|
TargetType.protein_types(), |
|
124
|
|
|
{TargetRelationshipType.subset_of, TargetRelationshipType.superset_of}, |
|
125
|
|
|
TargetType.protein_types(), |
|
126
|
|
|
) |
|
127
|
|
|
accepted = target.traverse(link_types) |
|
128
|
|
|
# based on the docs I wrote, originally by looking thru the search results |
|
129
|
|
|
assert len(accepted) > 40 |
|
130
|
|
|
assert len(accepted) < 60 |
|
131
|
|
|
assert {"GABA" in t.target.name.upper() for t in accepted} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
if __name__ == "__main__": |
|
135
|
|
|
pytest.main() |
|
136
|
|
|
|