Skip to content

Commit b209e23

Browse files
committed
DEVSU-2797 - main.ipr_report - allow null ipr_url if ipr_upload = False
1 parent 7df2a3b commit b209e23

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

pori_python/ipr/main.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
preprocess_cosmic,
3232
preprocess_expression_variants,
3333
preprocess_hla,
34-
preprocess_msi,
3534
preprocess_hrd,
35+
preprocess_msi,
3636
preprocess_signature_variants,
3737
preprocess_small_mutations,
3838
preprocess_structural_variants,
@@ -294,7 +294,7 @@ def ipr_report(
294294
username: str,
295295
password: str,
296296
content: Dict,
297-
ipr_url: str,
297+
ipr_url: str = "",
298298
log_level: str = "info",
299299
output_json_path: str = "",
300300
always_write_output_json: bool = False,
@@ -324,7 +324,7 @@ def ipr_report(
324324
Args:
325325
username: the username for connecting to GraphKB and IPR
326326
password: the password for connecting to GraphKB and IPR
327-
ipr_url: base URL to use in connecting to IPR
327+
ipr_url: base URL to use in connecting to IPR (eg. https://ipr-api.bcgsc.ca/api)
328328
log_level: the logging level
329329
content: report content
330330
output_json_path: path to a JSON file to output the report upload body.
@@ -358,17 +358,24 @@ def ipr_report(
358358
)
359359

360360
# IPR CONNECTION
361-
ipr_conn = IprConnection(username, password, ipr_url)
361+
ipr_conn = None
362+
if ipr_url:
363+
ipr_conn = IprConnection(username, password, ipr_url)
364+
else:
365+
logger.warning("No ipr_url given")
362366

363367
if validate_json:
368+
if not ipr_conn:
369+
raise ValueError("ipr_url required to validate_json")
364370
ipr_result = ipr_conn.validate_json(content)
365371
return ipr_result
366372

367373
if upload_json:
374+
if not ipr_conn:
375+
raise ValueError("ipr_url required to validate_json")
368376
ipr_result = ipr_conn.upload_report(
369377
content, mins_to_wait, async_upload, ignore_extra_fields
370378
)
371-
return ipr_result
372379

373380
# validate the JSON content follows the specification
374381
try:
@@ -495,6 +502,8 @@ def ipr_report(
495502
comments_list.append(graphkb_comments)
496503

497504
if include_ipr_variant_text:
505+
if not ipr_conn:
506+
raise ValueError("ipr_url required to include_ipr_variant_text")
498507
ipr_comments = get_ipr_analyst_comments(
499508
ipr_conn,
500509
gkb_matches,
@@ -550,18 +559,18 @@ def ipr_report(
550559

551560
# if input includes hrdScore field, that is ok to pass to db
552561
# but prefer the 'hrd' field if it exists
553-
if output.get('hrd'):
554-
if output.get('hrd').get('score'):
555-
output['hrdScore'] = output['hrd']['score']
556-
output.pop('hrd') # kbmatches have already been made
562+
if output.get("hrd"):
563+
if output.get("hrd").get("score"):
564+
output["hrdScore"] = output["hrd"]["score"]
565+
output.pop("hrd") # kbmatches have already been made
557566

558-
ipr_spec = ipr_conn.get_spec()
559-
output = clean_unsupported_content(output, ipr_spec)
560567
ipr_result = {}
561568
upload_error = None
562569

563570
# UPLOAD TO IPR
564571
if ipr_upload:
572+
ipr_spec = ipr_conn.get_spec()
573+
output = clean_unsupported_content(output, ipr_spec)
565574
try:
566575
logger.info(f"Uploading to IPR {ipr_conn.url}")
567576
ipr_result = ipr_conn.upload_report(

0 commit comments

Comments
 (0)