Skip to content

Commit 9ddc55d

Browse files
authored
Merge branch 'develop' into feat/DEVSU-2616-create-project-when-submitting-a-report-with-report_async
2 parents 09a7bb0 + 2d35f42 commit 9ddc55d

3 files changed

Lines changed: 80 additions & 13 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For documentation on how to create reports using the IPR adaptor, see the [main
1515

1616
- [Getting Started](#getting-started)
1717
- [Install (For developers)](#install-for-developers)
18+
- [JSON Validate and Upload to IPR](#json-validate-and-upload-to-ipr)
1819
- [Documentation](#documentation)
1920
- [Deployment (Publishing)](#deployment-publishing)
2021

@@ -82,6 +83,17 @@ export DELETE_UPLOAD_TEST_REPORTS=0
8283
pytest tests
8384
```
8485

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+
8597
## Documentation
8698

8799
The user documentation for this tool is hosted with the [main documentation site](https://bcgsc.github.io/pori/).

pori_python/ipr/connection.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ def delete(self, uri: str, data: Dict = {}, **kwargs) -> Dict:
9595
)
9696

9797
def upload_report(
98-
self, content: Dict, mins_to_wait: int = 5, async_upload: bool = False
98+
self,
99+
content: Dict,
100+
mins_to_wait: int = 5,
101+
async_upload: bool = False,
102+
ignore_extra_fields: bool = False,
99103
) -> Dict:
100104
if async_upload:
101105
# if async is used, the response for reports-async contains either 'jobStatus'
@@ -115,7 +119,10 @@ def upload_report(
115119
except Exception as err:
116120
raise Exception(f"Project creation failed due to {err}")
117121

118-
initial_result = self.post("reports-async", content)
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)
119126

120127
report_id = initial_result["ident"]
121128

@@ -172,7 +179,10 @@ def check_status(interval: int = 5, num_attempts: int = 5):
172179

173180
return current_status
174181
else:
175-
return self.post("reports", content)
182+
if ignore_extra_fields:
183+
return self.post("reports?ignore_extra_fields=true", content)
184+
else:
185+
return self.post("reports", content)
176186

177187
def set_analyst_comments(self, report_id: str, data: Dict) -> Dict:
178188
"""
@@ -226,3 +236,11 @@ def get_spec(self) -> Dict:
226236
Get the current IPR spec, for the purposes of current report upload fields
227237
"""
228238
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

pori_python/ipr/main.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def command_interface() -> None:
108108
parser.add_argument(
109109
"-o",
110110
"--output_json_path",
111+
default=f"pori_python_report_{timestamp()}.json",
111112
help="path to a JSON to output the report upload body",
112113
)
113114
parser.add_argument(
@@ -134,6 +135,24 @@ def command_interface() -> None:
134135
action="store_true",
135136
help="True to include matches to multivariant statements where not all variants are present",
136137
)
138+
parser.add_argument(
139+
"--upload_json",
140+
default=False,
141+
action="store_true",
142+
help="True to skip all the preprocessing and just submit a json to ipr",
143+
)
144+
parser.add_argument(
145+
"--validate_json",
146+
default=False,
147+
action="store_true",
148+
help="True if only need to validate the json",
149+
)
150+
parser.add_argument(
151+
"--ignore_extra_fields",
152+
default=False,
153+
action="store_true",
154+
help="True if ignore extra fields in json",
155+
)
137156
args = parser.parse_args()
138157

139158
with open(args.content, "r") as fh:
@@ -155,6 +174,9 @@ def command_interface() -> None:
155174
async_upload=args.async_upload,
156175
mins_to_wait=args.mins_to_wait,
157176
allow_partial_matches=args.allow_partial_matches,
177+
upload_json=args.upload_json,
178+
validate_json=args.validate_json,
179+
ignore_extra_fields=args.ignore_extra_fields,
158180
)
159181

160182

@@ -288,6 +310,9 @@ def ipr_report(
288310
include_nonspecific_project: bool = False,
289311
include_nonspecific_template: bool = False,
290312
allow_partial_matches: bool = False,
313+
upload_json: bool = False,
314+
validate_json: bool = False,
315+
ignore_extra_fields: bool = False,
291316
tmb_high: float = TMB_SIGNATURE_HIGH_THRESHOLD,
292317
) -> Dict:
293318
"""Run the matching and create the report JSON for upload to IPR.
@@ -327,6 +352,20 @@ def ipr_report(
327352
format="%(asctime)s %(name)s %(levelname)s %(message)s",
328353
datefmt="%m-%d-%y %H:%M:%S",
329354
)
355+
356+
# IPR CONNECTION
357+
ipr_conn = IprConnection(username, password, ipr_url)
358+
359+
if validate_json:
360+
ipr_result = ipr_conn.validate_json(content)
361+
return ipr_result
362+
363+
if upload_json:
364+
ipr_result = ipr_conn.upload_report(
365+
content, mins_to_wait, async_upload, ignore_extra_fields
366+
)
367+
return ipr_result
368+
330369
# validate the JSON content follows the specification
331370
try:
332371
validate_report_content(content)
@@ -365,10 +404,6 @@ def ipr_report(
365404
small_mutations, expression_variants, copy_variants, structural_variants
366405
)
367406

368-
# IPR CONNECTION
369-
ipr_conn = IprConnection(username, password, ipr_url)
370-
ipr_spec = ipr_conn.get_spec()
371-
372407
# GKB CONNECTION
373408
if graphkb_url:
374409
logger.info(f"connecting to graphkb: {graphkb_url}")
@@ -509,6 +544,7 @@ def ipr_report(
509544
)
510545
output.setdefault("images", []).extend(select_expression_plots(gkb_matches, all_variants))
511546

547+
ipr_spec = ipr_conn.get_spec()
512548
output = clean_unsupported_content(output, ipr_spec)
513549
ipr_result = None
514550
upload_error = None
@@ -517,19 +553,20 @@ def ipr_report(
517553
if ipr_upload:
518554
try:
519555
logger.info(f"Uploading to IPR {ipr_conn.url}")
520-
ipr_result = ipr_conn.upload_report(output, mins_to_wait, async_upload)
556+
ipr_result = ipr_conn.upload_report(
557+
output, mins_to_wait, async_upload, ignore_extra_fields
558+
)
521559
logger.info(ipr_result)
522560
output.update(ipr_result)
523561
except Exception as err:
524562
upload_error = err
525563
logger.error(f"ipr_conn.upload_report failed: {err}", exc_info=True)
526564

527565
# SAVE TO JSON FILE
528-
if output_json_path:
529-
if always_write_output_json or not ipr_result:
530-
logger.info(f"Writing IPR upload json to: {output_json_path}")
531-
with open(output_json_path, "w") as fh:
532-
fh.write(json.dumps(output))
566+
if always_write_output_json:
567+
logger.info(f"Writing IPR upload json to: {output_json_path}")
568+
with open(output_json_path, "w") as fh:
569+
fh.write(json.dumps(output))
533570

534571
logger.info(f"made {graphkb_conn.request_count} requests to graphkb")
535572
logger.info(f"average load {int(graphkb_conn.load or 0)} req/s")

0 commit comments

Comments
 (0)