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.
Files changed (49) hide show
  1. pori_python/__init__.py +1 -0
  2. pori_python/graphkb/__init__.py +2 -0
  3. pori_python/graphkb/constants.py +220 -0
  4. pori_python/graphkb/genes.py +540 -0
  5. pori_python/graphkb/match.py +710 -0
  6. pori_python/graphkb/py.typed +0 -0
  7. pori_python/graphkb/statement.py +48 -0
  8. pori_python/graphkb/util.py +523 -0
  9. pori_python/graphkb/vocab.py +198 -0
  10. pori_python/ipr/__init__.py +0 -0
  11. pori_python/ipr/annotate.py +373 -0
  12. pori_python/ipr/connection.py +214 -0
  13. pori_python/ipr/constants.py +9 -0
  14. pori_python/ipr/inputs.py +593 -0
  15. pori_python/ipr/ipr.py +390 -0
  16. pori_python/ipr/main.py +512 -0
  17. pori_python/ipr/py.typed +0 -0
  18. pori_python/ipr/summary.py +412 -0
  19. pori_python/ipr/therapeutic_options.py +83 -0
  20. pori_python/ipr/util.py +173 -0
  21. pori_python/types.py +177 -0
  22. pori_python-0.1.0.dist-info/LICENSE +674 -0
  23. pori_python-0.1.0.dist-info/METADATA +151 -0
  24. pori_python-0.1.0.dist-info/RECORD +49 -0
  25. pori_python-0.1.0.dist-info/WHEEL +5 -0
  26. pori_python-0.1.0.dist-info/dependency_links.txt +1 -0
  27. pori_python-0.1.0.dist-info/entry_points.txt +2 -0
  28. pori_python-0.1.0.dist-info/top_level.txt +2 -0
  29. tests/__init__.py +0 -0
  30. tests/test_graphkb/__init__.py +0 -0
  31. tests/test_graphkb/data.py +78 -0
  32. tests/test_graphkb/test_genes.py +306 -0
  33. tests/test_graphkb/test_graphkb.py +32 -0
  34. tests/test_graphkb/test_match.py +662 -0
  35. tests/test_graphkb/test_statement.py +100 -0
  36. tests/test_graphkb/test_util.py +151 -0
  37. tests/test_graphkb/test_vocab.py +85 -0
  38. tests/test_ipr/__init__.py +0 -0
  39. tests/test_ipr/constants.py +3 -0
  40. tests/test_ipr/test_annotate.py +149 -0
  41. tests/test_ipr/test_connection.py +97 -0
  42. tests/test_ipr/test_inputs.py +295 -0
  43. tests/test_ipr/test_ipr.py +338 -0
  44. tests/test_ipr/test_main.py +154 -0
  45. tests/test_ipr/test_probe.py +72 -0
  46. tests/test_ipr/test_summary.py +157 -0
  47. tests/test_ipr/test_upload.py +274 -0
  48. tests/test_ipr/test_util.py +29 -0
  49. tests/test_ipr/util.py +9 -0
@@ -0,0 +1,295 @@
1
+ import json
2
+ import numpy as np
3
+ import os
4
+ import pandas as pd
5
+ import pytest
6
+ from unittest import mock
7
+
8
+ from pori_python.graphkb.match import INPUT_COPY_CATEGORIES
9
+ from pori_python.ipr.inputs import (
10
+ COPY_OPTIONAL,
11
+ check_comparators,
12
+ check_variant_links,
13
+ create_graphkb_sv_notation,
14
+ preprocess_copy_variants,
15
+ preprocess_expression_variants,
16
+ preprocess_small_mutations,
17
+ preprocess_structural_variants,
18
+ validate_report_content,
19
+ )
20
+ from pori_python.ipr.util import logger
21
+ from pori_python.types import IprFusionVariant, IprGeneVariant
22
+
23
+ DATA_DIR = os.path.join(os.path.dirname(__file__), "test_data")
24
+ NON_EMPTY_STRING_NULLS = ["", None, np.nan, pd.NA]
25
+
26
+
27
+ def read_data_file(filename):
28
+ pass
29
+
30
+
31
+ class TestPreProcessSmallMutations:
32
+ def test_load_test_file(self) -> None:
33
+ records = preprocess_small_mutations(
34
+ pd.read_csv(os.path.join(DATA_DIR, "small_mutations.tab"), sep="\t").to_dict("records")
35
+ )
36
+ assert records
37
+ assert len(records) == 2614
38
+
39
+ def test_maintains_optional_fields(self):
40
+ original = {
41
+ "gene": "A1BG",
42
+ "proteinChange": "p.V460M",
43
+ "zygosity": "het",
44
+ "tumourAltCount": 42,
45
+ "tumourRefCount": 48,
46
+ "hgvsProtein": "",
47
+ "transcript": "ENST1000",
48
+ "hgvsCds": "",
49
+ "hgvsGenomic": "",
50
+ "key": "02fe85a3477784b5ac0f8ecffb300d10",
51
+ "variant": "blargh",
52
+ "chromosome": "2",
53
+ "startPosition": 1234,
54
+ }
55
+ records = preprocess_small_mutations([original])
56
+ record = records[0]
57
+ assert record["variantType"] == "mut"
58
+ for col in original:
59
+ assert col in record
60
+ assert record["variant"] == "A1BG:p.V460M"
61
+ assert "endPosition" in record
62
+ assert record["endPosition"] == record["startPosition"]
63
+ assert "tumourDepth" in record
64
+ assert record["tumourDepth"] == 90
65
+
66
+ def test_null(self):
67
+ original = {
68
+ "gene": "A1BG",
69
+ "proteinChange": "p.V460M",
70
+ "tumourAltCount": 42,
71
+ "tumourRefCount": 48,
72
+ "startPosition": 1234,
73
+ }
74
+ # Make sure TEST_KEYS are appropriate.
75
+ # For some fields, like 'ref' and 'alt', NA is _not_ equivalent to a null string.
76
+ TEST_KEYS = ["startPosition", "endPosition", "tumourAltCount", "tumourRefCount"]
77
+ for key in TEST_KEYS:
78
+ for null in NON_EMPTY_STRING_NULLS:
79
+ small_mut = original.copy()
80
+ small_mut[key] = null
81
+ records = preprocess_small_mutations([small_mut])
82
+ record = records[0]
83
+ assert record["variantType"] == "mut"
84
+ for col in original:
85
+ assert col in record
86
+ assert record["variant"] == "A1BG:p.V460M"
87
+ assert "endPosition" in record
88
+
89
+ def test_load_small_mutations_probe(self) -> None:
90
+ records = preprocess_small_mutations(
91
+ pd.read_csv(os.path.join(DATA_DIR, "small_mutations_probe.tab"), sep="\t").to_dict(
92
+ "records"
93
+ )
94
+ )
95
+ assert records
96
+ assert len(records) == 4
97
+ assert records[0]["variantType"] == "mut"
98
+ assert "variant" in records[0]
99
+
100
+
101
+ class TestPreProcessCopyVariants:
102
+ def test_load_copy_variants(self) -> None:
103
+ records = preprocess_copy_variants(
104
+ pd.read_csv(os.path.join(DATA_DIR, "copy_variants.tab"), sep="\t").to_dict("records")
105
+ )
106
+ assert records
107
+ assert len(records) == 4603
108
+ assert records[0]["variantType"] == "cnv"
109
+ assert "variant" in records[0]
110
+
111
+ def test_null(self):
112
+ for kb_cat in list(INPUT_COPY_CATEGORIES.values()) + NON_EMPTY_STRING_NULLS:
113
+ original = {"gene": "ERBB2", "kbCategory": kb_cat}
114
+ for key in COPY_OPTIONAL:
115
+ for null in NON_EMPTY_STRING_NULLS:
116
+ copy_var = original.copy()
117
+ copy_var[key] = null
118
+ records = preprocess_copy_variants([copy_var])
119
+ record = records[0]
120
+ assert record["variantType"] == "cnv"
121
+
122
+
123
+ def test_load_structural_variants() -> None:
124
+ records = preprocess_structural_variants(
125
+ pd.read_csv(os.path.join(DATA_DIR, "fusions.tab"), sep="\t").to_dict("records")
126
+ )
127
+ assert records
128
+ assert len(records) == 7
129
+ assert records[0]["variantType"] == "sv"
130
+ assert "variant" in records[0]
131
+
132
+
133
+ def test_load_expression_variants() -> None:
134
+ records = preprocess_expression_variants(
135
+ pd.read_csv(os.path.join(DATA_DIR, "expression.tab"), sep="\t").to_dict("records")
136
+ )
137
+ assert records
138
+ assert len(records) == 4603
139
+ assert records[0]["variantType"] == "exp"
140
+ assert "variant" in records[0]
141
+
142
+
143
+ class TestCheckVariantLinks:
144
+ def test_sm_missing_copy_empty_ok(self) -> None:
145
+ genes = check_variant_links(
146
+ small_mutations=[IprGeneVariant({"gene": "KRAS"})], # type: ignore
147
+ copy_variants=[],
148
+ expression_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
149
+ structural_variants=[],
150
+ )
151
+ assert genes == {"KRAS"}
152
+
153
+ def test_sm_missing_exp_empty_ok(self) -> None:
154
+ genes = check_variant_links(
155
+ small_mutations=[IprGeneVariant({"gene": "KRAS"})], # type: ignore
156
+ copy_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
157
+ expression_variants=[],
158
+ structural_variants=[],
159
+ )
160
+ assert genes == {"KRAS"}
161
+
162
+ def test_sm_missing_copy(self) -> None:
163
+ with mock.patch.object(logger, "debug") as mock_debug:
164
+ check_variant_links(
165
+ small_mutations=[IprGeneVariant({"gene": "KRAS"})], # type: ignore
166
+ copy_variants=[IprGeneVariant({"gene": "CDK", "variant": ""})], # type: ignore
167
+ expression_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
168
+ structural_variants=[],
169
+ )
170
+ assert mock_debug.called
171
+
172
+ def test_sm_missing_exp(self) -> None:
173
+ with mock.patch.object(logger, "debug") as mock_debug:
174
+ check_variant_links(
175
+ small_mutations=[IprGeneVariant({"gene": "KRAS"})], # type: ignore
176
+ copy_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
177
+ expression_variants=[IprGeneVariant({"gene": "CDK", "variant": ""})], # type: ignore
178
+ structural_variants=[],
179
+ )
180
+ assert mock_debug.called
181
+
182
+ def test_with_valid_inputs(self) -> None:
183
+ genes = check_variant_links(
184
+ small_mutations=[IprGeneVariant({"gene": "KRAS"})], # type: ignore
185
+ copy_variants=[
186
+ IprGeneVariant({"gene": "KRAS", "variant": ""}), # type: ignore
187
+ IprGeneVariant({"gene": "CDK", "variant": ""}), # type: ignore
188
+ ],
189
+ expression_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
190
+ structural_variants=[],
191
+ )
192
+ assert genes == {"KRAS"}
193
+
194
+ def test_copy_missing_exp(self) -> None:
195
+ with mock.patch.object(logger, "debug") as mock_debug:
196
+ check_variant_links(
197
+ small_mutations=[],
198
+ copy_variants=[
199
+ IprGeneVariant({"gene": "BRAF", "variant": "copy gain"}), # type: ignore
200
+ IprGeneVariant({"gene": "KRAS", "variant": ""}), # type: ignore
201
+ ],
202
+ expression_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
203
+ structural_variants=[],
204
+ )
205
+ assert mock_debug.called
206
+
207
+ def test_exp_missing_copy(self) -> None:
208
+ with mock.patch.object(logger, "debug") as mock_debug:
209
+ check_variant_links(
210
+ small_mutations=[],
211
+ copy_variants=[IprGeneVariant({"gene": "KRAS", "variant": ""})], # type: ignore
212
+ expression_variants=[
213
+ IprGeneVariant({"gene": "BRAF", "variant": "increased expression"}) # type: ignore
214
+ ],
215
+ structural_variants=[],
216
+ )
217
+ assert mock_debug.called
218
+
219
+
220
+ class TestCreateGraphkbSvNotation:
221
+ def test_both_genes_and_exons(self) -> None:
222
+ notation = create_graphkb_sv_notation(
223
+ IprFusionVariant({"gene1": "A", "gene2": "B", "exon1": 1, "exon2": 2}) # type: ignore
224
+ )
225
+ assert notation == "(A,B):fusion(e.1,e.2)"
226
+
227
+ def test_one_exon_missing(self) -> None:
228
+ notation = create_graphkb_sv_notation(
229
+ IprFusionVariant({"gene1": "A", "gene2": "B", "exon1": "", "exon2": 2}) # type: ignore
230
+ )
231
+ assert notation == "(A,B):fusion(e.?,e.2)"
232
+
233
+ def test_one_gene_missing(self) -> None:
234
+ notation = create_graphkb_sv_notation(
235
+ IprFusionVariant({"gene1": "A", "gene2": "", "exon1": 1, "exon2": 2}) # type: ignore
236
+ )
237
+ assert notation == "(A,?):fusion(e.1,e.2)"
238
+
239
+ def test_first_gene_missing(self) -> None:
240
+ notation = create_graphkb_sv_notation(
241
+ IprFusionVariant({"gene1": "", "gene2": "B", "exon1": 1, "exon2": 2}) # type: ignore
242
+ )
243
+ assert notation == "(B,?):fusion(e.2,e.1)"
244
+
245
+ def test_no_genes_error(self) -> None:
246
+ with pytest.raises(ValueError):
247
+ create_graphkb_sv_notation(
248
+ IprFusionVariant({"gene1": "", "gene2": "", "exon1": 1, "exon2": 2, "key": "x"}) # type: ignore
249
+ )
250
+
251
+
252
+ class TestCheckComparators:
253
+ def test_missing_disease_expression_error(self):
254
+ content = {"comparators": [{"analysisRole": "expression (primary site)"}]}
255
+ variants = [{}]
256
+
257
+ with pytest.raises(ValueError):
258
+ check_comparators(content, variants)
259
+
260
+ def test_missing_primary_expression_error(self):
261
+ content = {"comparators": [{"analysisRole": "expression (disease)"}]}
262
+ variants = [{"primarySiteFoldChange": 1}]
263
+
264
+ with pytest.raises(ValueError):
265
+ check_comparators(content, variants)
266
+
267
+ def test_missing_biopsy_expression_error(self):
268
+ content = {"comparators": [{"analysisRole": "expression (disease)"}]}
269
+ variants = [{"biopsySitePercentile": 1}]
270
+
271
+ with pytest.raises(ValueError):
272
+ check_comparators(content, variants)
273
+
274
+ def test_expression_not_required_without_variants(self):
275
+ content = {"comparators": []}
276
+ variants = []
277
+
278
+ assert check_comparators(content, variants) is None
279
+
280
+ def test_missing_mutation_burden(self):
281
+ content = {
282
+ "comparators": [{"analysisRole": "mutation burden (secondary)"}],
283
+ "images": [{"key": "mutationBurden.density_snv.primary"}],
284
+ }
285
+ variants = []
286
+
287
+ with pytest.raises(ValueError):
288
+ check_comparators(content, variants)
289
+
290
+
291
+ @pytest.mark.parametrize("example_name", ["no_variants", "sm_and_exp", "sm_only"])
292
+ def test_valid_json_inputs(example_name: str):
293
+ with open(os.path.join(DATA_DIR, "json_examples", f"{example_name}.json"), "r") as fh:
294
+ content = json.load(fh)
295
+ validate_report_content(content)
@@ -0,0 +1,338 @@
1
+ import pytest
2
+ from unittest.mock import Mock, patch
3
+
4
+ from pori_python.graphkb import statement as gkb_statement
5
+ from pori_python.graphkb import vocab as gkb_vocab
6
+ from pori_python.ipr.ipr import convert_statements_to_alterations, germline_kb_matches
7
+ from pori_python.types import Statement
8
+
9
+ DISEASE_RIDS = ["#138:12", "#138:13"]
10
+ APPROVED_EVIDENCE_RIDS = ["approved1", "approved2"]
11
+ GERMLINE_VARIANTS = [
12
+ {
13
+ "key": "1",
14
+ "germline": True,
15
+ "hgvsCds": "SLC28A3:c.1381C>T",
16
+ "hgvsGenomic": "chr9:g.84286011G>A",
17
+ "hgvsProtein": "SLC28A3:p.L461L",
18
+ "ncbiBuild": "GRCh38",
19
+ "normalAltCount": 37,
20
+ "normalDepth": 37,
21
+ "normalRefCount": 0,
22
+ "proteinChange": "p.L461L",
23
+ "rnaAltCount": "",
24
+ "rnaDepth": "",
25
+ "rnaRefCount": "",
26
+ "startPosition": 84286011,
27
+ "transcript": "ENST00000376238",
28
+ "tumourAltCount": "",
29
+ "tumourDepth": "",
30
+ "tumourRefCount": "",
31
+ "variant": "SLC28A3:p.L461L",
32
+ "variantType": "mut",
33
+ "zygosity": "",
34
+ },
35
+ {
36
+ "key": "2",
37
+ "germline": True,
38
+ "hgvsCds": "BRCA1:c.4837A>",
39
+ "hgvsGenomic": "chr17:g.43071077T>C",
40
+ "hgvsProtein": "BRCA1:p.S1613G",
41
+ "normalAltCount": 33,
42
+ "normalDepth": 33,
43
+ "normalRefCount": 0,
44
+ "tumourAltCount": 37,
45
+ "tumourDepth": 37,
46
+ "tumourRefCount": 0,
47
+ },
48
+ ]
49
+
50
+ SOMATIC_VARIANTS = [
51
+ {
52
+ "key": "1",
53
+ "gene": "SLC28A3",
54
+ "germline": False,
55
+ "hgvsCds": "SLC28A3:c.1381C>T",
56
+ "hgvsGenomic": "chr9:g.84286011G>A",
57
+ "hgvsProtein": "SLC28A3:p.L461L",
58
+ "ncbiBuild": "GRCh38",
59
+ "normalAltCount": 0,
60
+ "normalDepth": 37,
61
+ "normalRefCount": 37,
62
+ "tumourAltCount": 37,
63
+ "tumourDepth": 37,
64
+ "tumourRefCount": 0,
65
+ "variant": "SLC28A3:p.L461L",
66
+ "variantType": "mut",
67
+ "zygosity": "",
68
+ },
69
+ {
70
+ "key": "2",
71
+ "germline": False,
72
+ "hgvsCds": "BRCA1:c.4837A>",
73
+ "hgvsGenomic": "chr17:g.43071077T>C",
74
+ "hgvsProtein": "BRCA1:p.S1613G",
75
+ "normalAltCount": 1,
76
+ "normalDepth": 33,
77
+ "normalRefCount": 32,
78
+ "tumourAltCount": 37,
79
+ "tumourDepth": 37,
80
+ "tumourRefCount": 0,
81
+ },
82
+ ]
83
+
84
+ GERMLINE_KB_MATCHES = [
85
+ {
86
+ "variant": "1",
87
+ "approvedTherapy": False,
88
+ "category": "pharmacogenomic",
89
+ "context": "anthracyclines",
90
+ "kbContextId": "#122:20944",
91
+ "kbRelevanceId": "#147:38",
92
+ "kbStatementId": "#154:13387",
93
+ "kbVariant": "SLC28A3:c.1381C>T",
94
+ "kbVariantId": "#159:5426",
95
+ "matchedCancer": False,
96
+ "reference": "PMID: 27197003",
97
+ "relevance": "decreased toxicity",
98
+ "reviewStatus": "initial",
99
+ },
100
+ {
101
+ "variant": "2",
102
+ "approvedTherapy": True,
103
+ "category": "cancer predisposition",
104
+ "kbContextId": "#135:8764",
105
+ "kbRelevanceId": "#147:32",
106
+ "kbStatementId": "#155:13511",
107
+ "kbVariant": "BRCA1 mutation",
108
+ "kbVariantId": "#161:938",
109
+ "matchedCancer": False,
110
+ "reference": "MOAlmanac FDA-56",
111
+ "relevance": "therapy",
112
+ "reviewStatus": None,
113
+ },
114
+ ]
115
+
116
+ SOMATIC_KB_MATCHES = [
117
+ {
118
+ "variant": "1",
119
+ "approvedTherapy": False,
120
+ "category": "prognostic",
121
+ "kbContextId": "somatic_test",
122
+ "kbRelevanceId": "#147:38",
123
+ "kbStatementId": "#154:13387",
124
+ "kbVariant": "SLC28A3:c.1381C>T",
125
+ "kbVariantId": "#159:5426",
126
+ "relevance": "prognostic",
127
+ "reviewStatus": "initial",
128
+ },
129
+ {
130
+ "variant": "2",
131
+ "approvedTherapy": True,
132
+ "category": "therapy",
133
+ "kbContextId": "#135:8764",
134
+ "kbRelevanceId": "#147:32",
135
+ "kbStatementId": "#155:13511",
136
+ "kbVariant": "BRCA1 mutation",
137
+ "kbVariantId": "#161:938",
138
+ "matchedCancer": False,
139
+ "reference": "MOAlmanac FDA-56",
140
+ "relevance": "therapy",
141
+ "reviewStatus": None,
142
+ },
143
+ ]
144
+
145
+
146
+ @pytest.fixture
147
+ def graphkb_conn():
148
+ class QueryMock:
149
+ return_values = [
150
+ # get approved evidence levels
151
+ [{"@rid": v} for v in APPROVED_EVIDENCE_RIDS]
152
+ ]
153
+ index = -1
154
+
155
+ def __call__(self, *args, **kwargs):
156
+ self.index += 1
157
+ ret_val = self.return_values[self.index] if self.index < len(self.return_values) else []
158
+ return ret_val
159
+
160
+ def mock_get_source(source):
161
+ return {"@rid": 0}
162
+
163
+ conn = Mock(query=QueryMock(), cache={}, get_source=mock_get_source)
164
+
165
+ return conn
166
+
167
+
168
+ def base_graphkb_statement(disease_id: str = "disease", relevance_rid: str = "other") -> Statement:
169
+ statement = Statement( # type: ignore
170
+ {
171
+ "conditions": [
172
+ {"@class": "Disease", "@rid": disease_id, "displayName": "disease_display_name"},
173
+ {
174
+ "@class": "CategoryVariant",
175
+ "@rid": "variant_rid",
176
+ "displayName": "KRAS increased expression",
177
+ },
178
+ ],
179
+ "evidence": [],
180
+ "subject": {
181
+ "@class": "dummy_value",
182
+ "@rid": "101:010",
183
+ "displayName": "dummy_display_name",
184
+ },
185
+ "source": None,
186
+ "sourceId": None,
187
+ "relevance": {
188
+ "@rid": relevance_rid,
189
+ "displayName": "relevance_display_name",
190
+ "name": "relevance_name",
191
+ },
192
+ "@rid": "statement_rid",
193
+ }
194
+ )
195
+ return statement
196
+
197
+
198
+ @pytest.fixture(autouse=True)
199
+ def mock_get_term_tree(monkeypatch):
200
+ def mock_func(*pos, **kwargs):
201
+ return [{"@rid": d} for d in DISEASE_RIDS]
202
+
203
+ monkeypatch.setattr(gkb_vocab, "get_term_tree", mock_func)
204
+
205
+
206
+ @pytest.fixture(autouse=True)
207
+ def mock_categorize_relevance(monkeypatch):
208
+ def mock_func(_, relevance_id):
209
+ return relevance_id
210
+
211
+ monkeypatch.setattr(gkb_statement, "categorize_relevance", mock_func)
212
+
213
+
214
+ class TestConvertStatementsToAlterations:
215
+ def test_disease_match(self, graphkb_conn, mock_get_term_tree) -> None:
216
+ statement = base_graphkb_statement(DISEASE_RIDS[0])
217
+ result = convert_statements_to_alterations(
218
+ graphkb_conn, [statement], "disease", {"variant_rid"}
219
+ )
220
+
221
+ assert len(result) == 1
222
+ row = result[0]
223
+ assert row["kbVariantId"] == "variant_rid"
224
+ assert row["kbStatementId"] == "statement_rid"
225
+ assert row["matchedCancer"]
226
+ assert row["kbVariant"] == "KRAS increased expression"
227
+ assert row["relevance"] == "relevance_display_name"
228
+
229
+ def test_no_disease_match(self, graphkb_conn) -> None:
230
+ statement = base_graphkb_statement("other")
231
+ result = convert_statements_to_alterations(
232
+ graphkb_conn, [statement], "disease", {"variant_rid"}
233
+ )
234
+
235
+ assert len(result) == 1
236
+ row = result[0]
237
+ assert not row["matchedCancer"]
238
+
239
+ def test_multiple_disease_not_match(self, graphkb_conn) -> None:
240
+ statement = base_graphkb_statement("disease")
241
+ statement["conditions"].append(
242
+ {"@class": "Disease", "@rid": "other", "displayName": "disease_display_name"} # type: ignore
243
+ )
244
+ result = convert_statements_to_alterations(
245
+ graphkb_conn, [statement], "disease", {"variant_rid"}
246
+ )
247
+
248
+ assert len(result) == 1
249
+ row = result[0]
250
+ assert not row["matchedCancer"]
251
+
252
+ def test_biological(self, graphkb_conn) -> None:
253
+ statement = base_graphkb_statement()
254
+ statement["relevance"]["@rid"] = "biological"
255
+
256
+ result = convert_statements_to_alterations(
257
+ graphkb_conn, [statement], "disease", {"variant_rid"}
258
+ )
259
+ assert len(result) == 1
260
+ row = result[0]
261
+ assert row["category"] == "biological"
262
+
263
+ def test_prognostic_no_disease_match(self, graphkb_conn) -> None:
264
+ statement = base_graphkb_statement()
265
+ statement["relevance"]["@rid"] = "prognostic"
266
+
267
+ result = convert_statements_to_alterations(
268
+ graphkb_conn, [statement], "disease", {"variant_rid"}
269
+ )
270
+ assert len(result) == 0
271
+
272
+ def test_prognostic_disease_match(self, graphkb_conn) -> None:
273
+ statement = base_graphkb_statement(DISEASE_RIDS[0])
274
+ statement["relevance"]["@rid"] = "prognostic"
275
+
276
+ result = convert_statements_to_alterations(
277
+ graphkb_conn, [statement], "disease", {"variant_rid"}
278
+ )
279
+ assert len(result) == 1
280
+ row = result[0]
281
+ assert row["category"] == "prognostic"
282
+
283
+ def test_diagnostic(self, graphkb_conn) -> None:
284
+ statement = base_graphkb_statement()
285
+ statement["relevance"]["@rid"] = "diagnostic"
286
+
287
+ result = convert_statements_to_alterations(
288
+ graphkb_conn, [statement], "disease", {"variant_rid"}
289
+ )
290
+ assert len(result) == 1
291
+ row = result[0]
292
+ assert row["category"] == "diagnostic"
293
+
294
+ @patch("pori_python.ipr.ipr.get_evidencelevel_mapping")
295
+ def test_unapproved_therapeutic(self, mock_get_evidencelevel_mapping, graphkb_conn) -> None:
296
+ mock_get_evidencelevel_mapping.return_value = {"other": "test"}
297
+
298
+ statement = base_graphkb_statement()
299
+ statement["relevance"]["@rid"] = "therapeutic"
300
+ statement["evidenceLevel"] = [{"@rid": "other", "displayName": "level"}] # type: ignore
301
+
302
+ result = convert_statements_to_alterations(
303
+ graphkb_conn, [statement], "disease", {"variant_rid"}
304
+ )
305
+ assert len(result) == 1
306
+ row = result[0]
307
+ assert row["category"] == "therapeutic"
308
+
309
+ @patch("pori_python.ipr.ipr.get_evidencelevel_mapping")
310
+ def test_approved_therapeutic(self, mock_get_evidencelevel_mapping, graphkb_conn) -> None:
311
+ mock_get_evidencelevel_mapping.return_value = {APPROVED_EVIDENCE_RIDS[0]: "test"}
312
+
313
+ statement = base_graphkb_statement()
314
+ statement["relevance"]["@rid"] = "therapeutic"
315
+ statement["evidenceLevel"] = [{"@rid": APPROVED_EVIDENCE_RIDS[0], "displayName": "level"}] # type: ignore
316
+
317
+ result = convert_statements_to_alterations(
318
+ graphkb_conn, [statement], "disease", {"variant_rid"}
319
+ )
320
+ assert len(result) == 1
321
+ row = result[0]
322
+ assert row["category"] == "therapeutic"
323
+
324
+
325
+ class TestKbmatchFilters:
326
+ def test_germline_kb_matches(self):
327
+ assert len(germline_kb_matches(GERMLINE_KB_MATCHES, GERMLINE_VARIANTS)) == len(
328
+ GERMLINE_KB_MATCHES
329
+ ), "Germline variant not matched to germline KB statement."
330
+ assert not germline_kb_matches(
331
+ GERMLINE_KB_MATCHES, SOMATIC_VARIANTS
332
+ ), "Somatic variant matched to KB germline statement."
333
+ assert len(germline_kb_matches(SOMATIC_KB_MATCHES, SOMATIC_VARIANTS)) == len(
334
+ SOMATIC_KB_MATCHES
335
+ ), "Somatic variant not matched to somatic KB statement."
336
+ assert not germline_kb_matches(
337
+ SOMATIC_KB_MATCHES, GERMLINE_VARIANTS
338
+ ), "Germline variant matched to KB somatic statement."