Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pori_python/graphkb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def login_demo(self) -> None:
1. get a first token from KeyCloak using username and password; self.login_demo()
2. get a second token from the GraphKB API using keyCloakToken; self.login()
"""
if not self.url:
raise ValueError("no self.url set - cannot make a login demo")
url_parts = urlsplit(self.url)
base_url = f"{url_parts.scheme}://{url_parts.netloc}"

Expand Down Expand Up @@ -251,7 +253,8 @@ def login(self, username: str, password: str, pori_demo: bool = False) -> None:
read_timeout = 61

# KBDEV-1328. Alt. GraphKB login for GSC's PORI online demo
if pori_demo or "pori-demo" in self.url:
if self.url and (pori_demo or "pori-demo" in self.url):
logger.warning("login demo")
self.login_demo()

# use requests package directly to avoid recursion loop on login failure
Expand Down
2 changes: 1 addition & 1 deletion pori_python/ipr/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from .constants import (
COSMIC_SIGNATURE_VARIANT_TYPE,
HLA_SIGNATURE_VARIANT_TYPE,
MSI_MAPPING,
HRD_MAPPING,
MSI_MAPPING,
TMB_SIGNATURE,
TMB_SIGNATURE_VARIANT_TYPE,
)
Expand Down
2 changes: 1 addition & 1 deletion pori_python/ipr/ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def convert_statements_to_alterations(
diseases = [c for c in statement["conditions"] if c["@class"] == "Disease"]
disease_match = len(diseases) == 1 and diseases[0]["@rid"] in disease_matches
reference = ";".join([e["displayName"] for e in statement["evidence"]])
if statement['relevance']['name'] == 'eligibility':
if statement["relevance"]["name"] == "eligibility":
reference = ";".join([e["sourceId"] for e in statement["evidence"]])

ipr_section = gkb_statement.categorize_relevance(
Expand Down
42 changes: 28 additions & 14 deletions pori_python/ipr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
preprocess_cosmic,
preprocess_expression_variants,
preprocess_hla,
preprocess_msi,
preprocess_hrd,
preprocess_msi,
preprocess_signature_variants,
preprocess_small_mutations,
preprocess_structural_variants,
Expand Down Expand Up @@ -294,7 +294,7 @@ def ipr_report(
username: str,
password: str,
content: Dict,
ipr_url: str,
ipr_url: str = "",
log_level: str = "info",
output_json_path: str = "",
always_write_output_json: bool = False,
Expand Down Expand Up @@ -324,7 +324,7 @@ def ipr_report(
Args:
username: the username for connecting to GraphKB and IPR
password: the password for connecting to GraphKB and IPR
ipr_url: base URL to use in connecting to IPR
ipr_url: base URL to use in connecting to IPR (eg. https://ipr-api.bcgsc.ca/api)
log_level: the logging level
content: report content
output_json_path: path to a JSON file to output the report upload body.
Expand Down Expand Up @@ -358,13 +358,22 @@ def ipr_report(
)

# IPR CONNECTION
ipr_conn = IprConnection(username, password, ipr_url)
ipr_url = ipr_url if ipr_url else os.environ.get("IPR_URL", "")
ipr_conn = None
if ipr_url:
ipr_conn = IprConnection(username, password, ipr_url)
else:
logger.warning("No ipr_url given")

if validate_json:
if not ipr_conn:
raise ValueError("ipr_url required to validate_json")
ipr_result = ipr_conn.validate_json(content)
return ipr_result

if upload_json:
if not ipr_conn:
raise ValueError("ipr_url required to upload_json")
ipr_result = ipr_conn.upload_report(
content, mins_to_wait, async_upload, ignore_extra_fields
)
Expand Down Expand Up @@ -410,14 +419,15 @@ def ipr_report(
)

# GKB CONNECTION
gkb_user = graphkb_username if graphkb_username else username
gkb_pass = graphkb_password if graphkb_password else password
graphkb_url = graphkb_url if graphkb_url else os.environ.get("GRAPHKB_URL", "")
if graphkb_url:
logger.info(f"connecting to graphkb: {graphkb_url}")
graphkb_conn = GraphKBConnection(graphkb_url)
else:
graphkb_conn = GraphKBConnection()

gkb_user = graphkb_username if graphkb_username else username
gkb_pass = graphkb_password if graphkb_password else password
# graphkb_conn = GraphKBConnection() # This will just error on trying to login
raise ValueError("graphkb_url is required")

graphkb_conn.login(gkb_user, gkb_pass)

Expand Down Expand Up @@ -495,6 +505,8 @@ def ipr_report(
comments_list.append(graphkb_comments)

if include_ipr_variant_text:
if not ipr_conn:
raise ValueError("ipr_url required to include_ipr_variant_text")
ipr_comments = get_ipr_analyst_comments(
ipr_conn,
gkb_matches,
Expand Down Expand Up @@ -550,18 +562,20 @@ def ipr_report(

# if input includes hrdScore field, that is ok to pass to db
# but prefer the 'hrd' field if it exists
if output.get('hrd'):
if output.get('hrd').get('score'):
output['hrdScore'] = output['hrd']['score']
output.pop('hrd') # kbmatches have already been made
if output.get("hrd"):
if output.get("hrd").get("score"):
output["hrdScore"] = output["hrd"]["score"]
output.pop("hrd") # kbmatches have already been made

ipr_spec = ipr_conn.get_spec()
output = clean_unsupported_content(output, ipr_spec)
ipr_result = {}
upload_error = None

# UPLOAD TO IPR
if ipr_upload:
if not ipr_conn:
raise ValueError("ipr_url required to upload_report")
ipr_spec = ipr_conn.get_spec()
output = clean_unsupported_content(output, ipr_spec)
try:
logger.info(f"Uploading to IPR {ipr_conn.url}")
ipr_result = ipr_conn.upload_report(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graphkb/test_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pori_python.graphkb import GraphKBConnection
from pori_python.graphkb.genes import (
PREFERRED_GENE_SOURCE_NAME,
get_cancer_genes,
get_cancer_predisposition_info,
get_gene_information,
Expand All @@ -18,7 +19,6 @@
get_pharmacogenomic_info,
get_preferred_gene_name,
get_therapeutic_associated_genes,
PREFERRED_GENE_SOURCE_NAME,
)
from pori_python.graphkb.util import get_rid

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ipr/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from pori_python.graphkb.match import INPUT_COPY_CATEGORIES
from pori_python.ipr.constants import (
MSI_MAPPING,
HRD_MAPPING,
MSI_MAPPING,
TMB_SIGNATURE,
TMB_SIGNATURE_HIGH_THRESHOLD,
)
Expand All @@ -21,8 +21,8 @@
preprocess_cosmic,
preprocess_expression_variants,
preprocess_hla,
preprocess_msi,
preprocess_hrd,
preprocess_msi,
preprocess_signature_variants,
preprocess_small_mutations,
preprocess_structural_variants,
Expand Down