pori-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pori_python/__init__.py +1 -0
- pori_python/graphkb/__init__.py +2 -0
- pori_python/graphkb/constants.py +220 -0
- pori_python/graphkb/genes.py +540 -0
- pori_python/graphkb/match.py +710 -0
- pori_python/graphkb/py.typed +0 -0
- pori_python/graphkb/statement.py +48 -0
- pori_python/graphkb/util.py +523 -0
- pori_python/graphkb/vocab.py +198 -0
- pori_python/ipr/__init__.py +0 -0
- pori_python/ipr/annotate.py +373 -0
- pori_python/ipr/connection.py +214 -0
- pori_python/ipr/constants.py +9 -0
- pori_python/ipr/inputs.py +593 -0
- pori_python/ipr/ipr.py +390 -0
- pori_python/ipr/main.py +512 -0
- pori_python/ipr/py.typed +0 -0
- pori_python/ipr/summary.py +412 -0
- pori_python/ipr/therapeutic_options.py +83 -0
- pori_python/ipr/util.py +173 -0
- pori_python/types.py +177 -0
- pori_python-0.1.0.dist-info/LICENSE +674 -0
- pori_python-0.1.0.dist-info/METADATA +151 -0
- pori_python-0.1.0.dist-info/RECORD +49 -0
- pori_python-0.1.0.dist-info/WHEEL +5 -0
- pori_python-0.1.0.dist-info/dependency_links.txt +1 -0
- pori_python-0.1.0.dist-info/entry_points.txt +2 -0
- pori_python-0.1.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/test_graphkb/__init__.py +0 -0
- tests/test_graphkb/data.py +78 -0
- tests/test_graphkb/test_genes.py +306 -0
- tests/test_graphkb/test_graphkb.py +32 -0
- tests/test_graphkb/test_match.py +662 -0
- tests/test_graphkb/test_statement.py +100 -0
- tests/test_graphkb/test_util.py +151 -0
- tests/test_graphkb/test_vocab.py +85 -0
- tests/test_ipr/__init__.py +0 -0
- tests/test_ipr/constants.py +3 -0
- tests/test_ipr/test_annotate.py +149 -0
- tests/test_ipr/test_connection.py +97 -0
- tests/test_ipr/test_inputs.py +295 -0
- tests/test_ipr/test_ipr.py +338 -0
- tests/test_ipr/test_main.py +154 -0
- tests/test_ipr/test_probe.py +72 -0
- tests/test_ipr/test_summary.py +157 -0
- tests/test_ipr/test_upload.py +274 -0
- tests/test_ipr/test_util.py +29 -0
- tests/test_ipr/util.py +9 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import re
|
|
4
|
+
from typing import List
|
|
5
|
+
from unittest.mock import MagicMock
|
|
6
|
+
|
|
7
|
+
import pori_python.graphkb
|
|
8
|
+
from pori_python.graphkb import GraphKBConnection, match
|
|
9
|
+
from pori_python.graphkb.constants import (
|
|
10
|
+
DEFAULT_NON_STRUCTURAL_VARIANT_TYPE,
|
|
11
|
+
STRUCTURAL_VARIANT_SIZE_THRESHOLD,
|
|
12
|
+
)
|
|
13
|
+
from pori_python.graphkb.util import FeatureNotFoundError
|
|
14
|
+
|
|
15
|
+
# Test datasets
|
|
16
|
+
from .data import structuralVariants
|
|
17
|
+
|
|
18
|
+
EXCLUDE_BCGSC_TESTS = os.environ.get("EXCLUDE_BCGSC_TESTS") == "1"
|
|
19
|
+
EXCLUDE_INTEGRATION_TESTS = os.environ.get("EXCLUDE_INTEGRATION_TESTS") == "1"
|
|
20
|
+
|
|
21
|
+
INCREASE_PREFIXES = ["up", "increase", "over", "gain", "amp"]
|
|
22
|
+
DECREASE_PREFIXES = ["down", "decrease", "reduce", "under", "loss", "delet"]
|
|
23
|
+
GENERAL_MUTATION = "mutation"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def has_prefix(word: str, prefixes: List[str]) -> bool:
|
|
27
|
+
for prefix in prefixes:
|
|
28
|
+
if re.search(r"\b" + prefix, word):
|
|
29
|
+
return True
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.fixture(scope="module")
|
|
34
|
+
def conn() -> GraphKBConnection:
|
|
35
|
+
conn = GraphKBConnection()
|
|
36
|
+
conn.login(os.environ["GRAPHKB_USER"], os.environ["GRAPHKB_PASS"])
|
|
37
|
+
return conn
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.fixture(scope="class")
|
|
41
|
+
def kras(conn):
|
|
42
|
+
return [f["displayName"] for f in match.get_equivalent_features(conn, "kras")]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
"""
|
|
46
|
+
version found in the db for ENSG00000133703 will vary depending on which
|
|
47
|
+
version of ensembl was loaded. checking for any . version
|
|
48
|
+
"""
|
|
49
|
+
kras_ensg_version = r"ENSG00000133703\..*"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class TestGetEquivalentFeatures:
|
|
53
|
+
def test_kras_has_self(self, kras):
|
|
54
|
+
assert "KRAS" in kras
|
|
55
|
+
|
|
56
|
+
def test_expands_aliases(self, kras):
|
|
57
|
+
assert "KRAS2" in kras
|
|
58
|
+
|
|
59
|
+
def test_expands_elements(self, kras):
|
|
60
|
+
assert "NM_033360" in kras
|
|
61
|
+
assert "ENST00000311936" in kras
|
|
62
|
+
|
|
63
|
+
def test_expands_generalizations(self, kras):
|
|
64
|
+
assert "NM_033360.4" in kras
|
|
65
|
+
ensg_version_found = False
|
|
66
|
+
for item in kras:
|
|
67
|
+
if re.match(kras_ensg_version, item):
|
|
68
|
+
ensg_version_found = True
|
|
69
|
+
assert ensg_version_found
|
|
70
|
+
|
|
71
|
+
def test_expands_generalizations_kras(self, kras):
|
|
72
|
+
assert "NM_033360.4" in kras
|
|
73
|
+
assert "NM_033360" in kras
|
|
74
|
+
ensg_version_found = False
|
|
75
|
+
for item in kras:
|
|
76
|
+
if re.match(kras_ensg_version, item):
|
|
77
|
+
ensg_version_found = True
|
|
78
|
+
assert ensg_version_found
|
|
79
|
+
assert "ENSG00000133703" in kras
|
|
80
|
+
|
|
81
|
+
@pytest.mark.parametrize(
|
|
82
|
+
"alt_rep", ("NM_033360.4", "NM_033360", "ENSG00000133703.11", "ENSG00000133703")
|
|
83
|
+
)
|
|
84
|
+
def test_expands_generalizations_refseq(self, alt_rep, conn):
|
|
85
|
+
kras = [f["displayName"] for f in match.get_equivalent_features(conn, alt_rep)]
|
|
86
|
+
assert "NM_033360.4" in kras
|
|
87
|
+
assert "NM_033360" in kras
|
|
88
|
+
ensg_version_found = False
|
|
89
|
+
for item in kras:
|
|
90
|
+
if re.match(kras_ensg_version, item):
|
|
91
|
+
ensg_version_found = True
|
|
92
|
+
assert ensg_version_found
|
|
93
|
+
assert "ENSG00000133703" in kras
|
|
94
|
+
|
|
95
|
+
def test_checks_by_source_id_kras(self, conn):
|
|
96
|
+
kras = [
|
|
97
|
+
f["displayName"]
|
|
98
|
+
for f in match.get_equivalent_features(
|
|
99
|
+
conn, "nm_033360", source="refseq", source_id_version="4", is_source_id=True
|
|
100
|
+
)
|
|
101
|
+
]
|
|
102
|
+
assert "KRAS" in kras
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class TestMatchCopyVariant:
|
|
106
|
+
def test_bad_category(self, conn):
|
|
107
|
+
with pytest.raises(ValueError):
|
|
108
|
+
match.match_copy_variant(conn, "kras", "not a copy number")
|
|
109
|
+
|
|
110
|
+
def test_bad_gene_name(self, conn):
|
|
111
|
+
with pytest.raises(FeatureNotFoundError):
|
|
112
|
+
match.match_copy_variant(conn, "not a real gene name", match.INPUT_COPY_CATEGORIES.AMP)
|
|
113
|
+
|
|
114
|
+
@pytest.mark.skipif(
|
|
115
|
+
EXCLUDE_BCGSC_TESTS,
|
|
116
|
+
reason="excluding BCGSC-specific tests - no copy loss variants in other data",
|
|
117
|
+
)
|
|
118
|
+
def test_known_loss(self, conn):
|
|
119
|
+
matches = match.match_copy_variant(conn, "CDKN2A", match.INPUT_COPY_CATEGORIES.ANY_LOSS)
|
|
120
|
+
assert matches
|
|
121
|
+
|
|
122
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
123
|
+
zygositys = {record["zygosity"] for record in matches}
|
|
124
|
+
|
|
125
|
+
assert match.INPUT_COPY_CATEGORIES.ANY_LOSS in types_selected
|
|
126
|
+
assert match.INPUT_COPY_CATEGORIES.AMP not in types_selected
|
|
127
|
+
assert GENERAL_MUTATION not in types_selected
|
|
128
|
+
|
|
129
|
+
assert "homozygous" in zygositys
|
|
130
|
+
|
|
131
|
+
for variant_type in types_selected:
|
|
132
|
+
assert not has_prefix(variant_type, INCREASE_PREFIXES)
|
|
133
|
+
|
|
134
|
+
@pytest.mark.skipif(
|
|
135
|
+
EXCLUDE_BCGSC_TESTS,
|
|
136
|
+
reason="excluding BCGSC-specific tests - no copy loss variants in other data",
|
|
137
|
+
)
|
|
138
|
+
def test_known_loss_zygosity_filtered(self, conn):
|
|
139
|
+
matches = match.match_copy_variant(
|
|
140
|
+
conn, "CDKN2A", match.INPUT_COPY_CATEGORIES.ANY_LOSS, True
|
|
141
|
+
)
|
|
142
|
+
assert matches
|
|
143
|
+
|
|
144
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
145
|
+
zygositys = {record["zygosity"] for record in matches}
|
|
146
|
+
|
|
147
|
+
assert "homozygous" not in zygositys
|
|
148
|
+
|
|
149
|
+
assert GENERAL_MUTATION not in types_selected
|
|
150
|
+
assert match.INPUT_COPY_CATEGORIES.ANY_LOSS in types_selected
|
|
151
|
+
assert match.INPUT_COPY_CATEGORIES.AMP not in types_selected
|
|
152
|
+
|
|
153
|
+
for variant_type in types_selected:
|
|
154
|
+
assert not has_prefix(variant_type, INCREASE_PREFIXES)
|
|
155
|
+
|
|
156
|
+
def test_known_gain(self, conn):
|
|
157
|
+
matches = match.match_copy_variant(conn, "KRAS", "copy gain")
|
|
158
|
+
assert matches
|
|
159
|
+
|
|
160
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
161
|
+
|
|
162
|
+
assert GENERAL_MUTATION not in types_selected
|
|
163
|
+
assert match.INPUT_COPY_CATEGORIES.AMP in types_selected
|
|
164
|
+
assert match.INPUT_COPY_CATEGORIES.ANY_LOSS not in types_selected
|
|
165
|
+
|
|
166
|
+
for variant_type in types_selected:
|
|
167
|
+
assert not has_prefix(variant_type, DECREASE_PREFIXES)
|
|
168
|
+
|
|
169
|
+
@pytest.mark.skipif(
|
|
170
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
171
|
+
)
|
|
172
|
+
def test_low_gain_excludes_amplification(self, conn):
|
|
173
|
+
matches = match.match_copy_variant(conn, "KRAS", match.INPUT_COPY_CATEGORIES.GAIN)
|
|
174
|
+
|
|
175
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
176
|
+
|
|
177
|
+
assert match.INPUT_COPY_CATEGORIES.AMP not in types_selected
|
|
178
|
+
assert match.INPUT_COPY_CATEGORIES.LOSS not in types_selected
|
|
179
|
+
assert GENERAL_MUTATION not in types_selected
|
|
180
|
+
|
|
181
|
+
for variant_type in types_selected:
|
|
182
|
+
assert not has_prefix(variant_type, DECREASE_PREFIXES)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@pytest.mark.parametrize("pos1,pos2_start,pos2_end", [[3, 2, 5], [2, None, 5], [3, 2, None]])
|
|
186
|
+
def test_range_overlap(pos1, pos2_start, pos2_end):
|
|
187
|
+
assert match.positions_overlap({"pos": pos1}, {"pos": pos2_start}, {"pos": pos2_end})
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@pytest.mark.parametrize(
|
|
191
|
+
"pos1,pos2_start,pos2_end",
|
|
192
|
+
[[2, 4, 5], [5, 2, 3], [10, None, 9], [10, 11, None], [1, 2, 2], [2, 1, 1]],
|
|
193
|
+
)
|
|
194
|
+
def test_range_not_overlap(pos1, pos2_start, pos2_end):
|
|
195
|
+
assert not match.positions_overlap({"pos": pos1}, {"pos": pos2_start}, {"pos": pos2_end})
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@pytest.mark.parametrize("pos1", [None, 1])
|
|
199
|
+
@pytest.mark.parametrize("pos2", [None, 1])
|
|
200
|
+
def test_position_match(pos1, pos2):
|
|
201
|
+
assert match.positions_overlap({"pos": pos1}, {"pos": pos2})
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class TestMatchExpressionVariant:
|
|
205
|
+
def test_bad_category(self, conn):
|
|
206
|
+
with pytest.raises(ValueError):
|
|
207
|
+
match.match_expression_variant(conn, "PTEN", "not a expression category")
|
|
208
|
+
|
|
209
|
+
def test_bad_gene_name(self, conn):
|
|
210
|
+
with pytest.raises(FeatureNotFoundError):
|
|
211
|
+
match.match_expression_variant(
|
|
212
|
+
conn, "not a real gene name", match.INPUT_EXPRESSION_CATEGORIES.UP
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
@pytest.mark.skipif(
|
|
216
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
217
|
+
)
|
|
218
|
+
@pytest.mark.skipif(
|
|
219
|
+
EXCLUDE_BCGSC_TESTS, reason="variants in db for this test are from IPRKB and ESMO"
|
|
220
|
+
)
|
|
221
|
+
def test_known_reduced_expression(self, conn):
|
|
222
|
+
matches = match.match_expression_variant(
|
|
223
|
+
conn, "PTEN", match.INPUT_EXPRESSION_CATEGORIES.DOWN
|
|
224
|
+
)
|
|
225
|
+
assert matches
|
|
226
|
+
|
|
227
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
228
|
+
|
|
229
|
+
assert match.INPUT_EXPRESSION_CATEGORIES.UP not in types_selected
|
|
230
|
+
assert GENERAL_MUTATION not in types_selected
|
|
231
|
+
|
|
232
|
+
for variant_type in types_selected:
|
|
233
|
+
assert not has_prefix(variant_type, INCREASE_PREFIXES)
|
|
234
|
+
|
|
235
|
+
@pytest.mark.skipif(
|
|
236
|
+
EXCLUDE_BCGSC_TESTS, reason="excluding BCGSC-specific tests - no applicable variants"
|
|
237
|
+
)
|
|
238
|
+
def test_known_reduced_expression_gene_id(self, conn):
|
|
239
|
+
gene_id = conn.query({"target": "Feature", "filters": [{"name": "PTEN"}]})[0]["@rid"]
|
|
240
|
+
matches = match.match_expression_variant(
|
|
241
|
+
conn, gene_id, match.INPUT_EXPRESSION_CATEGORIES.DOWN
|
|
242
|
+
)
|
|
243
|
+
assert matches
|
|
244
|
+
|
|
245
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
246
|
+
|
|
247
|
+
assert match.INPUT_EXPRESSION_CATEGORIES.UP not in types_selected
|
|
248
|
+
assert GENERAL_MUTATION not in types_selected
|
|
249
|
+
|
|
250
|
+
for variant_type in types_selected:
|
|
251
|
+
assert not has_prefix(variant_type, INCREASE_PREFIXES)
|
|
252
|
+
|
|
253
|
+
@pytest.mark.skipif(
|
|
254
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
255
|
+
)
|
|
256
|
+
def test_known_increased_expression(self, conn):
|
|
257
|
+
matches = match.match_expression_variant(conn, "CA9", match.INPUT_EXPRESSION_CATEGORIES.UP)
|
|
258
|
+
assert matches
|
|
259
|
+
|
|
260
|
+
types_selected = {record["type"]["name"] for record in matches}
|
|
261
|
+
|
|
262
|
+
assert match.INPUT_EXPRESSION_CATEGORIES.UP not in types_selected
|
|
263
|
+
assert GENERAL_MUTATION not in types_selected
|
|
264
|
+
|
|
265
|
+
for variant_type in types_selected:
|
|
266
|
+
assert not has_prefix(variant_type, DECREASE_PREFIXES)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class TestComparePositionalVariants:
|
|
270
|
+
def test_nonspecific_altseq(self):
|
|
271
|
+
assert match.compare_positional_variants(
|
|
272
|
+
{"break1Start": {"pos": 1}}, {"break1Start": {"pos": 1}}
|
|
273
|
+
)
|
|
274
|
+
# null matches anything
|
|
275
|
+
assert match.compare_positional_variants(
|
|
276
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "T"}, {"break1Start": {"pos": 1}}
|
|
277
|
+
)
|
|
278
|
+
assert match.compare_positional_variants(
|
|
279
|
+
{"break1Start": {"pos": 1}}, {"break1Start": {"pos": 1}, "untemplatedSeq": "T"}
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
@pytest.mark.parametrize("seq1", ["T", "X", "?"])
|
|
283
|
+
@pytest.mark.parametrize("seq2", ["T", "X", "?"])
|
|
284
|
+
def test_ambiguous_altseq(self, seq1, seq2):
|
|
285
|
+
# ambiguous AA matches anything the same length
|
|
286
|
+
assert match.compare_positional_variants(
|
|
287
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": seq1},
|
|
288
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": seq2},
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
def test_altseq_length_mismatch(self):
|
|
292
|
+
assert not match.compare_positional_variants(
|
|
293
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "??"},
|
|
294
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "T"},
|
|
295
|
+
)
|
|
296
|
+
assert not match.compare_positional_variants(
|
|
297
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "?"},
|
|
298
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "TT"},
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
def test_nonspecific_refseq(self):
|
|
302
|
+
# null matches anything
|
|
303
|
+
assert match.compare_positional_variants(
|
|
304
|
+
{"break1Start": {"pos": 1}, "refSeq": "T"}, {"break1Start": {"pos": 1}}
|
|
305
|
+
)
|
|
306
|
+
assert match.compare_positional_variants(
|
|
307
|
+
{"break1Start": {"pos": 1}}, {"break1Start": {"pos": 1}, "refSeq": "T"}
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
@pytest.mark.parametrize("seq1", ["T", "X", "?"])
|
|
311
|
+
@pytest.mark.parametrize("seq2", ["T", "X", "?"])
|
|
312
|
+
def test_ambiguous_refseq(self, seq1, seq2):
|
|
313
|
+
# ambiguous AA matches anything the same length
|
|
314
|
+
assert match.compare_positional_variants(
|
|
315
|
+
{"break1Start": {"pos": 1}, "refSeq": seq1}, {"break1Start": {"pos": 1}, "refSeq": seq2}
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
def test_refseq_length_mismatch(self):
|
|
319
|
+
assert not match.compare_positional_variants(
|
|
320
|
+
{"break1Start": {"pos": 1}, "refSeq": "??"}, {"break1Start": {"pos": 1}, "refSeq": "T"}
|
|
321
|
+
)
|
|
322
|
+
assert not match.compare_positional_variants(
|
|
323
|
+
{"break1Start": {"pos": 1}, "refSeq": "?"}, {"break1Start": {"pos": 1}, "refSeq": "TT"}
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
def test_diff_altseq(self):
|
|
327
|
+
assert not match.compare_positional_variants(
|
|
328
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "M"},
|
|
329
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "R"},
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
def test_same_altseq_matches(self):
|
|
333
|
+
assert match.compare_positional_variants(
|
|
334
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "R"},
|
|
335
|
+
{"break1Start": {"pos": 1}, "untemplatedSeq": "R"},
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
def test_diff_refseq(self):
|
|
339
|
+
assert not match.compare_positional_variants(
|
|
340
|
+
{"break1Start": {"pos": 1}, "refSeq": "M"}, {"break1Start": {"pos": 1}, "refSeq": "R"}
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
def test_same_refseq_matches(self):
|
|
344
|
+
assert match.compare_positional_variants(
|
|
345
|
+
{"break1Start": {"pos": 1}, "refSeq": "R"}, {"break1Start": {"pos": 1}, "refSeq": "R"}
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
def test_range_vs_sub(self):
|
|
349
|
+
sub = {
|
|
350
|
+
"break1Repr": "p.G776",
|
|
351
|
+
"break1Start": {"@Class": "ProteinPosition", "pos": 776, "refAA": "G"},
|
|
352
|
+
"break2Repr": "p.V777",
|
|
353
|
+
"break2Start": {"@Class": "ProteinPosition", "pos": 777, "refAA": "V"},
|
|
354
|
+
"reference1": "ERBB2",
|
|
355
|
+
"type": "insertion",
|
|
356
|
+
"untemplatedSeq": "YVMA",
|
|
357
|
+
"untemplatedSeqSize": 4,
|
|
358
|
+
}
|
|
359
|
+
range_variant = {
|
|
360
|
+
"break1Repr": "p.G776",
|
|
361
|
+
"break1Start": {"@Class": "ProteinPosition", "pos": 776, "refAA": "G"},
|
|
362
|
+
"break2Repr": "p.?776",
|
|
363
|
+
"break2Start": None,
|
|
364
|
+
"refSeq": "G",
|
|
365
|
+
"untemplatedSeq": "VV",
|
|
366
|
+
}
|
|
367
|
+
assert not match.compare_positional_variants(sub, range_variant)
|
|
368
|
+
assert not match.compare_positional_variants(range_variant, sub)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
class TestMatchPositionalVariant:
|
|
372
|
+
def test_error_on_duplicate_reference1(self, conn):
|
|
373
|
+
with pytest.raises(ValueError):
|
|
374
|
+
match.match_positional_variant(conn, "KRAS:p.G12D", "#123:34")
|
|
375
|
+
|
|
376
|
+
def test_error_on_bad_reference2(self, conn):
|
|
377
|
+
with pytest.raises(ValueError):
|
|
378
|
+
match.match_positional_variant(conn, "KRAS:p.G12D", reference2="#123:34")
|
|
379
|
+
|
|
380
|
+
def test_error_on_duplicate_reference2(self, conn):
|
|
381
|
+
with pytest.raises(ValueError):
|
|
382
|
+
match.match_positional_variant(
|
|
383
|
+
conn, "(BCR,ABL1):fusion(e.13,e.3)", reference2="#123:34"
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
def test_uncertain_position_not_supported(self, conn):
|
|
387
|
+
with pytest.raises(NotImplementedError):
|
|
388
|
+
match.match_positional_variant(conn, "(BCR,ABL1):fusion(e.13_24,e.3)")
|
|
389
|
+
|
|
390
|
+
def test_bad_gene_name(self, conn):
|
|
391
|
+
with pytest.raises(FeatureNotFoundError):
|
|
392
|
+
match.match_positional_variant(conn, "ME-AS-A-GENE:p.G12D")
|
|
393
|
+
|
|
394
|
+
def test_bad_gene2_name(self, conn):
|
|
395
|
+
with pytest.raises(FeatureNotFoundError):
|
|
396
|
+
match.match_positional_variant(conn, "(BCR,ME-AS-A-GENE):fusion(e.13,e.3)")
|
|
397
|
+
|
|
398
|
+
def test_match_explicit_reference1(self, conn):
|
|
399
|
+
reference1 = conn.query({"target": "Feature", "filters": {"name": "KRAS"}})[0]["@rid"]
|
|
400
|
+
matches = match.match_positional_variant(conn, "p.G12D", reference1=reference1)
|
|
401
|
+
assert matches
|
|
402
|
+
|
|
403
|
+
@pytest.mark.skipif(
|
|
404
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
405
|
+
)
|
|
406
|
+
def test_match_explicit_references(self, conn):
|
|
407
|
+
reference1 = conn.query({"target": "Feature", "filters": {"name": "BCR"}})[0]["@rid"]
|
|
408
|
+
reference2 = conn.query({"target": "Feature", "filters": {"name": "ABL1"}})[0]["@rid"]
|
|
409
|
+
matches = match.match_positional_variant(
|
|
410
|
+
conn, "fusion(e.13,e.3)", reference1=reference1, reference2=reference2
|
|
411
|
+
)
|
|
412
|
+
assert matches
|
|
413
|
+
|
|
414
|
+
@pytest.mark.skipif(
|
|
415
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
416
|
+
)
|
|
417
|
+
@pytest.mark.parametrize(
|
|
418
|
+
"known_variant,related_variants,unrelated_variants",
|
|
419
|
+
[
|
|
420
|
+
["KRAS:p.G12D", ["KRAS:p.G12X", "chr12:g.25398284C>T"], ["KRAS:p.G12V"]],
|
|
421
|
+
["KRAS:p.G13D", ["KRAS:p.?13mut"], []],
|
|
422
|
+
["chr12:g.25398284C>T", ["KRAS:p.G12D"], ["KRAS:p.G12V"]],
|
|
423
|
+
["EGFR:p.E746_S752delinsI", ["EGFR mutation"], ["EGFR copy variant"]],
|
|
424
|
+
],
|
|
425
|
+
)
|
|
426
|
+
@pytest.mark.skipif(
|
|
427
|
+
EXCLUDE_BCGSC_TESTS, reason="TODO: fix loader for vars ending in X, p.?, copy variant"
|
|
428
|
+
)
|
|
429
|
+
def test_known_variants(self, conn, known_variant, related_variants, unrelated_variants):
|
|
430
|
+
matches = match.match_positional_variant(conn, known_variant)
|
|
431
|
+
names = {m["displayName"] for m in matches}
|
|
432
|
+
assert matches
|
|
433
|
+
assert known_variant in names
|
|
434
|
+
for variant in related_variants:
|
|
435
|
+
assert variant in names
|
|
436
|
+
for variant in unrelated_variants:
|
|
437
|
+
assert variant not in names
|
|
438
|
+
|
|
439
|
+
@pytest.mark.skipif(
|
|
440
|
+
EXCLUDE_BCGSC_TESTS, reason="TODO: add nonIPRKB fusion tests; source for these is IPRKB"
|
|
441
|
+
)
|
|
442
|
+
@pytest.mark.parametrize(
|
|
443
|
+
"known_variant,related_variants",
|
|
444
|
+
[
|
|
445
|
+
["(BCR,ABL1):fusion(e.13,e.3)", ["BCR and ABL1 fusion"]],
|
|
446
|
+
["(ATP1B1,NRG1):fusion(e.2,e.2)", ["NRG1 fusion", "ATP1B1 and NRG1 fusion"]],
|
|
447
|
+
],
|
|
448
|
+
)
|
|
449
|
+
def test_known_fusions(self, conn, known_variant, related_variants):
|
|
450
|
+
matches = match.match_positional_variant(conn, known_variant)
|
|
451
|
+
types_selected = [m["type"]["name"] for m in matches]
|
|
452
|
+
assert GENERAL_MUTATION not in types_selected
|
|
453
|
+
names = {m["displayName"] for m in matches}
|
|
454
|
+
assert matches
|
|
455
|
+
assert known_variant in names
|
|
456
|
+
for variant in related_variants:
|
|
457
|
+
assert variant in names
|
|
458
|
+
|
|
459
|
+
def test_known_fusion_single_gene_no_match(self, conn):
|
|
460
|
+
known = "(TERT,?):fusion(e.1,e.?)"
|
|
461
|
+
matches = match.match_positional_variant(conn, known)
|
|
462
|
+
assert not matches
|
|
463
|
+
|
|
464
|
+
def test_novel_specific_matches_general(self, conn):
|
|
465
|
+
novel_specific = "CDKN2A:p.T18888888888888888888M"
|
|
466
|
+
matches = match.match_positional_variant(conn, novel_specific)
|
|
467
|
+
names = {m["displayName"] for m in matches}
|
|
468
|
+
assert matches
|
|
469
|
+
assert novel_specific not in names
|
|
470
|
+
assert "CDKN2A mutation" in names
|
|
471
|
+
|
|
472
|
+
@pytest.mark.skipif(
|
|
473
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
474
|
+
)
|
|
475
|
+
def test_genomic_coordinates(self, conn):
|
|
476
|
+
genomic = "X:g.100611165A>T"
|
|
477
|
+
x = match.match_positional_variant(conn, genomic)
|
|
478
|
+
assert x != []
|
|
479
|
+
# no assert b/c checking for no error rather than the result (but also want to confirm some result returned)
|
|
480
|
+
|
|
481
|
+
@pytest.mark.skipif(
|
|
482
|
+
EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests"
|
|
483
|
+
)
|
|
484
|
+
@pytest.mark.skipif(EXCLUDE_BCGSC_TESTS, reason="source for this variant is IPRKB")
|
|
485
|
+
def test_tert_promoter(self, conn):
|
|
486
|
+
assert match.match_positional_variant(conn, "TERT:c.-124C>T")
|
|
487
|
+
|
|
488
|
+
def test_wildtype_match_error(self, conn):
|
|
489
|
+
for gkb_match in match.match_positional_variant(conn, "TP53:p.E285K"):
|
|
490
|
+
assert (
|
|
491
|
+
"wildtype" not in gkb_match["displayName"]
|
|
492
|
+
), f"TP53:p.E285K should not match {gkb_match['displayName']}"
|
|
493
|
+
|
|
494
|
+
@pytest.mark.skipif(
|
|
495
|
+
True, reason="GERO-303 - technically incorrect notation for GSC backwards compatibility."
|
|
496
|
+
)
|
|
497
|
+
def test_tert_promoter_leading_one_alt_notation(self, conn):
|
|
498
|
+
# GERO-303 - technically this format is incorrect.
|
|
499
|
+
assert match.match_positional_variant(conn, "TERT:c.1-124C>T")
|
|
500
|
+
|
|
501
|
+
def test_missense_is_not_nonsense(self, conn):
|
|
502
|
+
"""GERO-299 - nonsense mutation creates a stop codon and is usually more severe."""
|
|
503
|
+
# equivalent TP53 notations
|
|
504
|
+
genomic = "chr17:g.7674252C>T"
|
|
505
|
+
cds = "ENST00000269305:c.711G>A"
|
|
506
|
+
protein = "TP53:p.M237I"
|
|
507
|
+
for mut in (protein, genomic, cds):
|
|
508
|
+
matches = match.match_positional_variant(conn, mut)
|
|
509
|
+
nonsense = [m for m in matches if "nonsense" in m["displayName"]]
|
|
510
|
+
assert (
|
|
511
|
+
not nonsense
|
|
512
|
+
), f"Missense {mut} is not a nonsense variant: {((m['displayName'], m['@rid']) for m in nonsense)}"
|
|
513
|
+
|
|
514
|
+
@pytest.mark.skipif(EXCLUDE_BCGSC_TESTS, reason="TODO: missing record for FGFR3 rearrangement")
|
|
515
|
+
def test_structural_variants(self, conn):
|
|
516
|
+
"""KBDEV-1056"""
|
|
517
|
+
for variant_string, expected in structuralVariants.items():
|
|
518
|
+
print(variant_string)
|
|
519
|
+
# Querying matches for variant_string
|
|
520
|
+
m = match.match_positional_variant(conn, variant_string)
|
|
521
|
+
MatchingDisplayNames = [el["displayName"] for el in m]
|
|
522
|
+
MatchingTypes = [el["type"]["name"] for el in m]
|
|
523
|
+
|
|
524
|
+
# Match
|
|
525
|
+
for displayName in expected.get("matches", {}).get("displayName", []):
|
|
526
|
+
assert displayName in MatchingDisplayNames
|
|
527
|
+
for type in expected.get("matches", {}).get("type", []):
|
|
528
|
+
assert type in MatchingTypes
|
|
529
|
+
|
|
530
|
+
# Does not match
|
|
531
|
+
for displayName in MatchingDisplayNames:
|
|
532
|
+
assert displayName not in expected.get("does_not_matches", {}).get(
|
|
533
|
+
"displayName", []
|
|
534
|
+
)
|
|
535
|
+
for type in MatchingTypes:
|
|
536
|
+
assert type not in expected.get("does_not_matches", {}).get("type", [])
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
class TestCacheMissingFeatures:
|
|
540
|
+
def test_filling_cache(self):
|
|
541
|
+
mock_conn = MagicMock(
|
|
542
|
+
query=MagicMock(
|
|
543
|
+
return_value=[
|
|
544
|
+
{"name": "bob", "sourceId": "alice"},
|
|
545
|
+
{"name": "KRAS", "sourceId": "1234"},
|
|
546
|
+
]
|
|
547
|
+
)
|
|
548
|
+
)
|
|
549
|
+
match.cache_missing_features(mock_conn)
|
|
550
|
+
assert "kras" in match.FEATURES_CACHE
|
|
551
|
+
assert "alice" in match.FEATURES_CACHE
|
|
552
|
+
match.FEATURES_CACHE = None
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
class TestTypeScreening:
|
|
556
|
+
# Types as class variables
|
|
557
|
+
default_type = DEFAULT_NON_STRUCTURAL_VARIANT_TYPE
|
|
558
|
+
threshold = STRUCTURAL_VARIANT_SIZE_THRESHOLD
|
|
559
|
+
unambiguous_structural = ["fusion", "translocation"]
|
|
560
|
+
ambiguous_structural = ["duplication", "deletion", "insertion", "indel"]
|
|
561
|
+
non_structural = ["substitution", "missense", "nonsense", "frameshift", "truncating"]
|
|
562
|
+
|
|
563
|
+
def test_type_screening_update(self, conn, monkeypatch):
|
|
564
|
+
# Monkey-patching get_terms_set()
|
|
565
|
+
def mock_get_terms_set(graphkb_conn, base_terms):
|
|
566
|
+
nonlocal called
|
|
567
|
+
called = True
|
|
568
|
+
return set()
|
|
569
|
+
|
|
570
|
+
monkeypatch.setattr("pori_python.graphkb.match.get_terms_set", mock_get_terms_set)
|
|
571
|
+
|
|
572
|
+
# Assert get_terms_set() has been called
|
|
573
|
+
called = False
|
|
574
|
+
pori_python.graphkb.match.type_screening(conn, {"type": ""}, updateStructuralTypes=True)
|
|
575
|
+
assert called
|
|
576
|
+
|
|
577
|
+
# Assert get_terms_set() has not been called (default behavior)
|
|
578
|
+
called = False
|
|
579
|
+
pori_python.graphkb.match.type_screening(conn, {"type": ""})
|
|
580
|
+
assert not called
|
|
581
|
+
|
|
582
|
+
def test_type_screening_non_structural(self, conn):
|
|
583
|
+
for type in TestTypeScreening.non_structural:
|
|
584
|
+
# type substitution and alike
|
|
585
|
+
assert match.type_screening(conn, {"type": type}) == type
|
|
586
|
+
|
|
587
|
+
def test_type_screening_structural(self, conn):
|
|
588
|
+
for type in TestTypeScreening.unambiguous_structural:
|
|
589
|
+
# type fusion and alike
|
|
590
|
+
assert match.type_screening(conn, {"type": type}) == type
|
|
591
|
+
for type in TestTypeScreening.ambiguous_structural:
|
|
592
|
+
# w/ reference2
|
|
593
|
+
assert match.type_screening(conn, {"type": type, "reference2": "#123:45"}) == type
|
|
594
|
+
# w/ cytoband coordinates
|
|
595
|
+
assert match.type_screening(conn, {"type": type, "prefix": "y"}) == type
|
|
596
|
+
|
|
597
|
+
def test_type_screening_structural_ambiguous_size(self, conn):
|
|
598
|
+
for type in TestTypeScreening.ambiguous_structural:
|
|
599
|
+
# coordinate system with ambiguous size
|
|
600
|
+
for prefix in ["e", "i"]:
|
|
601
|
+
assert (
|
|
602
|
+
match.type_screening(
|
|
603
|
+
conn,
|
|
604
|
+
{
|
|
605
|
+
"type": type,
|
|
606
|
+
"break2Start": {"pos": TestTypeScreening.threshold},
|
|
607
|
+
"prefix": prefix,
|
|
608
|
+
},
|
|
609
|
+
)
|
|
610
|
+
== TestTypeScreening.default_type
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
def test_type_screening_structural_untemplatedSeqSize(self, conn):
|
|
614
|
+
for type in TestTypeScreening.ambiguous_structural:
|
|
615
|
+
# Variation length too small (< threshold)
|
|
616
|
+
assert (
|
|
617
|
+
match.type_screening(
|
|
618
|
+
conn, {"type": type, "untemplatedSeqSize": TestTypeScreening.threshold - 1}
|
|
619
|
+
)
|
|
620
|
+
== TestTypeScreening.default_type
|
|
621
|
+
)
|
|
622
|
+
# Variation length big enough (>= threshold)
|
|
623
|
+
assert (
|
|
624
|
+
match.type_screening(
|
|
625
|
+
conn, {"type": type, "untemplatedSeqSize": TestTypeScreening.threshold}
|
|
626
|
+
)
|
|
627
|
+
== type
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
def test_type_screening_structural_positions(self, conn):
|
|
631
|
+
for type in TestTypeScreening.ambiguous_structural:
|
|
632
|
+
# Variation length too small (< threshold)
|
|
633
|
+
for opt in [
|
|
634
|
+
{"break2Start": {"pos": TestTypeScreening.threshold - 1}},
|
|
635
|
+
{"break2Start": {"pos": TestTypeScreening.threshold - 1}, "prefix": "c"},
|
|
636
|
+
{"break2Start": {"pos": TestTypeScreening.threshold - 1}, "prefix": "g"},
|
|
637
|
+
{"break2Start": {"pos": TestTypeScreening.threshold - 1}, "prefix": "n"},
|
|
638
|
+
{"break2Start": {"pos": TestTypeScreening.threshold - 1}, "prefix": "r"},
|
|
639
|
+
{"break2Start": {"pos": int(TestTypeScreening.threshold / 3) - 1}, "prefix": "p"},
|
|
640
|
+
{
|
|
641
|
+
"break1Start": {"pos": 1 + 99},
|
|
642
|
+
"break2Start": {"pos": TestTypeScreening.threshold + 99 - 1},
|
|
643
|
+
},
|
|
644
|
+
]:
|
|
645
|
+
assert (
|
|
646
|
+
match.type_screening(conn, {"type": type, **opt})
|
|
647
|
+
== TestTypeScreening.default_type
|
|
648
|
+
)
|
|
649
|
+
# Variation length big enough (>= threshold)
|
|
650
|
+
for opt in [
|
|
651
|
+
{"break2Start": {"pos": TestTypeScreening.threshold}},
|
|
652
|
+
{"break2Start": {"pos": TestTypeScreening.threshold}, "prefix": "c"},
|
|
653
|
+
{"break2Start": {"pos": TestTypeScreening.threshold}, "prefix": "g"},
|
|
654
|
+
{"break2Start": {"pos": TestTypeScreening.threshold}, "prefix": "n"},
|
|
655
|
+
{"break2Start": {"pos": TestTypeScreening.threshold}, "prefix": "r"},
|
|
656
|
+
{"break2Start": {"pos": int(TestTypeScreening.threshold / 3) + 1}, "prefix": "p"},
|
|
657
|
+
{
|
|
658
|
+
"break1Start": {"pos": 1 + 99},
|
|
659
|
+
"break2Start": {"pos": TestTypeScreening.threshold + 99},
|
|
660
|
+
},
|
|
661
|
+
]:
|
|
662
|
+
assert match.type_screening(conn, {"type": type, **opt}) == type
|