pori-python 0.1.2__tar.gz → 1.0.0__tar.gz
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-0.1.2/pori_python.egg-info → pori_python-1.0.0}/PKG-INFO +3 -2
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/genes.py +3 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/match.py +95 -21
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/annotate.py +97 -24
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/constants.py +3 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/content.spec.json +12 -3
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/inputs.py +96 -2
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/ipr.py +279 -13
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/main.py +168 -37
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/summary.py +133 -10
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/types.py +52 -1
- {pori_python-0.1.2 → pori_python-1.0.0/pori_python.egg-info}/PKG-INFO +3 -2
- {pori_python-0.1.2 → pori_python-1.0.0}/setup.cfg +1 -1
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/data.py +4 -4
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/test_match.py +27 -12
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_annotate.py +11 -5
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_inputs.py +120 -0
- pori_python-1.0.0/tests/test_ipr/test_ipr.py +734 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_main.py +15 -2
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_probe.py +34 -24
- pori_python-1.0.0/tests/test_ipr/test_summary.py +355 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_upload.py +110 -29
- pori_python-0.1.2/tests/test_ipr/test_ipr.py +0 -338
- pori_python-0.1.2/tests/test_ipr/test_summary.py +0 -157
- {pori_python-0.1.2 → pori_python-1.0.0}/LICENSE +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/MANIFEST.in +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/README.md +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/__init__.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/__init__.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/constants.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/py.typed +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/statement.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/util.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/graphkb/vocab.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/__init__.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/connection.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/py.typed +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/therapeutic_options.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python/ipr/util.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python.egg-info/SOURCES.txt +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python.egg-info/dependency_links.txt +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python.egg-info/entry_points.txt +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python.egg-info/requires.txt +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pori_python.egg-info/top_level.txt +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/pyproject.toml +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/setup.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/__init__.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/__init__.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/test_genes.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/test_graphkb.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/test_statement.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/test_util.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_graphkb/test_vocab.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/__init__.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/constants.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_connection.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/test_util.py +0 -0
- {pori_python-0.1.2 → pori_python-1.0.0}/tests/test_ipr/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pori_python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Home-page: https://github.com/bcgsc/pori_python
|
|
5
5
|
Author-email: dat@bcgsc.ca
|
|
6
6
|
Maintainer-email: dat@bcgsc.ca
|
|
@@ -42,6 +42,7 @@ Requires-Dist: black; extra == "dev"
|
|
|
42
42
|
Requires-Dist: flake8-annotations; extra == "dev"
|
|
43
43
|
Requires-Dist: isort; extra == "dev"
|
|
44
44
|
Requires-Dist: mypy; extra == "dev"
|
|
45
|
+
Dynamic: license-file
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
# PORI Python Adaptor
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from typing import Any, Dict, List, Sequence, Set, Tuple, cast
|
|
6
|
+
from typing_extensions import deprecated
|
|
6
7
|
|
|
7
8
|
from pori_python.types import IprGene, Ontology, Record, Statement, Variant
|
|
8
9
|
|
|
@@ -256,6 +257,7 @@ def get_preferred_gene_name(
|
|
|
256
257
|
return gene_names[0]
|
|
257
258
|
|
|
258
259
|
|
|
260
|
+
@deprecated("Use get_gene_linked_cancer_predisposition_info instead")
|
|
259
261
|
def get_cancer_predisposition_info(
|
|
260
262
|
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE_NAME
|
|
261
263
|
) -> Tuple[List[str], Dict[str, str]]:
|
|
@@ -360,6 +362,7 @@ def get_gene_linked_cancer_predisposition_info(
|
|
|
360
362
|
return sorted(genes), variants
|
|
361
363
|
|
|
362
364
|
|
|
365
|
+
@deprecated("Use get_gene_linked_pharmacogenomic_info instead")
|
|
363
366
|
def get_pharmacogenomic_info(
|
|
364
367
|
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE_NAME
|
|
365
368
|
) -> Tuple[List[str], Dict[str, str]]:
|
|
@@ -31,7 +31,12 @@ from .util import (
|
|
|
31
31
|
looks_like_rid,
|
|
32
32
|
stringifyVariant,
|
|
33
33
|
)
|
|
34
|
-
from .vocab import
|
|
34
|
+
from .vocab import (
|
|
35
|
+
get_equivalent_terms,
|
|
36
|
+
get_term_by_name,
|
|
37
|
+
get_term_tree,
|
|
38
|
+
get_terms_set,
|
|
39
|
+
)
|
|
35
40
|
|
|
36
41
|
FEATURES_CACHE: Set[str] = set()
|
|
37
42
|
|
|
@@ -124,50 +129,62 @@ def cache_missing_features(conn: GraphKBConnection) -> None:
|
|
|
124
129
|
|
|
125
130
|
def match_category_variant(
|
|
126
131
|
conn: GraphKBConnection,
|
|
127
|
-
|
|
132
|
+
reference_name: str,
|
|
128
133
|
category: str,
|
|
129
134
|
root_exclude_term: str = "",
|
|
130
135
|
gene_source: str = "",
|
|
131
136
|
gene_is_source_id: bool = False,
|
|
132
137
|
ignore_cache: bool = False,
|
|
138
|
+
reference_class: str = 'Feature',
|
|
133
139
|
) -> List[Variant]:
|
|
134
140
|
"""
|
|
135
141
|
Returns a list of variants matching the input variant
|
|
136
142
|
|
|
137
143
|
Args:
|
|
138
144
|
conn (GraphKBConnection): the graphkb connection object
|
|
139
|
-
|
|
145
|
+
reference_name (str): the name of the Feature(gene)/Signature the variant is in reference to
|
|
140
146
|
category (str): the variant category (ex. copy loss)
|
|
141
147
|
gene_source: The source database the gene is defined by (ex. ensembl)
|
|
142
148
|
gene_is_source_id: Indicates the gene name(s) input should be treated as sourceIds not names
|
|
149
|
+
reference_class (str): Class name of the variant reference. Default to 'Feature'
|
|
143
150
|
Raises:
|
|
144
151
|
FeatureNotFoundError: The gene could not be found in GraphKB
|
|
145
152
|
|
|
146
153
|
Returns:
|
|
147
154
|
Array.<dict>: List of variant records from GraphKB which match the input
|
|
148
155
|
"""
|
|
149
|
-
# disambiguate the
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
# disambiguate the reference to find all equivalent representations
|
|
157
|
+
references: List[str] = []
|
|
158
|
+
if reference_class == 'Feature':
|
|
159
|
+
references = convert_to_rid_list(
|
|
160
|
+
get_equivalent_features(
|
|
161
|
+
conn,
|
|
162
|
+
reference_name,
|
|
163
|
+
source=gene_source,
|
|
164
|
+
is_source_id=gene_is_source_id,
|
|
165
|
+
ignore_cache=ignore_cache,
|
|
166
|
+
)
|
|
157
167
|
)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
168
|
+
if not references:
|
|
169
|
+
raise FeatureNotFoundError(
|
|
170
|
+
f"unable to find the gene ({reference_name}) or any equivalent representations"
|
|
171
|
+
)
|
|
172
|
+
if reference_class == 'Signature':
|
|
173
|
+
references = convert_to_rid_list(
|
|
174
|
+
get_equivalent_terms(
|
|
175
|
+
conn,
|
|
176
|
+
reference_name.lower(),
|
|
177
|
+
ontology_class='Signature',
|
|
178
|
+
ignore_cache=ignore_cache,
|
|
179
|
+
)
|
|
163
180
|
)
|
|
164
181
|
|
|
165
182
|
# get the list of terms that we should match
|
|
166
|
-
|
|
183
|
+
types = convert_to_rid_list(
|
|
167
184
|
get_term_tree(conn, category, root_exclude_term, ignore_cache=ignore_cache)
|
|
168
185
|
)
|
|
169
186
|
|
|
170
|
-
if not
|
|
187
|
+
if not types:
|
|
171
188
|
raise ValueError(f"unable to find the term/category ({category}) or any equivalent")
|
|
172
189
|
|
|
173
190
|
# find the variant list
|
|
@@ -178,8 +195,8 @@ def match_category_variant(
|
|
|
178
195
|
"target": {
|
|
179
196
|
"target": "CategoryVariant",
|
|
180
197
|
"filters": [
|
|
181
|
-
{"reference1":
|
|
182
|
-
{"type":
|
|
198
|
+
{"reference1": references, "operator": "IN"},
|
|
199
|
+
{"type": types, "operator": "IN"},
|
|
183
200
|
],
|
|
184
201
|
},
|
|
185
202
|
"queryType": "similarTo",
|
|
@@ -275,7 +292,55 @@ def positions_overlap(
|
|
|
275
292
|
return start is None or pos == start
|
|
276
293
|
|
|
277
294
|
|
|
295
|
+
def equivalent_types(
|
|
296
|
+
conn: GraphKBConnection,
|
|
297
|
+
type1: str,
|
|
298
|
+
type2: str,
|
|
299
|
+
strict: bool = False,
|
|
300
|
+
) -> bool:
|
|
301
|
+
"""
|
|
302
|
+
Compare 2 variant types to determine if they should match
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
conn: the graphkb connection object
|
|
306
|
+
type1: type from the observed variant we want to match to the DB
|
|
307
|
+
type2: type from the DB variant
|
|
308
|
+
strict: wether or not only the specific-to-generic ones are considered.
|
|
309
|
+
By default (false), not only specific types can match more generic ones,
|
|
310
|
+
but generic types can also match more specific ones.
|
|
311
|
+
|
|
312
|
+
Returns:
|
|
313
|
+
bool: True if the types can be matched
|
|
314
|
+
"""
|
|
315
|
+
|
|
316
|
+
# Convert rid to displayName if needed
|
|
317
|
+
if looks_like_rid(type1):
|
|
318
|
+
type1 = conn.get_records_by_id([type1])[0]['displayName']
|
|
319
|
+
if looks_like_rid(type2):
|
|
320
|
+
type2 = conn.get_records_by_id([type2])[0]['displayName']
|
|
321
|
+
|
|
322
|
+
# Get type terms from observed variant
|
|
323
|
+
terms1 = []
|
|
324
|
+
if strict:
|
|
325
|
+
try:
|
|
326
|
+
terms1.append(get_term_by_name(conn, type1)['@rid'])
|
|
327
|
+
except:
|
|
328
|
+
pass
|
|
329
|
+
else:
|
|
330
|
+
terms1 = get_terms_set(conn, [type1])
|
|
331
|
+
|
|
332
|
+
# Get type terms from DB variant
|
|
333
|
+
terms2 = get_terms_set(conn, [type2])
|
|
334
|
+
|
|
335
|
+
# Check for intersect
|
|
336
|
+
if len(terms2.intersection(terms1)) == 0:
|
|
337
|
+
return False
|
|
338
|
+
|
|
339
|
+
return True
|
|
340
|
+
|
|
341
|
+
|
|
278
342
|
def compare_positional_variants(
|
|
343
|
+
conn: GraphKBConnection,
|
|
279
344
|
variant: Union[PositionalVariant, ParsedVariant],
|
|
280
345
|
reference_variant: Union[PositionalVariant, ParsedVariant],
|
|
281
346
|
generic: bool = True,
|
|
@@ -378,6 +443,11 @@ def compare_positional_variants(
|
|
|
378
443
|
elif len(variant["refSeq"]) != len(reference_variant["refSeq"]): # type: ignore
|
|
379
444
|
return False
|
|
380
445
|
|
|
446
|
+
# Equivalent types
|
|
447
|
+
if variant.get('type') and reference_variant.get('type'):
|
|
448
|
+
if not equivalent_types(conn, variant["type"], reference_variant["type"]):
|
|
449
|
+
return False
|
|
450
|
+
|
|
381
451
|
return True
|
|
382
452
|
|
|
383
453
|
|
|
@@ -598,10 +668,14 @@ def match_positional_variant(
|
|
|
598
668
|
):
|
|
599
669
|
# TODO: Check if variant and reference_variant should be interchanged
|
|
600
670
|
if compare_positional_variants(
|
|
601
|
-
|
|
671
|
+
conn,
|
|
672
|
+
variant=parsed,
|
|
673
|
+
reference_variant=cast(PositionalVariant, row),
|
|
674
|
+
generic=True,
|
|
602
675
|
):
|
|
603
676
|
filtered_similarAndGeneric.append(row)
|
|
604
677
|
if compare_positional_variants(
|
|
678
|
+
conn,
|
|
605
679
|
variant=parsed,
|
|
606
680
|
reference_variant=cast(PositionalVariant, row),
|
|
607
681
|
generic=False, # Similar variants only
|
|
@@ -19,6 +19,7 @@ from pori_python.types import (
|
|
|
19
19
|
Hashabledict,
|
|
20
20
|
IprCopyVariant,
|
|
21
21
|
IprExprVariant,
|
|
22
|
+
IprSignatureVariant,
|
|
22
23
|
IprStructuralVariant,
|
|
23
24
|
KbMatch,
|
|
24
25
|
Statement,
|
|
@@ -56,7 +57,7 @@ def get_second_pass_variants(
|
|
|
56
57
|
|
|
57
58
|
|
|
58
59
|
def get_ipr_statements_from_variants(
|
|
59
|
-
graphkb_conn: GraphKBConnection, matches: List[Variant],
|
|
60
|
+
graphkb_conn: GraphKBConnection, matches: List[Variant], disease_matches: List[str]
|
|
60
61
|
) -> List[KbMatch]:
|
|
61
62
|
"""IPR upload formatted GraphKB statements from the list of variants.
|
|
62
63
|
|
|
@@ -66,11 +67,12 @@ def get_ipr_statements_from_variants(
|
|
|
66
67
|
if not matches:
|
|
67
68
|
return []
|
|
68
69
|
rows = []
|
|
70
|
+
|
|
69
71
|
statements = get_statements_from_variants(graphkb_conn, matches)
|
|
70
72
|
existing_statements = {s["@rid"] for s in statements}
|
|
71
73
|
|
|
72
74
|
for ipr_row in convert_statements_to_alterations(
|
|
73
|
-
graphkb_conn, statements,
|
|
75
|
+
graphkb_conn, statements, disease_matches, convert_to_rid_set(matches)
|
|
74
76
|
):
|
|
75
77
|
rows.append(ipr_row)
|
|
76
78
|
|
|
@@ -84,7 +86,10 @@ def get_ipr_statements_from_variants(
|
|
|
84
86
|
]
|
|
85
87
|
|
|
86
88
|
for ipr_row in convert_statements_to_alterations(
|
|
87
|
-
graphkb_conn,
|
|
89
|
+
graphkb_conn,
|
|
90
|
+
inferred_statements,
|
|
91
|
+
disease_matches,
|
|
92
|
+
convert_to_rid_set(inferred_matches),
|
|
88
93
|
):
|
|
89
94
|
ipr_row["kbData"]["inferred"] = True
|
|
90
95
|
rows.append(ipr_row)
|
|
@@ -94,15 +99,17 @@ def get_ipr_statements_from_variants(
|
|
|
94
99
|
|
|
95
100
|
def annotate_expression_variants(
|
|
96
101
|
graphkb_conn: GraphKBConnection,
|
|
102
|
+
disease_matches: List[str],
|
|
97
103
|
variants: List[IprExprVariant],
|
|
98
|
-
disease_name: str,
|
|
99
104
|
show_progress: bool = False,
|
|
100
105
|
) -> List[KbMatch]:
|
|
101
106
|
"""Annotate expression variants with GraphKB in the IPR alterations format.
|
|
102
107
|
|
|
103
108
|
Args:
|
|
104
|
-
graphkb_conn: the graphkb api connection object
|
|
105
|
-
|
|
109
|
+
graphkb_conn (GraphKBConnection): the graphkb api connection object
|
|
110
|
+
disease_matches (list.str): GraphKB disease RIDs
|
|
111
|
+
variants (list.IprExprVariant): list of variants.
|
|
112
|
+
show_progress (bool): Progressbar displayed for long runs.
|
|
106
113
|
|
|
107
114
|
Returns:
|
|
108
115
|
list of kbMatches records for IPR
|
|
@@ -122,7 +129,7 @@ def annotate_expression_variants(
|
|
|
122
129
|
continue
|
|
123
130
|
try:
|
|
124
131
|
matches = gkb_match.match_expression_variant(graphkb_conn, gene, variant)
|
|
125
|
-
for ipr_row in get_ipr_statements_from_variants(graphkb_conn, matches,
|
|
132
|
+
for ipr_row in get_ipr_statements_from_variants(graphkb_conn, matches, disease_matches):
|
|
126
133
|
ipr_row["variant"] = row["key"]
|
|
127
134
|
ipr_row["variantType"] = row.get("variantType", "exp")
|
|
128
135
|
alterations.append(ipr_row)
|
|
@@ -145,15 +152,17 @@ def annotate_expression_variants(
|
|
|
145
152
|
|
|
146
153
|
def annotate_copy_variants(
|
|
147
154
|
graphkb_conn: GraphKBConnection,
|
|
155
|
+
disease_matches: List[str],
|
|
148
156
|
variants: List[IprCopyVariant],
|
|
149
|
-
disease_name: str,
|
|
150
157
|
show_progress: bool = False,
|
|
151
158
|
) -> List[KbMatch]:
|
|
152
159
|
"""Annotate allowed copy variants with GraphKB in the IPR alterations format.
|
|
153
160
|
|
|
154
161
|
Args:
|
|
155
|
-
graphkb_conn: the graphkb api connection object
|
|
156
|
-
|
|
162
|
+
graphkb_conn (GraphKBConnection): the graphkb api connection object
|
|
163
|
+
disease_matches (list.str): GraphKB disease RIDs
|
|
164
|
+
variants (list.IprCopyVariant): list of variants.
|
|
165
|
+
show_progress (bool): Progressbar displayed for long runs.
|
|
157
166
|
|
|
158
167
|
Returns:
|
|
159
168
|
list of kbMatches records for IPR
|
|
@@ -175,7 +184,7 @@ def annotate_copy_variants(
|
|
|
175
184
|
continue
|
|
176
185
|
try:
|
|
177
186
|
matches = gkb_match.match_copy_variant(graphkb_conn, gene, variant)
|
|
178
|
-
for ipr_row in get_ipr_statements_from_variants(graphkb_conn, matches,
|
|
187
|
+
for ipr_row in get_ipr_statements_from_variants(graphkb_conn, matches, disease_matches):
|
|
179
188
|
ipr_row["variant"] = row["key"]
|
|
180
189
|
ipr_row["variantType"] = row.get("variantType", "cnv")
|
|
181
190
|
alterations.append(ipr_row)
|
|
@@ -201,7 +210,7 @@ def annotate_copy_variants(
|
|
|
201
210
|
def annotate_positional_variants(
|
|
202
211
|
graphkb_conn: GraphKBConnection,
|
|
203
212
|
variants: Sequence[IprStructuralVariant] | Sequence[Hashabledict],
|
|
204
|
-
|
|
213
|
+
disease_matches: List[str],
|
|
205
214
|
show_progress: bool = False,
|
|
206
215
|
) -> List[Hashabledict]:
|
|
207
216
|
"""Annotate SNP, INDEL or fusion variant calls with GraphKB and return in IPR match format.
|
|
@@ -209,8 +218,8 @@ def annotate_positional_variants(
|
|
|
209
218
|
Hashable type is required to turn lists into sets.
|
|
210
219
|
Args:
|
|
211
220
|
graphkb_conn (GraphKBConnection): the graphkb api connection object
|
|
212
|
-
variants (
|
|
213
|
-
|
|
221
|
+
variants (Sequence): list of variants.
|
|
222
|
+
disease_matches (list.str): GraphKB disease RIDs
|
|
214
223
|
show_progress (bool): Progressbar displayed for long runs.
|
|
215
224
|
|
|
216
225
|
Returns:
|
|
@@ -254,7 +263,9 @@ def annotate_positional_variants(
|
|
|
254
263
|
raise parse_err
|
|
255
264
|
|
|
256
265
|
for ipr_row in get_ipr_statements_from_variants(
|
|
257
|
-
graphkb_conn,
|
|
266
|
+
graphkb_conn,
|
|
267
|
+
matches,
|
|
268
|
+
disease_matches,
|
|
258
269
|
):
|
|
259
270
|
ipr_row["variant"] = row["key"]
|
|
260
271
|
ipr_row["variantType"] = row.get(
|
|
@@ -299,15 +310,16 @@ def annotate_positional_variants(
|
|
|
299
310
|
|
|
300
311
|
def annotate_msi(
|
|
301
312
|
graphkb_conn: GraphKBConnection,
|
|
302
|
-
|
|
313
|
+
disease_matches: List[str],
|
|
303
314
|
msi_category: str = "microsatellite instability",
|
|
304
315
|
) -> List[KbMatch]:
|
|
305
316
|
"""Annotate microsatellite instablity from GraphKB in the IPR alterations format.
|
|
306
317
|
|
|
307
318
|
Match to GraphKb Category variants with similar names
|
|
308
319
|
Args:
|
|
309
|
-
graphkb_conn: the graphkb api connection object
|
|
310
|
-
|
|
320
|
+
graphkb_conn (GraphKBConnection): the graphkb api connection object
|
|
321
|
+
disease_matches (list.str): GraphKB disease RIDs
|
|
322
|
+
msi_category (str): such as 'microsatellite instability'
|
|
311
323
|
|
|
312
324
|
Returns:
|
|
313
325
|
list of kbMatches records for IPR
|
|
@@ -318,7 +330,10 @@ def annotate_msi(
|
|
|
318
330
|
"target": {
|
|
319
331
|
"target": "CategoryVariant",
|
|
320
332
|
"filters": {
|
|
321
|
-
"reference1": {
|
|
333
|
+
"reference1": {
|
|
334
|
+
"target": "Signature",
|
|
335
|
+
"filters": {"name": msi_category},
|
|
336
|
+
}
|
|
322
337
|
},
|
|
323
338
|
},
|
|
324
339
|
"queryType": "similarTo",
|
|
@@ -327,7 +342,9 @@ def annotate_msi(
|
|
|
327
342
|
)
|
|
328
343
|
if msi_categories:
|
|
329
344
|
msi_variants = [cast(Variant, var) for var in msi_categories]
|
|
330
|
-
for ipr_row in get_ipr_statements_from_variants(
|
|
345
|
+
for ipr_row in get_ipr_statements_from_variants(
|
|
346
|
+
graphkb_conn, msi_variants, disease_matches
|
|
347
|
+
):
|
|
331
348
|
ipr_row["variant"] = msi_category
|
|
332
349
|
ipr_row["variantType"] = "msi"
|
|
333
350
|
gkb_matches.append(ipr_row)
|
|
@@ -335,14 +352,16 @@ def annotate_msi(
|
|
|
335
352
|
|
|
336
353
|
|
|
337
354
|
def annotate_tmb(
|
|
338
|
-
graphkb_conn: GraphKBConnection,
|
|
355
|
+
graphkb_conn: GraphKBConnection,
|
|
356
|
+
disease_matches: List[str],
|
|
357
|
+
category: str = TMB_HIGH_CATEGORY,
|
|
339
358
|
) -> List[KbMatch]:
|
|
340
359
|
"""Annotate Tumour Mutation Burden (tmb) categories from GraphKB in the IPR alterations format.
|
|
341
360
|
|
|
342
361
|
Match to GraphKb Category variants with similar names
|
|
343
362
|
Args:
|
|
344
|
-
graphkb_conn: the graphkb api connection object
|
|
345
|
-
|
|
363
|
+
graphkb_conn (GraphKBConnection): the graphkb api connection object
|
|
364
|
+
disease_matches (list.str): GraphKB disease RIDs
|
|
346
365
|
category: such as 'high mutation burden'
|
|
347
366
|
|
|
348
367
|
Returns:
|
|
@@ -366,8 +385,62 @@ def annotate_tmb(
|
|
|
366
385
|
)
|
|
367
386
|
if categories:
|
|
368
387
|
cat_variants = [cast(Variant, var) for var in categories]
|
|
369
|
-
for ipr_row in get_ipr_statements_from_variants(
|
|
388
|
+
for ipr_row in get_ipr_statements_from_variants(
|
|
389
|
+
graphkb_conn, cat_variants, disease_matches
|
|
390
|
+
):
|
|
370
391
|
ipr_row["variant"] = category
|
|
371
392
|
ipr_row["variantType"] = "tmb"
|
|
372
393
|
gkb_matches.append(ipr_row)
|
|
373
394
|
return gkb_matches
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def annotate_signature_variants(
|
|
398
|
+
graphkb_conn: GraphKBConnection,
|
|
399
|
+
disease_matches: List[str],
|
|
400
|
+
variants: List[IprSignatureVariant] = [],
|
|
401
|
+
show_progress: bool = False,
|
|
402
|
+
) -> List[KbMatch]:
|
|
403
|
+
"""Annotate Signature variants with GraphKB in the IPR alterations format.
|
|
404
|
+
|
|
405
|
+
Match to corresponding GraphKB Variants, then to linked GraphKB Statements
|
|
406
|
+
|
|
407
|
+
Args:
|
|
408
|
+
graphkb_conn (GraphKBConnection): the graphkb api connection object
|
|
409
|
+
disease_matches (list.str): GraphKB disease RIDs
|
|
410
|
+
variants (list.IprSignatureVariant): list of signature variants
|
|
411
|
+
show_progress (bool): progressbar displayed for long runs; default to False
|
|
412
|
+
|
|
413
|
+
Returns:
|
|
414
|
+
list of kbMatches records for IPR
|
|
415
|
+
"""
|
|
416
|
+
alterations: List[Hashabledict] = []
|
|
417
|
+
|
|
418
|
+
iterfunc = tqdm if show_progress else iter
|
|
419
|
+
for variant in iterfunc(variants):
|
|
420
|
+
try:
|
|
421
|
+
# Matching signature variant to GKB Variants
|
|
422
|
+
matched_variants: List[Variant] = gkb_match.match_category_variant(
|
|
423
|
+
graphkb_conn,
|
|
424
|
+
variant["signatureName"],
|
|
425
|
+
variant["variantTypeName"],
|
|
426
|
+
reference_class="Signature",
|
|
427
|
+
)
|
|
428
|
+
# Matching GKB Variants to GKB Statements
|
|
429
|
+
for ipr_row in get_ipr_statements_from_variants(
|
|
430
|
+
graphkb_conn, matched_variants, disease_matches
|
|
431
|
+
):
|
|
432
|
+
ipr_row["variant"] = variant["key"]
|
|
433
|
+
ipr_row["variantType"] = "sigv"
|
|
434
|
+
alterations.append(Hashabledict(ipr_row))
|
|
435
|
+
|
|
436
|
+
except ValueError as err:
|
|
437
|
+
logger.error(f"failed to match signature category variant '{variant}': {err}")
|
|
438
|
+
|
|
439
|
+
# drop duplicates
|
|
440
|
+
alterations = list(set(alterations))
|
|
441
|
+
|
|
442
|
+
logger.info(
|
|
443
|
+
f"matched {len(variants)} signature category variants to {len(alterations)} graphkb annotations"
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
return alterations
|
|
@@ -5,5 +5,8 @@ VARIANT_CLASSES = {"Variant", "CategoryVariant", "PositionalVariant", "Catalogue
|
|
|
5
5
|
# all possible values for review status are: ['pending', 'not required', 'passed', 'failed', 'initial']
|
|
6
6
|
FAILED_REVIEW_STATUS = "failed"
|
|
7
7
|
|
|
8
|
+
# Signatures
|
|
9
|
+
COSMIC_SIGNATURE_VARIANT_TYPE = "high signature"
|
|
10
|
+
HLA_SIGNATURE_VARIANT_TYPE = "signature present"
|
|
8
11
|
TMB_HIGH = 10.0 # genomic mutations per mb - https://www.bcgsc.ca/jira/browse/GERO-296
|
|
9
12
|
TMB_HIGH_CATEGORY = "high mutation burden"
|
|
@@ -99,12 +99,11 @@
|
|
|
99
99
|
"items": {
|
|
100
100
|
"properties": {
|
|
101
101
|
"chromosomeBand": {
|
|
102
|
-
"example": "
|
|
103
|
-
"pattern": "^(\\S+:\\S+?)?$",
|
|
102
|
+
"example": "Xp12.2",
|
|
104
103
|
"type": "string"
|
|
105
104
|
},
|
|
106
105
|
"cna": {
|
|
107
|
-
"description": "
|
|
106
|
+
"description": "Copy Number, Absolute (cna)",
|
|
108
107
|
"example": 1.22,
|
|
109
108
|
"type": [
|
|
110
109
|
"number",
|
|
@@ -213,6 +212,16 @@
|
|
|
213
212
|
},
|
|
214
213
|
"type": "array"
|
|
215
214
|
},
|
|
215
|
+
"cosmicSignatures": {
|
|
216
|
+
"default": [],
|
|
217
|
+
"description": "List of observed (above threshold) COSMIC signatures (DBS, SBS and ID) & dMMR",
|
|
218
|
+
"items": {
|
|
219
|
+
"description": "Signature name",
|
|
220
|
+
"example": "DBS1",
|
|
221
|
+
"type": "string"
|
|
222
|
+
},
|
|
223
|
+
"type": "array"
|
|
224
|
+
},
|
|
216
225
|
"expressionVariants": {
|
|
217
226
|
"default": [],
|
|
218
227
|
"items": {
|
|
@@ -7,6 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
import json
|
|
8
8
|
import jsonschema
|
|
9
9
|
import os
|
|
10
|
+
import re
|
|
10
11
|
import pandas as pd
|
|
11
12
|
from Bio.Data.IUPACData import protein_letters_3to1
|
|
12
13
|
from typing import Callable, Dict, Iterable, List, Set, Tuple, cast
|
|
@@ -16,11 +17,16 @@ from pori_python.types import (
|
|
|
16
17
|
IprCopyVariant,
|
|
17
18
|
IprExprVariant,
|
|
18
19
|
IprFusionVariant,
|
|
20
|
+
IprSignatureVariant,
|
|
19
21
|
IprSmallMutationVariant,
|
|
20
22
|
IprVariant,
|
|
21
23
|
)
|
|
22
24
|
|
|
23
|
-
from .constants import
|
|
25
|
+
from .constants import (
|
|
26
|
+
COSMIC_SIGNATURE_VARIANT_TYPE,
|
|
27
|
+
DEFAULT_URL,
|
|
28
|
+
HLA_SIGNATURE_VARIANT_TYPE,
|
|
29
|
+
)
|
|
24
30
|
from .util import hash_key, logger, pandas_falsy
|
|
25
31
|
|
|
26
32
|
protein_letters_3to1.setdefault("Ter", "*")
|
|
@@ -40,6 +46,8 @@ COPY_OPTIONAL = [
|
|
|
40
46
|
"copyChange",
|
|
41
47
|
"lohState", # Loss of Heterzygosity state - informative detail to analyst
|
|
42
48
|
"chromosomeBand",
|
|
49
|
+
"chromosome",
|
|
50
|
+
"chr", # expect only one of chromosome or chr
|
|
43
51
|
"start",
|
|
44
52
|
"end",
|
|
45
53
|
"size",
|
|
@@ -152,6 +160,12 @@ SV_OPTIONAL = [
|
|
|
152
160
|
"mavis_product_id",
|
|
153
161
|
]
|
|
154
162
|
|
|
163
|
+
SIGV_REQ = ["signatureName", "variantTypeName"]
|
|
164
|
+
SIGV_COSMIC = ["signature"] # 1st element used as signatureName key
|
|
165
|
+
SIGV_HLA = ["a1", "a2", "b1", "b2", "c1", "c2"]
|
|
166
|
+
SIGV_OPTIONAL = ["displayName"]
|
|
167
|
+
SIGV_KEY = SIGV_REQ[:]
|
|
168
|
+
|
|
155
169
|
|
|
156
170
|
def validate_variant_rows(
|
|
157
171
|
rows: Iterable[Dict], required: List[str], optional: List[str], row_to_key: Callable
|
|
@@ -220,6 +234,7 @@ def preprocess_copy_variants(rows: Iterable[Dict]) -> List[IprCopyVariant]:
|
|
|
220
234
|
result = validate_variant_rows(rows, COPY_REQ, COPY_OPTIONAL, row_key)
|
|
221
235
|
ret_list = [cast(IprCopyVariant, var) for var in result]
|
|
222
236
|
for row in ret_list:
|
|
237
|
+
|
|
223
238
|
kb_cat = row.get("kbCategory")
|
|
224
239
|
kb_cat = "" if pd.isnull(kb_cat) else str(kb_cat)
|
|
225
240
|
if kb_cat:
|
|
@@ -229,6 +244,20 @@ def preprocess_copy_variants(rows: Iterable[Dict]) -> List[IprCopyVariant]:
|
|
|
229
244
|
row["cnvState"] = display_name_mapping[kb_cat]
|
|
230
245
|
row["variant"] = kb_cat
|
|
231
246
|
row["variantType"] = "cnv"
|
|
247
|
+
chrband = row.get("chromosomeBand", False)
|
|
248
|
+
chrom = row.pop("chromosome", False)
|
|
249
|
+
if not chrom:
|
|
250
|
+
chrom = row.pop("chr", False)
|
|
251
|
+
# remove chr if it was not used for chrom
|
|
252
|
+
row.pop("chr", False)
|
|
253
|
+
if chrom:
|
|
254
|
+
# check that chr isn't already in the chrband;
|
|
255
|
+
# this regex from https://vrs.ga4gh.org/en/1.2/terms_and_model.html#id25
|
|
256
|
+
if chrband and (re.match("^cen|[pq](ter|([1-9][0-9]*(\.[1-9][0-9]*)?))$", chrband)):
|
|
257
|
+
if isinstance(chrom, int):
|
|
258
|
+
chrom = str(chrom)
|
|
259
|
+
chrom = chrom.strip("chr")
|
|
260
|
+
row["chromosomeBand"] = chrom + row["chromosomeBand"]
|
|
232
261
|
|
|
233
262
|
return ret_list
|
|
234
263
|
|
|
@@ -388,6 +417,69 @@ def preprocess_structural_variants(rows: Iterable[Dict]) -> List[IprFusionVarian
|
|
|
388
417
|
return result
|
|
389
418
|
|
|
390
419
|
|
|
420
|
+
def preprocess_signature_variants(rows: Iterable[Dict]) -> List[IprSignatureVariant]:
|
|
421
|
+
"""
|
|
422
|
+
Validate the input rows contain the minimum required fields and
|
|
423
|
+
generate any default values where possible
|
|
424
|
+
"""
|
|
425
|
+
|
|
426
|
+
def row_key(row: Dict) -> Tuple[str, ...]:
|
|
427
|
+
return tuple(["sigv"] + [row[key] for key in SIGV_KEY])
|
|
428
|
+
|
|
429
|
+
variants = validate_variant_rows(rows, SIGV_REQ, SIGV_OPTIONAL, row_key)
|
|
430
|
+
result = [cast(IprSignatureVariant, var) for var in variants]
|
|
431
|
+
|
|
432
|
+
# Adding additional required properties
|
|
433
|
+
for row in result:
|
|
434
|
+
row["variant"] = row["displayName"]
|
|
435
|
+
row["variantType"] = "sigv"
|
|
436
|
+
|
|
437
|
+
return result
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def preprocess_cosmic(rows: Iterable[Dict]) -> Iterable[Dict]:
|
|
441
|
+
"""
|
|
442
|
+
Process cosmic inputs into preformatted signature inputs
|
|
443
|
+
Note: Cosmic and dMMR already evaluated against thresholds in gsc_report
|
|
444
|
+
"""
|
|
445
|
+
cosmic = set()
|
|
446
|
+
for row in rows:
|
|
447
|
+
if not set(SIGV_COSMIC).issubset(row.keys()):
|
|
448
|
+
continue
|
|
449
|
+
cosmic.add(row[SIGV_COSMIC[0]])
|
|
450
|
+
|
|
451
|
+
return [
|
|
452
|
+
{
|
|
453
|
+
"displayName": f"{signature} {COSMIC_SIGNATURE_VARIANT_TYPE}",
|
|
454
|
+
"signatureName": signature,
|
|
455
|
+
"variantTypeName": COSMIC_SIGNATURE_VARIANT_TYPE,
|
|
456
|
+
}
|
|
457
|
+
for signature in cosmic
|
|
458
|
+
]
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def preprocess_hla(rows: Iterable[Dict]) -> Iterable[Dict]:
|
|
462
|
+
"""
|
|
463
|
+
Process hla inputs into preformatted signature inputs
|
|
464
|
+
"""
|
|
465
|
+
hla: Set[str] = set()
|
|
466
|
+
for row in rows: # 1 row per sample; should be 3
|
|
467
|
+
for k, v in row.items():
|
|
468
|
+
if k not in SIGV_HLA:
|
|
469
|
+
continue
|
|
470
|
+
hla.add(f"HLA-{v}") # 2nd level, e.g. 'HLA-A*02:01'
|
|
471
|
+
hla.add(f"HLA-{v.split(':')[0]}") # 1st level, e.g. 'HLA-A*02'
|
|
472
|
+
|
|
473
|
+
return [
|
|
474
|
+
{
|
|
475
|
+
"displayName": f"{signature} {HLA_SIGNATURE_VARIANT_TYPE}",
|
|
476
|
+
"signatureName": signature,
|
|
477
|
+
"variantTypeName": HLA_SIGNATURE_VARIANT_TYPE,
|
|
478
|
+
}
|
|
479
|
+
for signature in hla
|
|
480
|
+
]
|
|
481
|
+
|
|
482
|
+
|
|
391
483
|
def check_variant_links(
|
|
392
484
|
small_mutations: List[IprSmallMutationVariant],
|
|
393
485
|
expression_variants: List[IprExprVariant],
|
|
@@ -573,7 +665,9 @@ def extend_with_default(validator_class):
|
|
|
573
665
|
type_checker = validator_class.TYPE_CHECKER.redefine("null", check_null)
|
|
574
666
|
|
|
575
667
|
return jsonschema.validators.extend(
|
|
576
|
-
validator_class,
|
|
668
|
+
validator_class,
|
|
669
|
+
validators={"properties": set_defaults},
|
|
670
|
+
type_checker=type_checker,
|
|
577
671
|
)
|
|
578
672
|
|
|
579
673
|
|