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,100 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
from unittest.mock import Mock
|
|
4
|
+
|
|
5
|
+
from pori_python.graphkb import GraphKBConnection, statement
|
|
6
|
+
|
|
7
|
+
EXCLUDE_INTEGRATION_TESTS = os.environ.get("EXCLUDE_INTEGRATION_TESTS") == "1"
|
|
8
|
+
EXCLUDE_BCGSC_TESTS = os.environ.get("EXCLUDE_BCGSC_TESTS") == "1"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture(scope="module")
|
|
12
|
+
def conn() -> GraphKBConnection:
|
|
13
|
+
conn = GraphKBConnection()
|
|
14
|
+
conn.login(os.environ["GRAPHKB_USER"], os.environ["GRAPHKB_PASS"])
|
|
15
|
+
return conn
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.fixture()
|
|
19
|
+
def graphkb_conn():
|
|
20
|
+
def make_rid_list(*values):
|
|
21
|
+
return [{"@rid": v} for v in values]
|
|
22
|
+
|
|
23
|
+
def term_tree_calls(*final_values):
|
|
24
|
+
# this function makes 2 calls to conn.query here
|
|
25
|
+
sets = [["fake"], final_values]
|
|
26
|
+
return [make_rid_list(*s) for s in sets]
|
|
27
|
+
|
|
28
|
+
return_values = [
|
|
29
|
+
*term_tree_calls("1"), # therapeutic
|
|
30
|
+
*term_tree_calls("2"), # therapeutic (2nd base term)
|
|
31
|
+
*term_tree_calls("3"), # diagnostic
|
|
32
|
+
*term_tree_calls("4"), # prognostic
|
|
33
|
+
*term_tree_calls("5"), # pharmacogenomic ['metabolism']
|
|
34
|
+
*term_tree_calls("6"), # pharmacogenomic ['toxicity']
|
|
35
|
+
*term_tree_calls("7"), # pharmacogenomic ['dosage']
|
|
36
|
+
*term_tree_calls("8"), # cancer predisposition
|
|
37
|
+
*term_tree_calls(), # biological
|
|
38
|
+
*term_tree_calls(), # biological (2nd base term)
|
|
39
|
+
*term_tree_calls(), # biological (3rd base term)
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
query_mock = Mock()
|
|
43
|
+
query_mock.side_effect = return_values
|
|
44
|
+
return Mock(query=query_mock, cache={})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestCategorizeRelevance:
|
|
48
|
+
def test_default_categories(self, graphkb_conn):
|
|
49
|
+
category = statement.categorize_relevance(graphkb_conn, "1")
|
|
50
|
+
assert category == "therapeutic"
|
|
51
|
+
|
|
52
|
+
def test_first_match_returns(self, graphkb_conn):
|
|
53
|
+
category = statement.categorize_relevance(graphkb_conn, "2")
|
|
54
|
+
assert category == "therapeutic"
|
|
55
|
+
|
|
56
|
+
def test_second_category(self, graphkb_conn):
|
|
57
|
+
category = statement.categorize_relevance(graphkb_conn, "3")
|
|
58
|
+
assert category == "diagnostic"
|
|
59
|
+
|
|
60
|
+
def test_third_category(self, graphkb_conn):
|
|
61
|
+
category = statement.categorize_relevance(graphkb_conn, "4")
|
|
62
|
+
assert category == "prognostic"
|
|
63
|
+
|
|
64
|
+
def test_fourth_category(self, graphkb_conn):
|
|
65
|
+
category = statement.categorize_relevance(graphkb_conn, "5")
|
|
66
|
+
assert category == "pharmacogenomic"
|
|
67
|
+
|
|
68
|
+
def test_fifth_category(self, graphkb_conn):
|
|
69
|
+
category = statement.categorize_relevance(graphkb_conn, "6")
|
|
70
|
+
assert category == "pharmacogenomic"
|
|
71
|
+
|
|
72
|
+
def test_predisposition_category(self, graphkb_conn):
|
|
73
|
+
category = statement.categorize_relevance(graphkb_conn, "8")
|
|
74
|
+
assert category == "cancer predisposition"
|
|
75
|
+
|
|
76
|
+
def test_no_match(self, graphkb_conn):
|
|
77
|
+
category = statement.categorize_relevance(graphkb_conn, "x")
|
|
78
|
+
assert category == ""
|
|
79
|
+
|
|
80
|
+
def test_custom_categories(self, graphkb_conn):
|
|
81
|
+
category = statement.categorize_relevance(
|
|
82
|
+
graphkb_conn, "x", [("blargh", ["some", "blargh"])]
|
|
83
|
+
)
|
|
84
|
+
assert category == ""
|
|
85
|
+
|
|
86
|
+
category = statement.categorize_relevance(
|
|
87
|
+
graphkb_conn, "1", [("blargh", ["some", "blargh"])]
|
|
88
|
+
)
|
|
89
|
+
assert category == "blargh"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@pytest.mark.skipif(
|
|
93
|
+
EXCLUDE_BCGSC_TESTS, reason="db-specific rid; requires Inferred Functional Annotation source"
|
|
94
|
+
)
|
|
95
|
+
@pytest.mark.skipif(EXCLUDE_INTEGRATION_TESTS, reason="excluding long running integration tests")
|
|
96
|
+
class TestStatementMatch:
|
|
97
|
+
def test_truncating_categories(self, conn): # noqa - pytest fixture, not redefinition
|
|
98
|
+
variant = {"@class": "CategoryVariant", "@rid": "#161:429", "displayName": "RB1 truncating"}
|
|
99
|
+
statements = statement.get_statements_from_variants(conn, [variant])
|
|
100
|
+
assert statements
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from pori_python.graphkb import GraphKBConnection, util
|
|
5
|
+
|
|
6
|
+
EXCLUDE_BCGSC_TESTS = os.environ.get("EXCLUDE_BCGSC_TESTS") == "1"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OntologyTerm:
|
|
10
|
+
def __init__(self, name, sourceId, displayName):
|
|
11
|
+
self.name = name
|
|
12
|
+
self.sourceId = sourceId
|
|
13
|
+
self.displayName = displayName
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture(scope="module")
|
|
17
|
+
def conn() -> GraphKBConnection:
|
|
18
|
+
conn = GraphKBConnection()
|
|
19
|
+
conn.login(os.environ["GRAPHKB_USER"], os.environ["GRAPHKB_PASS"])
|
|
20
|
+
return conn
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class TestLooksLikeRid:
|
|
24
|
+
@pytest.mark.parametrize("rid", ["#3:4", "#50:04", "#-3:4", "#-3:-4", "#3:-4"])
|
|
25
|
+
def test_valid(self, rid):
|
|
26
|
+
assert util.looks_like_rid(rid)
|
|
27
|
+
|
|
28
|
+
@pytest.mark.parametrize("rid", ["-3:4", "KRAS"])
|
|
29
|
+
def test_invalid(self, rid):
|
|
30
|
+
assert not util.looks_like_rid(rid)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize(
|
|
34
|
+
"input,result",
|
|
35
|
+
[
|
|
36
|
+
["GP5:p.Leu113His", "GP5:p.L113H"],
|
|
37
|
+
["GP5:p.Lys113His", "GP5:p.K113H"],
|
|
38
|
+
["CDK11A:p.Arg536Gln", "CDK11A:p.R536Q"],
|
|
39
|
+
["APC:p.Cys1405*", "APC:p.C1405*"],
|
|
40
|
+
["ApcTer:p.Cys1405*", "ApcTer:p.C1405*"],
|
|
41
|
+
["GP5:p.Leu113_His114insLys", "GP5:p.L113_H114insK"],
|
|
42
|
+
["NP_003997.1:p.Lys23_Val25del", "NP_003997.1:p.K23_V25del"],
|
|
43
|
+
["LRG_199p1:p.Val7del", "LRG_199p1:p.V7del"],
|
|
44
|
+
],
|
|
45
|
+
)
|
|
46
|
+
def test_convert_aa_3to1(input, result):
|
|
47
|
+
assert util.convert_aa_3to1(input) == result
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class TestStripParentheses:
|
|
51
|
+
@pytest.mark.parametrize(
|
|
52
|
+
"breakRepr,StrippedBreakRepr",
|
|
53
|
+
[
|
|
54
|
+
["p.(E2015_Q2114)", "p.E2015_Q2114"],
|
|
55
|
+
["p.(?572_?630)", "p.?572_?630"],
|
|
56
|
+
["g.178916854", "g.178916854"],
|
|
57
|
+
["e.10", "e.10"],
|
|
58
|
+
],
|
|
59
|
+
)
|
|
60
|
+
def test_stripParentheses(self, breakRepr, StrippedBreakRepr):
|
|
61
|
+
assert util.stripParentheses(breakRepr) == StrippedBreakRepr
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class TestStripRefSeq:
|
|
65
|
+
@pytest.mark.parametrize(
|
|
66
|
+
"breakRepr,StrippedBreakRepr",
|
|
67
|
+
[
|
|
68
|
+
["p.L2209", "p.2209"],
|
|
69
|
+
["p.?891", "p.891"],
|
|
70
|
+
# TODO: ['p.?572_?630', 'p.572_630'],
|
|
71
|
+
],
|
|
72
|
+
)
|
|
73
|
+
def test_stripRefSeq(self, breakRepr, StrippedBreakRepr):
|
|
74
|
+
assert util.stripRefSeq(breakRepr) == StrippedBreakRepr
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class TestStripDisplayName:
|
|
78
|
+
@pytest.mark.parametrize(
|
|
79
|
+
"opt,stripDisplayName",
|
|
80
|
+
[
|
|
81
|
+
[{"displayName": "ABL1:p.T315I", "withRef": True, "withRefSeq": True}, "ABL1:p.T315I"],
|
|
82
|
+
[{"displayName": "ABL1:p.T315I", "withRef": False, "withRefSeq": True}, "p.T315I"],
|
|
83
|
+
[{"displayName": "ABL1:p.T315I", "withRef": True, "withRefSeq": False}, "ABL1:p.315I"],
|
|
84
|
+
[{"displayName": "ABL1:p.T315I", "withRef": False, "withRefSeq": False}, "p.315I"],
|
|
85
|
+
[
|
|
86
|
+
{"displayName": "chr3:g.41266125C>T", "withRef": False, "withRefSeq": False},
|
|
87
|
+
"g.41266125>T",
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
"displayName": "chrX:g.99662504_99662505insG",
|
|
92
|
+
"withRef": False,
|
|
93
|
+
"withRefSeq": False,
|
|
94
|
+
},
|
|
95
|
+
"g.99662504_99662505insG",
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
{
|
|
99
|
+
"displayName": "chrX:g.99662504_99662505dup",
|
|
100
|
+
"withRef": False,
|
|
101
|
+
"withRefSeq": False,
|
|
102
|
+
},
|
|
103
|
+
"g.99662504_99662505dup",
|
|
104
|
+
],
|
|
105
|
+
# TODO: [{'displayName': 'VHL:c.330_331delCAinsTT', 'withRef': False, 'withRefSeq': False}, 'c.330_331delinsTT'],
|
|
106
|
+
# TODO: [{'displayName': 'VHL:c.464-2G>A', 'withRef': False, 'withRefSeq': False}, 'c.464-2>A'],
|
|
107
|
+
],
|
|
108
|
+
)
|
|
109
|
+
def test_stripDisplayName(self, opt, stripDisplayName):
|
|
110
|
+
assert util.stripDisplayName(**opt) == stripDisplayName
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class TestStringifyVariant:
|
|
114
|
+
@pytest.mark.parametrize(
|
|
115
|
+
"hgvs_string,opt,stringifiedVariant",
|
|
116
|
+
[
|
|
117
|
+
["VHL:c.345C>G", {"withRef": True, "withRefSeq": True}, "VHL:c.345C>G"],
|
|
118
|
+
["VHL:c.345C>G", {"withRef": False, "withRefSeq": True}, "c.345C>G"],
|
|
119
|
+
["VHL:c.345C>G", {"withRef": True, "withRefSeq": False}, "VHL:c.345>G"],
|
|
120
|
+
["VHL:c.345C>G", {"withRef": False, "withRefSeq": False}, "c.345>G"],
|
|
121
|
+
[
|
|
122
|
+
"(LMNA,NTRK1):fusion(e.10,e.12)",
|
|
123
|
+
{"withRef": False, "withRefSeq": False},
|
|
124
|
+
"fusion(e.10,e.12)",
|
|
125
|
+
],
|
|
126
|
+
["ABCA12:p.N1671Ifs*4", {"withRef": False, "withRefSeq": False}, "p.1671Ifs*4"],
|
|
127
|
+
["x:y.p22.33copyloss", {"withRef": False, "withRefSeq": False}, "y.p22.33copyloss"],
|
|
128
|
+
# TODO: ['MED12:p.(?34_?68)mut', {'withRef': False, 'withRefSeq': False}, 'p.(34_68)mut'],
|
|
129
|
+
# TODO: ['FLT3:p.(?572_?630)_(?572_?630)ins', {'withRef': False, 'withRefSeq': False}, 'p.(572_630)_(572_630)ins'],
|
|
130
|
+
],
|
|
131
|
+
)
|
|
132
|
+
def test_stringifyVariant_parsed(self, conn, hgvs_string, opt, stringifiedVariant):
|
|
133
|
+
opt["variant"] = conn.parse(hgvs_string)
|
|
134
|
+
assert util.stringifyVariant(**opt) == stringifiedVariant
|
|
135
|
+
|
|
136
|
+
# Based on the assumption that these variants are in the database.
|
|
137
|
+
# createdAt date help avoiding errors if assumption tuns to be false
|
|
138
|
+
@pytest.mark.parametrize(
|
|
139
|
+
"rid,createdAt,stringifiedVariant",
|
|
140
|
+
[
|
|
141
|
+
["#157:0", 1565627324397, "p.315I"],
|
|
142
|
+
["#157:79", 1565627683602, "p.776_777insVGC"],
|
|
143
|
+
["#158:35317", 1652734056311, "c.1>G"],
|
|
144
|
+
],
|
|
145
|
+
)
|
|
146
|
+
@pytest.mark.skipif(EXCLUDE_BCGSC_TESTS, reason="db-dependent rids")
|
|
147
|
+
def test_stringifyVariant_positional(self, conn, rid, createdAt, stringifiedVariant):
|
|
148
|
+
opt = {"withRef": False, "withRefSeq": False}
|
|
149
|
+
variant = conn.get_record_by_id(rid)
|
|
150
|
+
if variant and variant.get("createdAt", None) == createdAt:
|
|
151
|
+
assert util.stringifyVariant(variant=variant, **opt) == stringifiedVariant
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests here depend on specific data in GraphKB which can change. To avoid this, expected/stable values are chosen
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from pori_python.graphkb import GraphKBConnection, genes, vocab
|
|
9
|
+
|
|
10
|
+
BASE_EXPRESSION = "expression variant"
|
|
11
|
+
BASE_INCREASED_EXPRESSION = "increased expression"
|
|
12
|
+
BASE_REDUCED_EXPRESSION = "reduced expression"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.fixture(scope="module")
|
|
16
|
+
def conn():
|
|
17
|
+
conn = GraphKBConnection()
|
|
18
|
+
conn.login(os.environ["GRAPHKB_USER"], os.environ["GRAPHKB_PASS"])
|
|
19
|
+
return conn
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_expression_vocabulary(conn):
|
|
23
|
+
result = vocab.get_term_tree(conn, BASE_EXPRESSION)
|
|
24
|
+
|
|
25
|
+
names = [row["name"] for row in result]
|
|
26
|
+
assert BASE_EXPRESSION in names
|
|
27
|
+
assert "increased rna expression" in names
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_indel_vocabulary(conn):
|
|
31
|
+
result = vocab.get_term_tree(conn, "indel")
|
|
32
|
+
|
|
33
|
+
names = {row["name"] for row in result}
|
|
34
|
+
assert "indel" in names
|
|
35
|
+
assert "copy variant" not in names
|
|
36
|
+
assert "copy number variant" not in names
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_expression_up(conn):
|
|
40
|
+
result = vocab.get_term_tree(conn, BASE_INCREASED_EXPRESSION)
|
|
41
|
+
|
|
42
|
+
names = [row["name"] for row in result]
|
|
43
|
+
assert BASE_EXPRESSION in names
|
|
44
|
+
assert BASE_INCREASED_EXPRESSION in names
|
|
45
|
+
assert "increased rna expression" in names
|
|
46
|
+
assert "reduced rna expression" not in names
|
|
47
|
+
assert BASE_REDUCED_EXPRESSION not in names
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_expression_down(conn):
|
|
51
|
+
result = vocab.get_term_tree(conn, BASE_REDUCED_EXPRESSION)
|
|
52
|
+
|
|
53
|
+
names = [row["name"] for row in result]
|
|
54
|
+
assert BASE_EXPRESSION in names
|
|
55
|
+
assert BASE_REDUCED_EXPRESSION in names
|
|
56
|
+
assert BASE_INCREASED_EXPRESSION not in names
|
|
57
|
+
assert "increased rna expression" not in names
|
|
58
|
+
assert "reduced rna expression" in names
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class TestGetEquivalentTerms:
|
|
62
|
+
def test_gain_excludes_amplification(self, conn):
|
|
63
|
+
result = vocab.get_equivalent_terms(conn, "copy gain")
|
|
64
|
+
names = {row["name"] for row in result}
|
|
65
|
+
assert "copy gain" in names
|
|
66
|
+
assert "amplification" not in names
|
|
67
|
+
|
|
68
|
+
def test_amplification_includes_gain(self, conn):
|
|
69
|
+
result = vocab.get_equivalent_terms(conn, "amplification")
|
|
70
|
+
names = {row["name"] for row in result}
|
|
71
|
+
assert "copy gain" in names
|
|
72
|
+
assert "amplification" in names
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_oncogenic(conn):
|
|
76
|
+
result = vocab.get_term_by_name(conn, genes.ONCOGENE)
|
|
77
|
+
assert result["name"] == genes.ONCOGENE
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_get_terms_set(conn):
|
|
81
|
+
terms = vocab.get_terms_set(conn, ["copy variant"])
|
|
82
|
+
assert terms
|
|
83
|
+
more_terms = vocab.get_terms_set(conn, ["copy variant", "expression variant"])
|
|
84
|
+
assert more_terms
|
|
85
|
+
assert len(more_terms) > len(terms)
|
|
File without changes
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from pori_python.graphkb import GraphKBConnection
|
|
5
|
+
from pori_python.ipr.annotate import annotate_positional_variants
|
|
6
|
+
from pori_python.types import IprSmallMutationVariant
|
|
7
|
+
|
|
8
|
+
EXCLUDE_BCGSC_TESTS = os.environ.get("EXCLUDE_BCGSC_TESTS") == "1"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# TP53 examples from https://www.bcgsc.ca/jira/browse/SDEV-3122
|
|
12
|
+
# Mutations are actually identical but on alternate transcripts.
|
|
13
|
+
|
|
14
|
+
TP53_MUT_DICT = {
|
|
15
|
+
"pref": IprSmallMutationVariant( # type: ignore
|
|
16
|
+
{
|
|
17
|
+
"key": "SDEV-3122_preferred",
|
|
18
|
+
"gene": "TP53",
|
|
19
|
+
"hgvsGenomic": "chr17:g.7674252C>T",
|
|
20
|
+
"hgvsCds": "ENST00000269305:c.711G>A",
|
|
21
|
+
"hgvsProtein": "TP53:p.M237I",
|
|
22
|
+
}
|
|
23
|
+
),
|
|
24
|
+
"intersect": IprSmallMutationVariant( # type: ignore
|
|
25
|
+
{
|
|
26
|
+
"key": "SDEV-3122_alt",
|
|
27
|
+
"gene": "TP53",
|
|
28
|
+
"hgvsGenomic": "chr17:g.7674252C>T",
|
|
29
|
+
"hgvsCds": "ENST00000610292:c.594G>A",
|
|
30
|
+
"hgvsProtein": "TP53:p.M198I",
|
|
31
|
+
}
|
|
32
|
+
),
|
|
33
|
+
"prot_only": IprSmallMutationVariant( # type: ignore
|
|
34
|
+
{"key": "prot_only", "gene": "TP53", "hgvsProtein": "TP53:p.M237I"}
|
|
35
|
+
),
|
|
36
|
+
"cds_only": IprSmallMutationVariant( # type: ignore
|
|
37
|
+
{"key": "cds_only", "gene": "TP53", "hgvsCds": "ENST00000269305:c.711G>A"}
|
|
38
|
+
),
|
|
39
|
+
"genome_only": IprSmallMutationVariant( # type: ignore
|
|
40
|
+
{"key": "genome_only", "gene": "TP53", "hgvsGenomic": "chr17:g.7674252C>T"}
|
|
41
|
+
),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
KBDEV1231_TP53_ERR_MATCH_WT = {
|
|
45
|
+
"altSeq": "",
|
|
46
|
+
"chromosome": "chr17",
|
|
47
|
+
"comments": "",
|
|
48
|
+
"endPosition": "",
|
|
49
|
+
"gene": "TP53",
|
|
50
|
+
"germline": False,
|
|
51
|
+
"hgvsCds": "ENST00000269305:c.853G>A",
|
|
52
|
+
"hgvsGenomic": "chr17:g.7673767C>T",
|
|
53
|
+
"hgvsProtein": "TP53:p.E285K",
|
|
54
|
+
"key": "c23a7b0387335e7a5ed6c1081a1822ae",
|
|
55
|
+
"library": "F145233;F145265",
|
|
56
|
+
"ncbiBuild": "GRCh38",
|
|
57
|
+
"normalAltCount": "",
|
|
58
|
+
"normalDepth": "",
|
|
59
|
+
"normalRefCount": "",
|
|
60
|
+
"proteinChange": "p.E285K",
|
|
61
|
+
"refSeq": "",
|
|
62
|
+
"rnaAltCount": 311,
|
|
63
|
+
"rnaDepth": 370,
|
|
64
|
+
"rnaRefCount": 59,
|
|
65
|
+
"startPosition": "",
|
|
66
|
+
"transcript": "ENST00000269305",
|
|
67
|
+
"tumourAltCopies": "",
|
|
68
|
+
"tumourAltCount": 64,
|
|
69
|
+
"tumourDepth": 100,
|
|
70
|
+
"tumourRefCopies": "",
|
|
71
|
+
"tumourRefCount": 36,
|
|
72
|
+
"variant": "TP53:p.E285K",
|
|
73
|
+
"variantType": "mut",
|
|
74
|
+
"zygosity": "",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@pytest.fixture(scope="module")
|
|
79
|
+
def graphkb_conn():
|
|
80
|
+
username = os.environ.get("GRAPHKB_USER", os.environ["IPR_USER"])
|
|
81
|
+
password = os.environ.get("GRAPHKB_PASS", os.environ["IPR_PASS"])
|
|
82
|
+
graphkb_url = os.environ.get("GRAPHKB_URL", False)
|
|
83
|
+
if graphkb_url:
|
|
84
|
+
graphkb_conn = GraphKBConnection(graphkb_url)
|
|
85
|
+
else:
|
|
86
|
+
graphkb_conn = GraphKBConnection()
|
|
87
|
+
graphkb_conn.login(username, password)
|
|
88
|
+
return graphkb_conn
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@pytest.mark.skipif(
|
|
92
|
+
EXCLUDE_BCGSC_TESTS, reason="excluding tests that depend on BCGSC-specific data"
|
|
93
|
+
)
|
|
94
|
+
class TestAnnotation:
|
|
95
|
+
def test_annotate_nonsense_vs_missense(self, graphkb_conn):
|
|
96
|
+
"""Verify missense (point mutation) is not mistaken for a nonsense (stop codon) mutation."""
|
|
97
|
+
disease = "cancer"
|
|
98
|
+
for key in ("prot_only", "cds_only", "genome_only", "pref"):
|
|
99
|
+
matched = annotate_positional_variants(graphkb_conn, [TP53_MUT_DICT[key]], disease)
|
|
100
|
+
# nonsense - stop codon - should not match. This is missense not nonsense (#164:933).
|
|
101
|
+
nonsense = [a for a in matched if a["kbVariant"] == "TP53 nonsense"]
|
|
102
|
+
assert not nonsense, f"nonsense matched to {key}: {TP53_MUT_DICT[key]}"
|
|
103
|
+
assert matched, f"should have matched in {key}: {TP53_MUT_DICT[key]}"
|
|
104
|
+
|
|
105
|
+
def test_annotate_nonsense_vs_missense_protein(self, graphkb_conn):
|
|
106
|
+
"""Verify missense (point mutation) is not mistaken for a nonsense (stop codon) mutation."""
|
|
107
|
+
disease = "cancer"
|
|
108
|
+
for key in ("prot_only", "pref"):
|
|
109
|
+
matched = annotate_positional_variants(graphkb_conn, [TP53_MUT_DICT[key]], disease)
|
|
110
|
+
# nonsense - stop codon - should not match. This is missense not nonsense (#164:933).
|
|
111
|
+
nonsense = [a for a in matched if "nonsense" in a["kbVariant"]]
|
|
112
|
+
assert not nonsense, f"nonsense matched to {key}: {TP53_MUT_DICT[key]}"
|
|
113
|
+
assert matched, f"should have matched in {key}: {TP53_MUT_DICT[key]}"
|
|
114
|
+
|
|
115
|
+
def test_annotate_structural_variants_tp53(self, graphkb_conn):
|
|
116
|
+
"""Verify alternate TP53 variants match."""
|
|
117
|
+
disease = "cancer"
|
|
118
|
+
ref_key = "prot_only"
|
|
119
|
+
pref = annotate_positional_variants(graphkb_conn, [TP53_MUT_DICT[ref_key]], disease)
|
|
120
|
+
# GERO-299 - nonsense - stop codon - should not match. This is missense not nonsense (#164:933).
|
|
121
|
+
nonsense = [a for a in pref if a["kbVariant"] == "TP53 nonsense"]
|
|
122
|
+
assert not nonsense
|
|
123
|
+
pref_vars = set([m["kbVariant"] for m in pref])
|
|
124
|
+
assert pref_vars, f"No matches to {TP53_MUT_DICT[pref]}"
|
|
125
|
+
print(pref_vars)
|
|
126
|
+
for key, alt_rep in TP53_MUT_DICT.items():
|
|
127
|
+
if key == ref_key:
|
|
128
|
+
continue
|
|
129
|
+
alt = annotate_positional_variants(graphkb_conn, [alt_rep], disease)
|
|
130
|
+
alt_vars = set([m["kbVariant"] for m in alt])
|
|
131
|
+
diff = pref_vars.symmetric_difference(alt_vars)
|
|
132
|
+
missing = pref_vars.difference(alt_vars)
|
|
133
|
+
|
|
134
|
+
known_issues = set()
|
|
135
|
+
if key == "genome_only":
|
|
136
|
+
# genome_only matched to more precise type 'TP53 deleterious mutation' but not 'TP53 mutation'
|
|
137
|
+
known_issues.add("TP53 mutation")
|
|
138
|
+
|
|
139
|
+
missing = pref_vars.difference(alt_vars).difference(known_issues)
|
|
140
|
+
print(alt_vars)
|
|
141
|
+
assert not missing, f"{key} missing{missing}: {diff}"
|
|
142
|
+
|
|
143
|
+
def test_wt_not_matched(self, graphkb_conn):
|
|
144
|
+
"""Verify wildtypes are not matched to mutations."""
|
|
145
|
+
disease = "cancer"
|
|
146
|
+
matches = annotate_positional_variants(graphkb_conn, [KBDEV1231_TP53_ERR_MATCH_WT], disease)
|
|
147
|
+
# KBDEV-1231 - wildtype - should not match. A mutation is not wildtype
|
|
148
|
+
wt_matches = sorted(set([m["kbVariant"] for m in matches if "wildtype" in m["kbVariant"]]))
|
|
149
|
+
assert not wt_matches, f"Mutation 'TP53:p.E285K' should NOT match {wt_matches}"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
from unittest import mock
|
|
4
|
+
|
|
5
|
+
from pori_python.ipr.connection import IprConnection
|
|
6
|
+
|
|
7
|
+
IMAGE_DIR = os.path.join(os.path.dirname(__file__), "../../docs/images")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestPostImages:
|
|
11
|
+
def test_no_images_ok(self):
|
|
12
|
+
def request(*args, **kwargs):
|
|
13
|
+
m = mock.MagicMock(
|
|
14
|
+
json=lambda: [{"upload": "successful"}], raise_for_status=lambda: None
|
|
15
|
+
)
|
|
16
|
+
return m
|
|
17
|
+
|
|
18
|
+
with mock.patch("pori_python.ipr.connection.requests.request", request):
|
|
19
|
+
conn = IprConnection("user", "pass")
|
|
20
|
+
result = conn.post_images("report_id", files={}, data={})
|
|
21
|
+
assert result is None
|
|
22
|
+
|
|
23
|
+
def test_images_load_ok(self):
|
|
24
|
+
def request(*args, **kwargs):
|
|
25
|
+
m = mock.MagicMock(
|
|
26
|
+
json=lambda: [{"upload": "successful"}], raise_for_status=lambda: None
|
|
27
|
+
)
|
|
28
|
+
return m
|
|
29
|
+
|
|
30
|
+
with mock.patch("pori_python.ipr.connection.requests.request", request):
|
|
31
|
+
conn = IprConnection("user", "pass")
|
|
32
|
+
result = conn.post_images(
|
|
33
|
+
"report_id",
|
|
34
|
+
files={
|
|
35
|
+
"expression.correlation": os.path.join(IMAGE_DIR, "expression_correlation.png"),
|
|
36
|
+
"mixcr.circos_trb_vj_gene_usage": os.path.join(
|
|
37
|
+
IMAGE_DIR, "mixcr.circos_trb_vj_gene_usage.png"
|
|
38
|
+
),
|
|
39
|
+
},
|
|
40
|
+
data={},
|
|
41
|
+
)
|
|
42
|
+
assert result is None
|
|
43
|
+
|
|
44
|
+
def test_images_with_data_load_ok(self):
|
|
45
|
+
def request(*args, **kwargs):
|
|
46
|
+
m = mock.MagicMock(
|
|
47
|
+
json=lambda: [{"upload": "successful"}], raise_for_status=lambda: None
|
|
48
|
+
)
|
|
49
|
+
return m
|
|
50
|
+
|
|
51
|
+
with mock.patch("pori_python.ipr.connection.requests.request", request):
|
|
52
|
+
conn = IprConnection("user", "pass")
|
|
53
|
+
result = conn.post_images(
|
|
54
|
+
"report_id",
|
|
55
|
+
files={
|
|
56
|
+
"expression.correlation": os.path.join(IMAGE_DIR, "expression_correlation.png"),
|
|
57
|
+
"mixcr.circos_trb_vj_gene_usage": os.path.join(
|
|
58
|
+
IMAGE_DIR, "mixcr.circos_trb_vj_gene_usage.png"
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
data={"expression.correlation.title": "this is a title"},
|
|
62
|
+
)
|
|
63
|
+
assert result is None
|
|
64
|
+
|
|
65
|
+
def test_bad_file(self):
|
|
66
|
+
def request(*args, **kwargs):
|
|
67
|
+
m = mock.MagicMock(
|
|
68
|
+
json=lambda: [{"upload": "successful"}], raise_for_status=lambda: None
|
|
69
|
+
)
|
|
70
|
+
return m
|
|
71
|
+
|
|
72
|
+
with mock.patch("pori_python.ipr.connection.requests.request", request):
|
|
73
|
+
conn = IprConnection("user", "pass")
|
|
74
|
+
with pytest.raises(FileNotFoundError):
|
|
75
|
+
conn.post_images(
|
|
76
|
+
"report_id", files={"expression.correlation": "thing/that/does/not/exist.png"}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def test_failed_image_load(self):
|
|
80
|
+
def request(*args, **kwargs):
|
|
81
|
+
m = mock.MagicMock(
|
|
82
|
+
json=lambda: [{"upload": "anything else", "key": "thing"}],
|
|
83
|
+
raise_for_status=lambda: None,
|
|
84
|
+
)
|
|
85
|
+
return m
|
|
86
|
+
|
|
87
|
+
with mock.patch("pori_python.ipr.connection.requests.request", request):
|
|
88
|
+
conn = IprConnection("user", "pass")
|
|
89
|
+
with pytest.raises(ValueError):
|
|
90
|
+
conn.post_images(
|
|
91
|
+
"report_id",
|
|
92
|
+
{
|
|
93
|
+
"expression.correlation": os.path.join(
|
|
94
|
+
IMAGE_DIR, "expression_correlation.png"
|
|
95
|
+
)
|
|
96
|
+
},
|
|
97
|
+
)
|