diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 607c0c6e..866a822f 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -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' }} diff --git a/.github/workflows/quick-pytest.yml b/.github/workflows/quick-pytest.yml index d4f70223..9c5318ac 100644 --- a/.github/workflows/quick-pytest.yml +++ b/.github/workflows/quick-pytest.yml @@ -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' \ No newline at end of file + if: github.event_name != 'pull_request' diff --git a/pori_python/graphkb/__init__.py b/pori_python/graphkb/__init__.py index a6fdd663..acce57aa 100644 --- a/pori_python/graphkb/__init__.py +++ b/pori_python/graphkb/__init__.py @@ -1,2 +1 @@ -from .constants import DEFAULT_URL # noqa: F401 from .util import GraphKBConnection, logger # noqa: F401 diff --git a/pori_python/graphkb/constants.py b/pori_python/graphkb/constants.py index 4861d70c..b068fdfc 100644 --- a/pori_python/graphkb/constants.py +++ b/pori_python/graphkb/constants.py @@ -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"] diff --git a/pori_python/graphkb/genes.py b/pori_python/graphkb/genes.py index e61e3cf5..3d3111ec 100644 --- a/pori_python/graphkb/genes.py +++ b/pori_python/graphkb/genes.py @@ -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, @@ -267,7 +266,7 @@ 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. @@ -275,16 +274,15 @@ def get_gene_linked_cancer_predisposition_info( 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() @@ -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. diff --git a/pori_python/graphkb/util.py b/pori_python/graphkb/util.py index 2ff8620c..bbc67766 100644 --- a/pori_python/graphkb/util.py +++ b/pori_python/graphkb/util.py @@ -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] = {} @@ -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, diff --git a/pori_python/ipr/connection.py b/pori_python/ipr/connection.py index f2652fdd..dca4687d 100644 --- a/pori_python/ipr/connection.py +++ b/pori_python/ipr/connection.py @@ -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 @@ -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 diff --git a/pori_python/ipr/constants.py b/pori_python/ipr/constants.py index 2ed2a3f2..dd8718aa 100644 --- a/pori_python/ipr/constants.py +++ b/pori_python/ipr/constants.py @@ -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"} diff --git a/pori_python/ipr/inputs.py b/pori_python/ipr/inputs.py index 1089539f..3cfe526c 100644 --- a/pori_python/ipr/inputs.py +++ b/pori_python/ipr/inputs.py @@ -25,7 +25,6 @@ from .constants import ( COSMIC_SIGNATURE_VARIANT_TYPE, - DEFAULT_URL, HLA_SIGNATURE_VARIANT_TYPE, MSI_MAPPING, HRD_MAPPING, @@ -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 diff --git a/pori_python/ipr/main.py b/pori_python/ipr/main.py index 76fd768b..3194779a 100644 --- a/pori_python/ipr/main.py +++ b/pori_python/ipr/main.py @@ -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, @@ -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", @@ -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, @@ -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. @@ -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 ) @@ -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, @@ -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(