pori-python 1.1.0__tar.gz → 1.2.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-1.1.0/pori_python.egg-info → pori_python-1.2.0}/PKG-INFO +13 -1
- {pori_python-1.1.0 → pori_python-1.2.0}/README.md +12 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/util.py +42 -2
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/connection.py +35 -3
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/ipr.py +64 -18
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/main.py +51 -11
- {pori_python-1.1.0 → pori_python-1.2.0/pori_python.egg-info}/PKG-INFO +13 -1
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python.egg-info/SOURCES.txt +1 -2
- {pori_python-1.1.0 → pori_python-1.2.0}/setup.cfg +3 -3
- pori_python-1.2.0/tests/test_graphkb/data.py +198 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/test_match.py +13 -1
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_ipr.py +56 -30
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_upload.py +4 -3
- pori_python-1.1.0/pori_python/ipr/py.typed +0 -0
- pori_python-1.1.0/tests/test_graphkb/data.py +0 -78
- {pori_python-1.1.0 → pori_python-1.2.0}/LICENSE +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/MANIFEST.in +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/__init__.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/__init__.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/constants.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/genes.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/match.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/statement.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/graphkb/vocab.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/__init__.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/annotate.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/constants.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/content.spec.json +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/inputs.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/summary.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/therapeutic_options.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/ipr/util.py +0 -0
- {pori_python-1.1.0/pori_python/graphkb → pori_python-1.2.0/pori_python}/py.typed +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python/types.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python.egg-info/dependency_links.txt +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python.egg-info/entry_points.txt +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python.egg-info/requires.txt +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pori_python.egg-info/top_level.txt +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/pyproject.toml +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/setup.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/__init__.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/__init__.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/test_genes.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/test_graphkb.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/test_statement.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/test_util.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_graphkb/test_vocab.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/__init__.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/constants.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_annotate.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_connection.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_inputs.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_main.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_probe.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_summary.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/test_util.py +0 -0
- {pori_python-1.1.0 → pori_python-1.2.0}/tests/test_ipr/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pori_python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.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
|
|
@@ -61,6 +61,7 @@ For documentation on how to create reports using the IPR adaptor, see the [main
|
|
|
61
61
|
|
|
62
62
|
- [Getting Started](#getting-started)
|
|
63
63
|
- [Install (For developers)](#install-for-developers)
|
|
64
|
+
- [JSON Validate and Upload to IPR](#json-validate-and-upload-to-ipr)
|
|
64
65
|
- [Documentation](#documentation)
|
|
65
66
|
- [Deployment (Publishing)](#deployment-publishing)
|
|
66
67
|
|
|
@@ -128,6 +129,17 @@ export DELETE_UPLOAD_TEST_REPORTS=0
|
|
|
128
129
|
pytest tests
|
|
129
130
|
```
|
|
130
131
|
|
|
132
|
+
### JSON Validate and Upload to IPR
|
|
133
|
+
If you only want to validate the json content, use
|
|
134
|
+
```bash
|
|
135
|
+
ipr --password $IPR_PASS -c 'path/to/content.json' --validate_json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
If you only want to upload the json directly to ipr and skip all the preprocessing, use
|
|
139
|
+
```bash
|
|
140
|
+
ipr --password $IPR_PASS -c 'path/to/content.json' --upload_json
|
|
141
|
+
```
|
|
142
|
+
|
|
131
143
|
## Documentation
|
|
132
144
|
|
|
133
145
|
The user documentation for this tool is hosted with the [main documentation site](https://bcgsc.github.io/pori/).
|
|
@@ -15,6 +15,7 @@ For documentation on how to create reports using the IPR adaptor, see the [main
|
|
|
15
15
|
|
|
16
16
|
- [Getting Started](#getting-started)
|
|
17
17
|
- [Install (For developers)](#install-for-developers)
|
|
18
|
+
- [JSON Validate and Upload to IPR](#json-validate-and-upload-to-ipr)
|
|
18
19
|
- [Documentation](#documentation)
|
|
19
20
|
- [Deployment (Publishing)](#deployment-publishing)
|
|
20
21
|
|
|
@@ -82,6 +83,17 @@ export DELETE_UPLOAD_TEST_REPORTS=0
|
|
|
82
83
|
pytest tests
|
|
83
84
|
```
|
|
84
85
|
|
|
86
|
+
### JSON Validate and Upload to IPR
|
|
87
|
+
If you only want to validate the json content, use
|
|
88
|
+
```bash
|
|
89
|
+
ipr --password $IPR_PASS -c 'path/to/content.json' --validate_json
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
If you only want to upload the json directly to ipr and skip all the preprocessing, use
|
|
93
|
+
```bash
|
|
94
|
+
ipr --password $IPR_PASS -c 'path/to/content.json' --upload_json
|
|
95
|
+
```
|
|
96
|
+
|
|
85
97
|
## Documentation
|
|
86
98
|
|
|
87
99
|
The user documentation for this tool is hosted with the [main documentation site](https://bcgsc.github.io/pori/).
|
|
@@ -9,6 +9,7 @@ import re
|
|
|
9
9
|
import time
|
|
10
10
|
from datetime import datetime
|
|
11
11
|
from typing import Any, Dict, Iterable, List, Optional, Union, cast
|
|
12
|
+
from urllib.parse import urlsplit
|
|
12
13
|
from urllib3.util.retry import Retry
|
|
13
14
|
|
|
14
15
|
from pori_python.types import ParsedVariant, PositionalVariant, Record
|
|
@@ -112,6 +113,7 @@ class GraphKBConnection:
|
|
|
112
113
|
)
|
|
113
114
|
self.http.mount("https://", HTTPAdapter(max_retries=retries))
|
|
114
115
|
self.token = ""
|
|
116
|
+
self.token_kc = ""
|
|
115
117
|
self.url = url
|
|
116
118
|
self.username = username
|
|
117
119
|
self.password = password
|
|
@@ -213,12 +215,45 @@ class GraphKBConnection:
|
|
|
213
215
|
"""Convenience method for making post requests."""
|
|
214
216
|
return self.request(uri, method="POST", data=json.dumps(data), **kwargs)
|
|
215
217
|
|
|
216
|
-
def
|
|
218
|
+
def login_demo(self) -> None:
|
|
219
|
+
"""
|
|
220
|
+
KBDEV-1328
|
|
221
|
+
GraphKB login in GSC's PORI online demo is done in 2 steps:
|
|
222
|
+
1. get a first token from KeyCloak using username and password; self.login_demo()
|
|
223
|
+
2. get a second token from the GraphKB API using keyCloakToken; self.login()
|
|
224
|
+
"""
|
|
225
|
+
url_parts = urlsplit(self.url)
|
|
226
|
+
base_url = f"{url_parts.scheme}://{url_parts.netloc}"
|
|
227
|
+
|
|
228
|
+
try:
|
|
229
|
+
resp = requests.request(
|
|
230
|
+
url=f"{base_url}/auth/realms/PORI/protocol/openid-connect/token",
|
|
231
|
+
method="POST",
|
|
232
|
+
data={
|
|
233
|
+
"client_id": "GraphKB",
|
|
234
|
+
"grant_type": "password",
|
|
235
|
+
"password": self.password,
|
|
236
|
+
"username": self.username,
|
|
237
|
+
},
|
|
238
|
+
)
|
|
239
|
+
except Exception as err:
|
|
240
|
+
logger.debug(f"unable to fetch a token from KeyCloak: {err}")
|
|
241
|
+
raise err
|
|
242
|
+
|
|
243
|
+
resp.raise_for_status()
|
|
244
|
+
content = resp.json()
|
|
245
|
+
self.token_kc = content["access_token"]
|
|
246
|
+
|
|
247
|
+
def login(self, username: str, password: str, pori_demo: bool = False) -> None:
|
|
217
248
|
self.username = username
|
|
218
249
|
self.password = password
|
|
219
250
|
connect_timeout = 7
|
|
220
251
|
read_timeout = 61
|
|
221
252
|
|
|
253
|
+
# KBDEV-1328. Alt. GraphKB login for GSC's PORI online demo
|
|
254
|
+
if pori_demo or "pori-demo" in self.url:
|
|
255
|
+
self.login_demo()
|
|
256
|
+
|
|
222
257
|
# use requests package directly to avoid recursion loop on login failure
|
|
223
258
|
attempts = range(10)
|
|
224
259
|
for attempt in attempts:
|
|
@@ -231,7 +266,12 @@ class GraphKBConnection:
|
|
|
231
266
|
method="POST",
|
|
232
267
|
headers=self.headers,
|
|
233
268
|
timeout=(connect_timeout, read_timeout),
|
|
234
|
-
data=json.dumps(
|
|
269
|
+
data=json.dumps(
|
|
270
|
+
# KBDEV-1328. Alt. GraphKB login for GSC's PORI online demo
|
|
271
|
+
{"keyCloakToken": self.token_kc}
|
|
272
|
+
if self.token_kc
|
|
273
|
+
else {"username": username, "password": password}
|
|
274
|
+
),
|
|
235
275
|
)
|
|
236
276
|
break
|
|
237
277
|
except (requests.exceptions.ConnectionError, OSError) as err:
|
|
@@ -95,13 +95,34 @@ class IprConnection:
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
def upload_report(
|
|
98
|
-
self,
|
|
98
|
+
self,
|
|
99
|
+
content: Dict,
|
|
100
|
+
mins_to_wait: int = 5,
|
|
101
|
+
async_upload: bool = False,
|
|
102
|
+
ignore_extra_fields: bool = False,
|
|
99
103
|
) -> Dict:
|
|
100
104
|
if async_upload:
|
|
101
105
|
# if async is used, the response for reports-async contains either 'jobStatus'
|
|
102
106
|
# or 'report'. jobStatus is no longer available once the report is successfully
|
|
103
107
|
# uploaded.
|
|
104
|
-
|
|
108
|
+
|
|
109
|
+
projects = self.get("project")
|
|
110
|
+
project_names = [item['name'] for item in projects]
|
|
111
|
+
|
|
112
|
+
# if project is not exist, create one
|
|
113
|
+
if content['project'] not in project_names:
|
|
114
|
+
logger.info(
|
|
115
|
+
f"Project not found - attempting to create project {content['project']}"
|
|
116
|
+
)
|
|
117
|
+
try:
|
|
118
|
+
self.post("project", {'name': content['project']})
|
|
119
|
+
except Exception as err:
|
|
120
|
+
raise Exception(f"Project creation failed due to {err}")
|
|
121
|
+
|
|
122
|
+
if ignore_extra_fields:
|
|
123
|
+
initial_result = self.post("reports-async?ignore_extra_fields=true", content)
|
|
124
|
+
else:
|
|
125
|
+
initial_result = self.post("reports-async", content)
|
|
105
126
|
|
|
106
127
|
report_id = initial_result["ident"]
|
|
107
128
|
|
|
@@ -158,7 +179,10 @@ class IprConnection:
|
|
|
158
179
|
|
|
159
180
|
return current_status
|
|
160
181
|
else:
|
|
161
|
-
|
|
182
|
+
if ignore_extra_fields:
|
|
183
|
+
return self.post("reports?ignore_extra_fields=true", content)
|
|
184
|
+
else:
|
|
185
|
+
return self.post("reports", content)
|
|
162
186
|
|
|
163
187
|
def set_analyst_comments(self, report_id: str, data: Dict) -> Dict:
|
|
164
188
|
"""
|
|
@@ -212,3 +236,11 @@ class IprConnection:
|
|
|
212
236
|
Get the current IPR spec, for the purposes of current report upload fields
|
|
213
237
|
"""
|
|
214
238
|
return self.request("/spec.json", method="GET")
|
|
239
|
+
|
|
240
|
+
def validate_json(self, content: Dict) -> Dict:
|
|
241
|
+
"""
|
|
242
|
+
Validate the provided json schema
|
|
243
|
+
"""
|
|
244
|
+
result = self.post("reports/schema", content)
|
|
245
|
+
logger.info(f"{result['message']}")
|
|
246
|
+
return result
|
|
@@ -4,12 +4,15 @@ by other reporting systems
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from copy import copy
|
|
9
|
-
from typing import Dict, Iterable, List, Sequence, Set, Tuple, cast
|
|
7
|
+
|
|
10
8
|
import uuid
|
|
9
|
+
from copy import copy
|
|
10
|
+
from itertools import product
|
|
11
|
+
from typing import Dict, Iterable, List, Optional, Sequence, Set, Tuple, cast
|
|
12
|
+
|
|
11
13
|
from pori_python.graphkb import GraphKBConnection
|
|
12
14
|
from pori_python.graphkb import statement as gkb_statement
|
|
15
|
+
from pori_python.graphkb import util as gkb_util
|
|
13
16
|
from pori_python.graphkb import vocab as gkb_vocab
|
|
14
17
|
from pori_python.types import (
|
|
15
18
|
Hashabledict,
|
|
@@ -18,12 +21,12 @@ from pori_python.types import (
|
|
|
18
21
|
IprGene,
|
|
19
22
|
IprVariant,
|
|
20
23
|
KbMatch,
|
|
21
|
-
Statement,
|
|
22
|
-
Variant,
|
|
23
|
-
KbVariantMatch,
|
|
24
24
|
KbMatchedStatement,
|
|
25
25
|
KbMatchedStatementConditionSet,
|
|
26
26
|
KbMatchSections,
|
|
27
|
+
KbVariantMatch,
|
|
28
|
+
Statement,
|
|
29
|
+
Variant,
|
|
27
30
|
)
|
|
28
31
|
|
|
29
32
|
from .constants import GERMLINE_BASE_TERMS, VARIANT_CLASSES
|
|
@@ -612,7 +615,7 @@ def get_kb_statement_matched_conditions(
|
|
|
612
615
|
|
|
613
616
|
def get_kb_matches_sections(
|
|
614
617
|
gkb_matches: List[KbMatch] | List[Hashabledict],
|
|
615
|
-
allow_partial_matches=False,
|
|
618
|
+
allow_partial_matches: bool = False,
|
|
616
619
|
) -> KbMatchSections:
|
|
617
620
|
kb_variants = get_kb_variants(gkb_matches)
|
|
618
621
|
kb_matched_statements = get_kb_matched_statements(gkb_matches)
|
|
@@ -627,25 +630,68 @@ def get_kb_matches_sections(
|
|
|
627
630
|
|
|
628
631
|
|
|
629
632
|
def get_kb_disease_matches(
|
|
630
|
-
graphkb_conn: GraphKBConnection,
|
|
633
|
+
graphkb_conn: GraphKBConnection,
|
|
634
|
+
kb_disease_match: Optional[str] = None,
|
|
635
|
+
verbose: bool = True,
|
|
636
|
+
useSubgraphsRoute: bool = True,
|
|
631
637
|
) -> list[str]:
|
|
632
638
|
|
|
639
|
+
disease_matches = []
|
|
640
|
+
|
|
633
641
|
if not kb_disease_match:
|
|
634
642
|
kb_disease_match = 'cancer'
|
|
635
643
|
if verbose:
|
|
636
644
|
logger.warning(f"No disease provided; will use '{kb_disease_match}'")
|
|
637
645
|
|
|
638
|
-
|
|
639
|
-
|
|
646
|
+
# Primary solution w/ subgraphs route
|
|
647
|
+
if useSubgraphsRoute:
|
|
648
|
+
if verbose:
|
|
649
|
+
logger.info(
|
|
650
|
+
f"Matching disease ({kb_disease_match}) to graphkb using 'subgraphs' API route."
|
|
651
|
+
)
|
|
640
652
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
653
|
+
try:
|
|
654
|
+
# KBDEV-1306
|
|
655
|
+
# Matching disease(s) from name, then tree traversal for ancestors & descendants.
|
|
656
|
+
# Leverage the new 'subgraphs' API route
|
|
657
|
+
base_records = gkb_util.convert_to_rid_list(
|
|
658
|
+
graphkb_conn.query(
|
|
659
|
+
gkb_vocab.query_by_name(
|
|
660
|
+
'Disease',
|
|
661
|
+
kb_disease_match,
|
|
662
|
+
)
|
|
663
|
+
)
|
|
664
|
+
)
|
|
665
|
+
if base_records:
|
|
666
|
+
response = graphkb_conn.post(
|
|
667
|
+
f'/subgraphs/Disease',
|
|
668
|
+
{
|
|
669
|
+
'subgraphType': 'tree',
|
|
670
|
+
'base': base_records,
|
|
671
|
+
},
|
|
672
|
+
)
|
|
673
|
+
disease_matches = list(response['result']['g']['nodes'].keys())
|
|
674
|
+
|
|
675
|
+
except Exception:
|
|
676
|
+
if verbose:
|
|
677
|
+
logger.info("Failed at using 'subgraphs' API route.")
|
|
678
|
+
useSubgraphsRoute = False
|
|
679
|
+
|
|
680
|
+
# Alternate solution w/ get_term_tree() -> 'similarTo' queryType route
|
|
681
|
+
# Traversal depth is limited
|
|
682
|
+
if not useSubgraphsRoute:
|
|
683
|
+
if verbose:
|
|
684
|
+
logger.info(f"Matching disease ({kb_disease_match}) to graphkb using get_term_tree()")
|
|
685
|
+
disease_matches = list(
|
|
686
|
+
{
|
|
687
|
+
r["@rid"]
|
|
688
|
+
for r in gkb_vocab.get_term_tree(
|
|
689
|
+
graphkb_conn,
|
|
690
|
+
kb_disease_match,
|
|
691
|
+
ontology_class="Disease",
|
|
692
|
+
)
|
|
693
|
+
}
|
|
647
694
|
)
|
|
648
|
-
}
|
|
649
695
|
|
|
650
696
|
if not disease_matches:
|
|
651
697
|
msg = f"failed to match disease ({kb_disease_match}) to graphkb"
|
|
@@ -653,4 +699,4 @@ def get_kb_disease_matches(
|
|
|
653
699
|
logger.error(msg)
|
|
654
700
|
raise ValueError(msg)
|
|
655
701
|
|
|
656
|
-
return
|
|
702
|
+
return disease_matches
|
|
@@ -69,6 +69,9 @@ def timestamp() -> str:
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
def command_interface() -> None:
|
|
72
|
+
"""Parse the ipr command from user input based on usage pattern.
|
|
73
|
+
Parsed arguments are used to call the ipr_report() function.
|
|
74
|
+
"""
|
|
72
75
|
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
|
73
76
|
req = parser.add_argument_group("required arguments")
|
|
74
77
|
(req if not os.environ.get("USER") else parser).add_argument(
|
|
@@ -108,6 +111,7 @@ def command_interface() -> None:
|
|
|
108
111
|
parser.add_argument(
|
|
109
112
|
"-o",
|
|
110
113
|
"--output_json_path",
|
|
114
|
+
default=f"pori_python_report_{timestamp()}.json",
|
|
111
115
|
help="path to a JSON to output the report upload body",
|
|
112
116
|
)
|
|
113
117
|
parser.add_argument(
|
|
@@ -134,12 +138,30 @@ def command_interface() -> None:
|
|
|
134
138
|
action="store_true",
|
|
135
139
|
help="True to include matches to multivariant statements where not all variants are present",
|
|
136
140
|
)
|
|
141
|
+
parser.add_argument(
|
|
142
|
+
"--upload_json",
|
|
143
|
+
default=False,
|
|
144
|
+
action="store_true",
|
|
145
|
+
help="True to skip all the preprocessing and just submit a json to ipr",
|
|
146
|
+
)
|
|
147
|
+
parser.add_argument(
|
|
148
|
+
"--validate_json",
|
|
149
|
+
default=False,
|
|
150
|
+
action="store_true",
|
|
151
|
+
help="True if only need to validate the json",
|
|
152
|
+
)
|
|
153
|
+
parser.add_argument(
|
|
154
|
+
"--ignore_extra_fields",
|
|
155
|
+
default=False,
|
|
156
|
+
action="store_true",
|
|
157
|
+
help="True if ignore extra fields in json",
|
|
158
|
+
)
|
|
137
159
|
args = parser.parse_args()
|
|
138
160
|
|
|
139
161
|
with open(args.content, "r") as fh:
|
|
140
162
|
content = json.load(fh)
|
|
141
163
|
|
|
142
|
-
|
|
164
|
+
ipr_report(
|
|
143
165
|
username=args.username,
|
|
144
166
|
password=args.password,
|
|
145
167
|
content=content,
|
|
@@ -155,6 +177,9 @@ def command_interface() -> None:
|
|
|
155
177
|
async_upload=args.async_upload,
|
|
156
178
|
mins_to_wait=args.mins_to_wait,
|
|
157
179
|
allow_partial_matches=args.allow_partial_matches,
|
|
180
|
+
upload_json=args.upload_json,
|
|
181
|
+
validate_json=args.validate_json,
|
|
182
|
+
ignore_extra_fields=args.ignore_extra_fields,
|
|
158
183
|
)
|
|
159
184
|
|
|
160
185
|
|
|
@@ -288,6 +313,9 @@ def ipr_report(
|
|
|
288
313
|
include_nonspecific_project: bool = False,
|
|
289
314
|
include_nonspecific_template: bool = False,
|
|
290
315
|
allow_partial_matches: bool = False,
|
|
316
|
+
upload_json: bool = False,
|
|
317
|
+
validate_json: bool = False,
|
|
318
|
+
ignore_extra_fields: bool = False,
|
|
291
319
|
tmb_high: float = TMB_SIGNATURE_HIGH_THRESHOLD,
|
|
292
320
|
) -> Dict:
|
|
293
321
|
"""Run the matching and create the report JSON for upload to IPR.
|
|
@@ -327,6 +355,20 @@ def ipr_report(
|
|
|
327
355
|
format="%(asctime)s %(name)s %(levelname)s %(message)s",
|
|
328
356
|
datefmt="%m-%d-%y %H:%M:%S",
|
|
329
357
|
)
|
|
358
|
+
|
|
359
|
+
# IPR CONNECTION
|
|
360
|
+
ipr_conn = IprConnection(username, password, ipr_url)
|
|
361
|
+
|
|
362
|
+
if validate_json:
|
|
363
|
+
ipr_result = ipr_conn.validate_json(content)
|
|
364
|
+
return ipr_result
|
|
365
|
+
|
|
366
|
+
if upload_json:
|
|
367
|
+
ipr_result = ipr_conn.upload_report(
|
|
368
|
+
content, mins_to_wait, async_upload, ignore_extra_fields
|
|
369
|
+
)
|
|
370
|
+
return ipr_result
|
|
371
|
+
|
|
330
372
|
# validate the JSON content follows the specification
|
|
331
373
|
try:
|
|
332
374
|
validate_report_content(content)
|
|
@@ -365,10 +407,6 @@ def ipr_report(
|
|
|
365
407
|
small_mutations, expression_variants, copy_variants, structural_variants
|
|
366
408
|
)
|
|
367
409
|
|
|
368
|
-
# IPR CONNECTION
|
|
369
|
-
ipr_conn = IprConnection(username, password, ipr_url)
|
|
370
|
-
ipr_spec = ipr_conn.get_spec()
|
|
371
|
-
|
|
372
410
|
# GKB CONNECTION
|
|
373
411
|
if graphkb_url:
|
|
374
412
|
logger.info(f"connecting to graphkb: {graphkb_url}")
|
|
@@ -509,6 +547,7 @@ def ipr_report(
|
|
|
509
547
|
)
|
|
510
548
|
output.setdefault("images", []).extend(select_expression_plots(gkb_matches, all_variants))
|
|
511
549
|
|
|
550
|
+
ipr_spec = ipr_conn.get_spec()
|
|
512
551
|
output = clean_unsupported_content(output, ipr_spec)
|
|
513
552
|
ipr_result = None
|
|
514
553
|
upload_error = None
|
|
@@ -517,7 +556,9 @@ def ipr_report(
|
|
|
517
556
|
if ipr_upload:
|
|
518
557
|
try:
|
|
519
558
|
logger.info(f"Uploading to IPR {ipr_conn.url}")
|
|
520
|
-
ipr_result = ipr_conn.upload_report(
|
|
559
|
+
ipr_result = ipr_conn.upload_report(
|
|
560
|
+
output, mins_to_wait, async_upload, ignore_extra_fields
|
|
561
|
+
)
|
|
521
562
|
logger.info(ipr_result)
|
|
522
563
|
output.update(ipr_result)
|
|
523
564
|
except Exception as err:
|
|
@@ -525,11 +566,10 @@ def ipr_report(
|
|
|
525
566
|
logger.error(f"ipr_conn.upload_report failed: {err}", exc_info=True)
|
|
526
567
|
|
|
527
568
|
# SAVE TO JSON FILE
|
|
528
|
-
if
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
fh.write(json.dumps(output))
|
|
569
|
+
if always_write_output_json:
|
|
570
|
+
logger.info(f"Writing IPR upload json to: {output_json_path}")
|
|
571
|
+
with open(output_json_path, "w") as fh:
|
|
572
|
+
fh.write(json.dumps(output))
|
|
533
573
|
|
|
534
574
|
logger.info(f"made {graphkb_conn.request_count} requests to graphkb")
|
|
535
575
|
logger.info(f"average load {int(graphkb_conn.load or 0)} req/s")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pori_python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.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
|
|
@@ -61,6 +61,7 @@ For documentation on how to create reports using the IPR adaptor, see the [main
|
|
|
61
61
|
|
|
62
62
|
- [Getting Started](#getting-started)
|
|
63
63
|
- [Install (For developers)](#install-for-developers)
|
|
64
|
+
- [JSON Validate and Upload to IPR](#json-validate-and-upload-to-ipr)
|
|
64
65
|
- [Documentation](#documentation)
|
|
65
66
|
- [Deployment (Publishing)](#deployment-publishing)
|
|
66
67
|
|
|
@@ -128,6 +129,17 @@ export DELETE_UPLOAD_TEST_REPORTS=0
|
|
|
128
129
|
pytest tests
|
|
129
130
|
```
|
|
130
131
|
|
|
132
|
+
### JSON Validate and Upload to IPR
|
|
133
|
+
If you only want to validate the json content, use
|
|
134
|
+
```bash
|
|
135
|
+
ipr --password $IPR_PASS -c 'path/to/content.json' --validate_json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
If you only want to upload the json directly to ipr and skip all the preprocessing, use
|
|
139
|
+
```bash
|
|
140
|
+
ipr --password $IPR_PASS -c 'path/to/content.json' --upload_json
|
|
141
|
+
```
|
|
142
|
+
|
|
131
143
|
## Documentation
|
|
132
144
|
|
|
133
145
|
The user documentation for this tool is hosted with the [main documentation site](https://bcgsc.github.io/pori/).
|
|
@@ -5,6 +5,7 @@ pyproject.toml
|
|
|
5
5
|
setup.cfg
|
|
6
6
|
setup.py
|
|
7
7
|
pori_python/__init__.py
|
|
8
|
+
pori_python/py.typed
|
|
8
9
|
pori_python/types.py
|
|
9
10
|
pori_python.egg-info/PKG-INFO
|
|
10
11
|
pori_python.egg-info/SOURCES.txt
|
|
@@ -16,7 +17,6 @@ pori_python/graphkb/__init__.py
|
|
|
16
17
|
pori_python/graphkb/constants.py
|
|
17
18
|
pori_python/graphkb/genes.py
|
|
18
19
|
pori_python/graphkb/match.py
|
|
19
|
-
pori_python/graphkb/py.typed
|
|
20
20
|
pori_python/graphkb/statement.py
|
|
21
21
|
pori_python/graphkb/util.py
|
|
22
22
|
pori_python/graphkb/vocab.py
|
|
@@ -28,7 +28,6 @@ pori_python/ipr/content.spec.json
|
|
|
28
28
|
pori_python/ipr/inputs.py
|
|
29
29
|
pori_python/ipr/ipr.py
|
|
30
30
|
pori_python/ipr/main.py
|
|
31
|
-
pori_python/ipr/py.typed
|
|
32
31
|
pori_python/ipr/summary.py
|
|
33
32
|
pori_python/ipr/therapeutic_options.py
|
|
34
33
|
pori_python/ipr/util.py
|
|
@@ -17,7 +17,7 @@ known_standard_library = requests
|
|
|
17
17
|
|
|
18
18
|
[metadata]
|
|
19
19
|
name = pori_python
|
|
20
|
-
version = 1.
|
|
20
|
+
version = 1.2.0
|
|
21
21
|
url = https://github.com/bcgsc/pori_python
|
|
22
22
|
author_email = dat@bcgsc.ca
|
|
23
23
|
maintainer_email = dat@bcgsc.ca
|
|
@@ -59,8 +59,8 @@ dev =
|
|
|
59
59
|
mypy
|
|
60
60
|
|
|
61
61
|
[options.package_data]
|
|
62
|
-
pori_python.ipr = content.spec.json
|
|
63
|
-
pori_python
|
|
62
|
+
pori_python.ipr = content.spec.json
|
|
63
|
+
pori_python = py.typed
|
|
64
64
|
|
|
65
65
|
[options.entry_points]
|
|
66
66
|
console_scripts =
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Screening structural variant to rule out small events [KBDEV_1056]
|
|
2
|
+
#
|
|
3
|
+
# matches:
|
|
4
|
+
# Array of variants (diplayName and type) that MUST be matching, but not restricted to
|
|
5
|
+
# does_not_matches:
|
|
6
|
+
# Array of variants (diplayName and type) that MUST NOT be matching, but not restricted to
|
|
7
|
+
#
|
|
8
|
+
structuralVariants = {
|
|
9
|
+
# Unambiguous structural variations
|
|
10
|
+
"(FGFR3,BRCA2):fusion(g.1234567,g.1234567)": {
|
|
11
|
+
"matches": {
|
|
12
|
+
"displayName": ["FGFR3 fusion", "FGFR3 rearrangement"],
|
|
13
|
+
"type": ["fusion", "rearrangement"],
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
# ambiguous structural variations -> structural
|
|
17
|
+
"FGFR3:c.1200_1300dup": {
|
|
18
|
+
"matches": {
|
|
19
|
+
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
20
|
+
"type": ["mutation", "rearrangement"],
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"FGFR3:c.1200_1201insACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT": {
|
|
24
|
+
"matches": {
|
|
25
|
+
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
26
|
+
"type": ["mutation", "rearrangement"],
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"FGFR3:g.5000_5100del": {
|
|
30
|
+
"matches": {
|
|
31
|
+
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
32
|
+
"type": ["mutation", "rearrangement"],
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"FGFR3:c.1200_1300delinsA": {
|
|
36
|
+
"matches": {
|
|
37
|
+
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
38
|
+
"type": ["mutation", "rearrangement"],
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"FGFR3:c.1200delinsACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT": {
|
|
42
|
+
"matches": {
|
|
43
|
+
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
44
|
+
"type": ["mutation", "rearrangement"],
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
# ambiguous structural variations -> non-structural
|
|
48
|
+
"FGFR3:c.1200dup": {
|
|
49
|
+
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
50
|
+
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
51
|
+
},
|
|
52
|
+
"FGFR3:c.1200_1201insA": {
|
|
53
|
+
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
54
|
+
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
55
|
+
},
|
|
56
|
+
"FGFR3:g.5000del": {
|
|
57
|
+
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
58
|
+
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
59
|
+
},
|
|
60
|
+
"FGFR3:c.1200delinsA": {
|
|
61
|
+
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
62
|
+
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
63
|
+
},
|
|
64
|
+
"STK11:e.1_100del": {
|
|
65
|
+
"matches": {"displayName": ["STK11 mutation"], "type": ["mutation"]},
|
|
66
|
+
"does_not_matches": {"displayName": ["STK11 deletion"], "type": ["deletion"]},
|
|
67
|
+
},
|
|
68
|
+
"STK11:i.1_100del": {
|
|
69
|
+
"matches": {"displayName": ["STK11 mutation"], "type": ["mutation"]},
|
|
70
|
+
"does_not_matches": {"displayName": ["STK11 deletion"], "type": ["deletion"]},
|
|
71
|
+
},
|
|
72
|
+
# non-structural variations
|
|
73
|
+
"FGFR3:c.1200C>A": {
|
|
74
|
+
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
75
|
+
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# KBDEV-1163.
|
|
80
|
+
# pos 0: a feature
|
|
81
|
+
# pos 1: expected equivalences
|
|
82
|
+
ensemblProteinSample = [
|
|
83
|
+
(
|
|
84
|
+
'EGFR',
|
|
85
|
+
[
|
|
86
|
+
'EGFR',
|
|
87
|
+
'ERBB',
|
|
88
|
+
'ENSG00000146648',
|
|
89
|
+
'ENSG00000146648.17',
|
|
90
|
+
'ENST00000275493',
|
|
91
|
+
'ENST00000275493.6',
|
|
92
|
+
'NM_001346897',
|
|
93
|
+
'NM_001346897.2',
|
|
94
|
+
'NP_001333826',
|
|
95
|
+
'NP_001333826.1',
|
|
96
|
+
],
|
|
97
|
+
),
|
|
98
|
+
(
|
|
99
|
+
'NM_001346897',
|
|
100
|
+
[
|
|
101
|
+
'EGFR',
|
|
102
|
+
'ERBB',
|
|
103
|
+
'ENSG00000146648',
|
|
104
|
+
'ENSG00000146648.17',
|
|
105
|
+
'NM_001346897',
|
|
106
|
+
'NM_001346897.2',
|
|
107
|
+
'NP_001333826',
|
|
108
|
+
'NP_001333826.1',
|
|
109
|
+
],
|
|
110
|
+
),
|
|
111
|
+
(
|
|
112
|
+
'NM_001346897.2',
|
|
113
|
+
[
|
|
114
|
+
'EGFR',
|
|
115
|
+
'ERBB',
|
|
116
|
+
'ENSG00000146648',
|
|
117
|
+
'ENSG00000146648.17',
|
|
118
|
+
'NM_001346897',
|
|
119
|
+
'NM_001346897.2',
|
|
120
|
+
'NP_001333826',
|
|
121
|
+
'NP_001333826.1',
|
|
122
|
+
],
|
|
123
|
+
),
|
|
124
|
+
(
|
|
125
|
+
'NP_001333826',
|
|
126
|
+
[
|
|
127
|
+
'EGFR',
|
|
128
|
+
'ERBB',
|
|
129
|
+
'ENSG00000146648', # Warn: Versionized ENSG won't be returned due to API limitations
|
|
130
|
+
'NM_001346897',
|
|
131
|
+
'NM_001346897.2',
|
|
132
|
+
'NP_001333826',
|
|
133
|
+
'NP_001333826.1',
|
|
134
|
+
],
|
|
135
|
+
),
|
|
136
|
+
(
|
|
137
|
+
'NP_001333826.1',
|
|
138
|
+
[
|
|
139
|
+
'EGFR',
|
|
140
|
+
'ERBB',
|
|
141
|
+
'ENSG00000146648', # Warn: Versionized ENSG won't be returned due to API limitations
|
|
142
|
+
'NM_001346897',
|
|
143
|
+
'NM_001346897.2',
|
|
144
|
+
'NP_001333826',
|
|
145
|
+
'NP_001333826.1',
|
|
146
|
+
],
|
|
147
|
+
),
|
|
148
|
+
(
|
|
149
|
+
'ENSG00000146648',
|
|
150
|
+
[
|
|
151
|
+
'EGFR',
|
|
152
|
+
'ERBB',
|
|
153
|
+
'ENSG00000146648',
|
|
154
|
+
'ENSG00000146648.17',
|
|
155
|
+
'ENST00000275493',
|
|
156
|
+
'ENST00000275493.6',
|
|
157
|
+
'NM_001346897',
|
|
158
|
+
'NM_001346897.2',
|
|
159
|
+
'NP_001333826', # Warn: Versionized NP won't be returned due to API limitations
|
|
160
|
+
],
|
|
161
|
+
),
|
|
162
|
+
(
|
|
163
|
+
'ENSG00000146648.17',
|
|
164
|
+
[
|
|
165
|
+
'EGFR',
|
|
166
|
+
'ERBB',
|
|
167
|
+
'ENSG00000146648',
|
|
168
|
+
'ENSG00000146648.17',
|
|
169
|
+
'ENST00000275493',
|
|
170
|
+
'ENST00000275493.6',
|
|
171
|
+
'NM_001346897',
|
|
172
|
+
'NM_001346897.2',
|
|
173
|
+
'NP_001333826', # Warn: Versionized NP won't be returned due to API limitations
|
|
174
|
+
],
|
|
175
|
+
),
|
|
176
|
+
(
|
|
177
|
+
'ENST00000275493',
|
|
178
|
+
[
|
|
179
|
+
'EGFR',
|
|
180
|
+
'ERBB',
|
|
181
|
+
'ENSG00000146648',
|
|
182
|
+
'ENSG00000146648.17',
|
|
183
|
+
'ENST00000275493',
|
|
184
|
+
'ENST00000275493.6',
|
|
185
|
+
],
|
|
186
|
+
),
|
|
187
|
+
(
|
|
188
|
+
'ENST00000275493.6',
|
|
189
|
+
[
|
|
190
|
+
'EGFR',
|
|
191
|
+
'ERBB',
|
|
192
|
+
'ENSG00000146648',
|
|
193
|
+
'ENSG00000146648.17',
|
|
194
|
+
'ENST00000275493',
|
|
195
|
+
'ENST00000275493.6',
|
|
196
|
+
],
|
|
197
|
+
),
|
|
198
|
+
]
|
|
@@ -13,7 +13,7 @@ from pori_python.graphkb.constants import (
|
|
|
13
13
|
from pori_python.graphkb.util import FeatureNotFoundError
|
|
14
14
|
|
|
15
15
|
# Test datasets
|
|
16
|
-
from .data import structuralVariants
|
|
16
|
+
from .data import ensemblProteinSample, structuralVariants
|
|
17
17
|
|
|
18
18
|
EXCLUDE_BCGSC_TESTS = os.environ.get("EXCLUDE_BCGSC_TESTS") == "1"
|
|
19
19
|
EXCLUDE_INTEGRATION_TESTS = os.environ.get("EXCLUDE_INTEGRATION_TESTS") == "1"
|
|
@@ -101,6 +101,18 @@ class TestGetEquivalentFeatures:
|
|
|
101
101
|
]
|
|
102
102
|
assert "KRAS" in kras
|
|
103
103
|
|
|
104
|
+
# KBDEV-1163
|
|
105
|
+
# Testing if the addition of Ensembl protein Features are limiting results
|
|
106
|
+
# returned by get_equivalent_features() since SimilatTo queryType queries
|
|
107
|
+
# aren't traversing the graph to it's whole depth.
|
|
108
|
+
@pytest.mark.skipif(EXCLUDE_INTEGRATION_TESTS, reason="excluding data-specific test")
|
|
109
|
+
def test_ensembl_protein(self, conn):
|
|
110
|
+
for feature, expected in ensemblProteinSample:
|
|
111
|
+
equivalent_features = match.get_equivalent_features(conn, feature)
|
|
112
|
+
equivalent_features = [el['displayName'] for el in equivalent_features]
|
|
113
|
+
for equivalent_feature in expected:
|
|
114
|
+
assert equivalent_feature in equivalent_features
|
|
115
|
+
|
|
104
116
|
|
|
105
117
|
class TestMatchCopyVariant:
|
|
106
118
|
def test_bad_category(self, conn):
|
|
@@ -6,6 +6,7 @@ from pori_python.graphkb import vocab as gkb_vocab
|
|
|
6
6
|
from pori_python.ipr.ipr import (
|
|
7
7
|
convert_statements_to_alterations,
|
|
8
8
|
germline_kb_matches,
|
|
9
|
+
get_kb_disease_matches,
|
|
9
10
|
get_kb_matched_statements,
|
|
10
11
|
get_kb_statement_matched_conditions,
|
|
11
12
|
get_kb_variants,
|
|
@@ -170,33 +171,6 @@ KB_MATCHES_STATEMENTS = [
|
|
|
170
171
|
]
|
|
171
172
|
|
|
172
173
|
|
|
173
|
-
@pytest.fixture
|
|
174
|
-
def graphkb_conn():
|
|
175
|
-
class QueryMock:
|
|
176
|
-
return_values = [
|
|
177
|
-
# get approved evidence levels
|
|
178
|
-
[{"@rid": v} for v in APPROVED_EVIDENCE_RIDS]
|
|
179
|
-
]
|
|
180
|
-
index = -1
|
|
181
|
-
|
|
182
|
-
def __call__(self, *args, **kwargs):
|
|
183
|
-
self.index += 1
|
|
184
|
-
ret_val = self.return_values[self.index] if self.index < len(self.return_values) else []
|
|
185
|
-
return ret_val
|
|
186
|
-
|
|
187
|
-
class PostMock:
|
|
188
|
-
def __call__(self, *args, **kwargs):
|
|
189
|
-
# custom return tailored for multi_variant_filtering() testing
|
|
190
|
-
return {"result": KB_MATCHES_STATEMENTS}
|
|
191
|
-
|
|
192
|
-
def mock_get_source(source):
|
|
193
|
-
return {"@rid": 0}
|
|
194
|
-
|
|
195
|
-
conn = Mock(query=QueryMock(), cache={}, get_source=mock_get_source, post=PostMock())
|
|
196
|
-
|
|
197
|
-
return conn
|
|
198
|
-
|
|
199
|
-
|
|
200
174
|
def base_graphkb_statement(disease_id: str = "disease", relevance_rid: str = "other") -> Statement:
|
|
201
175
|
statement = Statement( # type: ignore
|
|
202
176
|
{
|
|
@@ -231,12 +205,48 @@ def base_graphkb_statement(disease_id: str = "disease", relevance_rid: str = "ot
|
|
|
231
205
|
return statement
|
|
232
206
|
|
|
233
207
|
|
|
208
|
+
@pytest.fixture
|
|
209
|
+
def graphkb_conn():
|
|
210
|
+
# Mock for the 'query' method
|
|
211
|
+
query_mock = Mock()
|
|
212
|
+
query_return_values = [[{"@rid": v} for v in APPROVED_EVIDENCE_RIDS]]
|
|
213
|
+
query_index = {"value": -1} # Mutable index for closure
|
|
214
|
+
|
|
215
|
+
def query_side_effect(*args, **kwargs):
|
|
216
|
+
if args:
|
|
217
|
+
# for TestGetKbDiseaseMatches
|
|
218
|
+
return [{'@rid': '#123:45'}]
|
|
219
|
+
query_index["value"] += 1
|
|
220
|
+
idx = query_index["value"]
|
|
221
|
+
return query_return_values[idx] if idx < len(query_return_values) else []
|
|
222
|
+
|
|
223
|
+
query_mock.side_effect = query_side_effect
|
|
224
|
+
|
|
225
|
+
# Mock for the 'post' method
|
|
226
|
+
post_mock = Mock(return_value={"result": KB_MATCHES_STATEMENTS})
|
|
227
|
+
|
|
228
|
+
# 'get_source' remains a plain function
|
|
229
|
+
def mock_get_source(source):
|
|
230
|
+
return {"@rid": 0}
|
|
231
|
+
|
|
232
|
+
# Create the connection mock with attributes
|
|
233
|
+
conn = Mock()
|
|
234
|
+
conn.query = query_mock
|
|
235
|
+
conn.post = post_mock
|
|
236
|
+
conn.cache = {}
|
|
237
|
+
conn.get_source = mock_get_source
|
|
238
|
+
|
|
239
|
+
yield conn
|
|
240
|
+
query_mock.reset_mock()
|
|
241
|
+
post_mock.reset_mock()
|
|
242
|
+
|
|
243
|
+
|
|
234
244
|
@pytest.fixture(autouse=True)
|
|
235
245
|
def mock_get_term_tree(monkeypatch):
|
|
236
|
-
|
|
237
|
-
return [{"@rid": d} for d in DISEASE_RIDS]
|
|
238
|
-
|
|
246
|
+
mock_func = Mock(return_value=[{"@rid": d} for d in DISEASE_RIDS])
|
|
239
247
|
monkeypatch.setattr(gkb_vocab, "get_term_tree", mock_func)
|
|
248
|
+
yield mock_func
|
|
249
|
+
mock_func.reset_mock()
|
|
240
250
|
|
|
241
251
|
|
|
242
252
|
@pytest.fixture(autouse=True)
|
|
@@ -255,6 +265,22 @@ def mock_categorize_relevance(monkeypatch):
|
|
|
255
265
|
monkeypatch.setattr(gkb_statement, "categorize_relevance", mock_func)
|
|
256
266
|
|
|
257
267
|
|
|
268
|
+
class TestGetKbDiseaseMatches:
|
|
269
|
+
def test_get_kb_disease_matches_default_disease(self, graphkb_conn) -> None:
|
|
270
|
+
get_kb_disease_matches(graphkb_conn) # default to 'cancer'
|
|
271
|
+
assert graphkb_conn.post.called
|
|
272
|
+
assert graphkb_conn.post.call_args_list[0].args[0] == '/subgraphs/Disease'
|
|
273
|
+
|
|
274
|
+
def test_get_kb_disease_matches_disease_with_subgraphs(self, graphkb_conn) -> None:
|
|
275
|
+
get_kb_disease_matches(graphkb_conn, 'Breast Cancer')
|
|
276
|
+
assert graphkb_conn.post.called
|
|
277
|
+
assert graphkb_conn.post.call_args_list[0].args[0] == '/subgraphs/Disease'
|
|
278
|
+
|
|
279
|
+
def test_get_kb_disease_matches_get_term_tree(self, graphkb_conn) -> None:
|
|
280
|
+
get_kb_disease_matches(graphkb_conn, 'Breast Cancer', useSubgraphsRoute=False)
|
|
281
|
+
assert not graphkb_conn.post.called
|
|
282
|
+
|
|
283
|
+
|
|
258
284
|
class TestConvertStatementsToAlterations:
|
|
259
285
|
def test_disease_match(self, graphkb_conn) -> None:
|
|
260
286
|
statement = base_graphkb_statement(DISEASE_RIDS[0])
|
|
@@ -83,9 +83,9 @@ def loaded_reports(tmp_path_factory) -> Generator:
|
|
|
83
83
|
pd.read_csv(get_test_file("fusions.tab"), sep="\t").to_json(orient="records")
|
|
84
84
|
),
|
|
85
85
|
"kbDiseaseMatch": "colorectal cancer",
|
|
86
|
-
"cosmicSignatures":
|
|
87
|
-
|
|
88
|
-
),
|
|
86
|
+
"cosmicSignatures": pd.read_csv(
|
|
87
|
+
get_test_file("cosmic_variants.tab"), sep="\t"
|
|
88
|
+
).signature.tolist(),
|
|
89
89
|
"hlaTypes": json.loads(
|
|
90
90
|
pd.read_csv(get_test_file("hla_variants.tab"), sep="\t").to_json(orient="records")
|
|
91
91
|
),
|
|
@@ -97,6 +97,7 @@ def loaded_reports(tmp_path_factory) -> Generator:
|
|
|
97
97
|
}
|
|
98
98
|
],
|
|
99
99
|
}
|
|
100
|
+
|
|
100
101
|
json_file.write_text(
|
|
101
102
|
json.dumps(
|
|
102
103
|
json_contents,
|
|
File without changes
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"""_summary_
|
|
2
|
-
matches:
|
|
3
|
-
Array of variants (diplayName and type) that MUST be matching, but not restricted to
|
|
4
|
-
does_not_matches:
|
|
5
|
-
Array of variants (diplayName and type) that MUST NOT be matching, but not restricted to
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
# Screening structural variant to rule out small events [KBDEV_1056]
|
|
9
|
-
structuralVariants = {
|
|
10
|
-
# Unambiguous structural variations
|
|
11
|
-
"(FGFR3,BRCA2):fusion(g.1234567,g.1234567)": {
|
|
12
|
-
"matches": {
|
|
13
|
-
"displayName": ["FGFR3 fusion", "FGFR3 rearrangement"],
|
|
14
|
-
"type": ["fusion", "rearrangement"],
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
# ambiguous structural variations -> structural
|
|
18
|
-
"FGFR3:c.1200_1300dup": {
|
|
19
|
-
"matches": {
|
|
20
|
-
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
21
|
-
"type": ["mutation", "rearrangement"],
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"FGFR3:c.1200_1201insACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT": {
|
|
25
|
-
"matches": {
|
|
26
|
-
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
27
|
-
"type": ["mutation", "rearrangement"],
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"FGFR3:g.5000_5100del": {
|
|
31
|
-
"matches": {
|
|
32
|
-
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
33
|
-
"type": ["mutation", "rearrangement"],
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"FGFR3:c.1200_1300delinsA": {
|
|
37
|
-
"matches": {
|
|
38
|
-
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
39
|
-
"type": ["mutation", "rearrangement"],
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"FGFR3:c.1200delinsACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT": {
|
|
43
|
-
"matches": {
|
|
44
|
-
"displayName": ["FGFR3 mutation", "FGFR3 rearrangement"],
|
|
45
|
-
"type": ["mutation", "rearrangement"],
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
# ambiguous structural variations -> non-structural
|
|
49
|
-
"FGFR3:c.1200dup": {
|
|
50
|
-
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
51
|
-
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
52
|
-
},
|
|
53
|
-
"FGFR3:c.1200_1201insA": {
|
|
54
|
-
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
55
|
-
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
56
|
-
},
|
|
57
|
-
"FGFR3:g.5000del": {
|
|
58
|
-
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
59
|
-
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
60
|
-
},
|
|
61
|
-
"FGFR3:c.1200delinsA": {
|
|
62
|
-
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
63
|
-
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
64
|
-
},
|
|
65
|
-
"STK11:e.1_100del": {
|
|
66
|
-
"matches": {"displayName": ["STK11 mutation"], "type": ["mutation"]},
|
|
67
|
-
"does_not_matches": {"displayName": ["STK11 deletion"], "type": ["deletion"]},
|
|
68
|
-
},
|
|
69
|
-
"STK11:i.1_100del": {
|
|
70
|
-
"matches": {"displayName": ["STK11 mutation"], "type": ["mutation"]},
|
|
71
|
-
"does_not_matches": {"displayName": ["STK11 deletion"], "type": ["deletion"]},
|
|
72
|
-
},
|
|
73
|
-
# non-structural variations
|
|
74
|
-
"FGFR3:c.1200C>A": {
|
|
75
|
-
"matches": {"displayName": ["FGFR3 mutation"], "type": ["mutation"]},
|
|
76
|
-
"does_not_matches": {"displayName": ["FGFR3 rearrangement"], "type": ["rearrangement"]},
|
|
77
|
-
},
|
|
78
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|