Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
IPR_PASS: ${{ secrets.IPR_TEST_PASSWORD }}
GRAPHKB_USER: ${{ secrets.GKB_TEST_USER }}
GRAPHKB_PASS: ${{ secrets.GKB_TEST_PASS }}
GRAPHKB_URL: ${{ secrets.GKB_TEST_URL }}
# SDEV-3381 - Turn off integration tests temporarily, till efficiency is increased
# turn on integration tests for one python version only
EXCLUDE_INTEGRATION_TESTS: ${{ matrix.python-version != '3.11' }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/quick-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ jobs:
env:
IPR_USER: ${{ secrets.IPR_TEST_USER }}
IPR_PASS: ${{ secrets.IPR_TEST_PASSWORD }}
IPR_URL: ${{ secrets.IPR_TEST_URL }}
GRAPHKB_USER: ${{ secrets.GKB_TEST_USER }}
GRAPHKB_PASS: ${{ secrets.GKB_TEST_PASS }}
GRAPHKB_URL: ${{ secrets.GKB_TEST_URL }}
EXCLUDE_INTEGRATION_TESTS: 1
# EXCLUDE_INTEGRATION_TESTS: ${{ matrix.python-version != '3.11' }}
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request'
1 change: 0 additions & 1 deletion pori_python/graphkb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .constants import DEFAULT_URL # noqa: F401
from .util import GraphKBConnection, logger # noqa: F401
5 changes: 0 additions & 5 deletions pori_python/graphkb/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
from pori_python.types import CategoryBaseTermMapping

DEFAULT_LIMIT = 1000
GKB_BASE_URL = "https://graphkb-api.bcgsc.ca/api"
GKB_STAGING_URL = "https://graphkbstaging-api.bcgsc.ca/api"
GKB_DEV_URL = "https://graphkbdev-api.bcgsc.ca/api"
DEFAULT_URL = GKB_BASE_URL

PREFERRED_GENE_SOURCE = "#39:5" # HGNC
PREFERRED_GENE_SOURCE_NAME = "HGNC"

BASE_RETURN_PROPERTIES = ["@rid", "@class"]
Expand Down
10 changes: 4 additions & 6 deletions pori_python/graphkb/genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
GSC_PHARMACOGENOMIC_SOURCE_EXCLUDE_LIST,
ONCOGENE,
ONCOKB_SOURCE_NAME,
PREFERRED_GENE_SOURCE,
PREFERRED_GENE_SOURCE_NAME,
RELEVANCE_BASE_TERMS,
TSO500_SOURCE_NAME,
Expand Down Expand Up @@ -267,24 +266,23 @@ def get_cancer_predisposition_info(


def get_gene_linked_cancer_predisposition_info(
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE_NAME
) -> Tuple[List[str], Dict[str, Tuple[str, List[str]]]]:
"""
Return two lists from GraphKB, one of cancer predisposition genes and one of associated variants.

GERO-272 - criteria for what counts as a "cancer predisposition" variant

In short:
* Statement 'source' is 'CGL'
* Statement 'source' is 'CGL' (not related to the preferred gene source)
* Statement 'relevance' is 'pathogenic'
* gene is gotten from any associated 'PositionalVariant' records

Example: https://graphkb.bcgsc.ca/view/Statement/155:11616



Returns:
genes: list of cancer predisposition genes
(using names from the source specified in this function's arguments)
variants: dictionary mapping pharmacogenomic variant IDs to variant display names
"""
genes = set()
Expand Down Expand Up @@ -372,7 +370,7 @@ def get_pharmacogenomic_info(


def get_gene_linked_pharmacogenomic_info(
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE_NAME
) -> Tuple[List[str], Dict[str, Tuple[str, List[str]]]]:
"""
Return two lists from GraphKB, one of pharmacogenomic genes and one of associated variants.
Expand Down
4 changes: 2 additions & 2 deletions pori_python/graphkb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pori_python.types import ParsedVariant, PositionalVariant, Record

from .constants import DEFAULT_LIMIT, DEFAULT_URL, TYPES_TO_NOTATION, AA_3to1_MAPPING
from .constants import DEFAULT_LIMIT, TYPES_TO_NOTATION, AA_3to1_MAPPING

QUERY_CACHE: Dict[Any, Any] = {}

Expand Down Expand Up @@ -98,7 +98,7 @@ def cache_key(request_body) -> str:
class GraphKBConnection:
def __init__(
self,
url: str = os.environ.get("GRAPHKB_URL", DEFAULT_URL),
url: str = os.environ.get("GRAPHKB_URL"),
username: str = "",
password: str = "",
use_global_cache: bool = True,
Expand Down
3 changes: 1 addition & 2 deletions pori_python/ipr/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import zlib
from typing import Dict, List

from .constants import DEFAULT_URL
from .util import logger

IMAGE_MAX = 20 # cannot upload more than 20 images at a time
Expand All @@ -17,7 +16,7 @@ def __init__(
self,
username: str,
password: str,
url: str = os.environ.get("IPR_URL", DEFAULT_URL),
url: str = os.environ.get("IPR_URL"),
):
self.token = None
self.url = url
Expand Down
1 change: 0 additions & 1 deletion pori_python/ipr/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DEFAULT_URL = "https://iprstaging-api.bcgsc.ca/api"
GERMLINE_BASE_TERMS = ("pharmacogenomic", "cancer predisposition") # based on graphkb.constants
VARIANT_CLASSES = {"Variant", "CategoryVariant", "PositionalVariant", "CatalogueVariant"}

Expand Down
3 changes: 1 addition & 2 deletions pori_python/ipr/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from .constants import (
COSMIC_SIGNATURE_VARIANT_TYPE,
DEFAULT_URL,
HLA_SIGNATURE_VARIANT_TYPE,
MSI_MAPPING,
HRD_MAPPING,
Expand All @@ -39,7 +38,7 @@
SPECIFICATION = os.path.join(os.path.dirname(__file__), "content.spec.json")

# content in the local specification should match the values in IPR_API_SPEC_JSON_URL
IPR_API_SPEC_JSON_URL = f'{os.environ.get("IPR_URL", DEFAULT_URL)}/spec.json'
IPR_API_SPEC_JSON_URL = f'{os.environ.get("IPR_URL")}/spec.json'

# TODO: GERO-307 - use SPECIFICATION json to derive the variant required and optional details defined below

Expand Down
28 changes: 21 additions & 7 deletions pori_python/ipr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from .annotate import annotate_variants
from .connection import IprConnection
from .constants import DEFAULT_URL, TMB_SIGNATURE_HIGH_THRESHOLD
from .constants import TMB_SIGNATURE_HIGH_THRESHOLD
from .inputs import (
check_comparators,
check_variant_links,
Expand Down Expand Up @@ -86,7 +86,7 @@ def command_interface() -> None:
"-c", "--content", required=True, type=file_path, help="Report Content as JSON"
)

parser.add_argument("--ipr_url", default=os.environ.get("IPR_URL", DEFAULT_URL))
parser.add_argument("--ipr_url", default=os.environ.get("IPR_URL"))
parser.add_argument(
"--graphkb_username",
help="username to use connecting to graphkb if different from ipr",
Expand Down Expand Up @@ -294,7 +294,7 @@ def ipr_report(
username: str,
password: str,
content: Dict,
ipr_url: str = DEFAULT_URL,
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 @@ -492,6 +501,8 @@ def ipr_report(
comments_list.append(graphkb_comments)

if include_ipr_variant_text:
if not ipr_conn:
raise ValueError("ipr_url required to to include ipr variant text")
ipr_comments = get_ipr_analyst_comments(
ipr_conn,
gkb_matches,
Expand Down Expand Up @@ -557,13 +568,16 @@ def ipr_report(
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