Skip to content

Commit 1219643

Browse files
authored
Merge pull request #89 from bcgsc/feat/DEVSU-2797-remove-gsc-defaults
remove default urls and rid
2 parents ddb48c4 + e290da6 commit 1219643

File tree

10 files changed

+33
-27
lines changed

10 files changed

+33
-27
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
IPR_PASS: ${{ secrets.IPR_TEST_PASSWORD }}
4747
GRAPHKB_USER: ${{ secrets.GKB_TEST_USER }}
4848
GRAPHKB_PASS: ${{ secrets.GKB_TEST_PASS }}
49+
GRAPHKB_URL: ${{ secrets.GKB_TEST_URL }}
4950
# SDEV-3381 - Turn off integration tests temporarily, till efficiency is increased
5051
# turn on integration tests for one python version only
5152
EXCLUDE_INTEGRATION_TESTS: ${{ matrix.python-version != '3.11' }}

.github/workflows/quick-pytest.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ jobs:
3939
env:
4040
IPR_USER: ${{ secrets.IPR_TEST_USER }}
4141
IPR_PASS: ${{ secrets.IPR_TEST_PASSWORD }}
42+
IPR_URL: ${{ secrets.IPR_TEST_URL }}
4243
GRAPHKB_USER: ${{ secrets.GKB_TEST_USER }}
4344
GRAPHKB_PASS: ${{ secrets.GKB_TEST_PASS }}
45+
GRAPHKB_URL: ${{ secrets.GKB_TEST_URL }}
4446
EXCLUDE_INTEGRATION_TESTS: 1
4547
# EXCLUDE_INTEGRATION_TESTS: ${{ matrix.python-version != '3.11' }}
46-
if: github.event_name != 'pull_request'
48+
if: github.event_name != 'pull_request'

pori_python/graphkb/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from .constants import DEFAULT_URL # noqa: F401
21
from .util import GraphKBConnection, logger # noqa: F401

pori_python/graphkb/constants.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
from pori_python.types import CategoryBaseTermMapping
55

66
DEFAULT_LIMIT = 1000
7-
GKB_BASE_URL = "https://graphkb-api.bcgsc.ca/api"
8-
GKB_STAGING_URL = "https://graphkbstaging-api.bcgsc.ca/api"
9-
GKB_DEV_URL = "https://graphkbdev-api.bcgsc.ca/api"
10-
DEFAULT_URL = GKB_BASE_URL
117

12-
PREFERRED_GENE_SOURCE = "#39:5" # HGNC
138
PREFERRED_GENE_SOURCE_NAME = "HGNC"
149

1510
BASE_RETURN_PROPERTIES = ["@rid", "@class"]

pori_python/graphkb/genes.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
GSC_PHARMACOGENOMIC_SOURCE_EXCLUDE_LIST,
1818
ONCOGENE,
1919
ONCOKB_SOURCE_NAME,
20-
PREFERRED_GENE_SOURCE,
2120
PREFERRED_GENE_SOURCE_NAME,
2221
RELEVANCE_BASE_TERMS,
2322
TSO500_SOURCE_NAME,
@@ -267,24 +266,23 @@ def get_cancer_predisposition_info(
267266

268267

269268
def get_gene_linked_cancer_predisposition_info(
270-
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE
269+
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE_NAME
271270
) -> Tuple[List[str], Dict[str, Tuple[str, List[str]]]]:
272271
"""
273272
Return two lists from GraphKB, one of cancer predisposition genes and one of associated variants.
274273
275274
GERO-272 - criteria for what counts as a "cancer predisposition" variant
276275
277276
In short:
278-
* Statement 'source' is 'CGL'
277+
* Statement 'source' is 'CGL' (not related to the preferred gene source)
279278
* Statement 'relevance' is 'pathogenic'
280279
* gene is gotten from any associated 'PositionalVariant' records
281280
282281
Example: https://graphkb.bcgsc.ca/view/Statement/155:11616
283282
284-
285-
286283
Returns:
287284
genes: list of cancer predisposition genes
285+
(using names from the source specified in this function's arguments)
288286
variants: dictionary mapping pharmacogenomic variant IDs to variant display names
289287
"""
290288
genes = set()
@@ -372,7 +370,7 @@ def get_pharmacogenomic_info(
372370

373371

374372
def get_gene_linked_pharmacogenomic_info(
375-
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE
373+
conn: GraphKBConnection, source: str = PREFERRED_GENE_SOURCE_NAME
376374
) -> Tuple[List[str], Dict[str, Tuple[str, List[str]]]]:
377375
"""
378376
Return two lists from GraphKB, one of pharmacogenomic genes and one of associated variants.

pori_python/graphkb/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from pori_python.types import ParsedVariant, PositionalVariant, Record
1616

17-
from .constants import DEFAULT_LIMIT, DEFAULT_URL, TYPES_TO_NOTATION, AA_3to1_MAPPING
17+
from .constants import DEFAULT_LIMIT, TYPES_TO_NOTATION, AA_3to1_MAPPING
1818

1919
QUERY_CACHE: Dict[Any, Any] = {}
2020

@@ -98,7 +98,7 @@ def cache_key(request_body) -> str:
9898
class GraphKBConnection:
9999
def __init__(
100100
self,
101-
url: str = os.environ.get("GRAPHKB_URL", DEFAULT_URL),
101+
url: str = os.environ.get("GRAPHKB_URL"),
102102
username: str = "",
103103
password: str = "",
104104
use_global_cache: bool = True,

pori_python/ipr/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import zlib
77
from typing import Dict, List
88

9-
from .constants import DEFAULT_URL
109
from .util import logger
1110

1211
IMAGE_MAX = 20 # cannot upload more than 20 images at a time
@@ -17,7 +16,7 @@ def __init__(
1716
self,
1817
username: str,
1918
password: str,
20-
url: str = os.environ.get("IPR_URL", DEFAULT_URL),
19+
url: str = os.environ.get("IPR_URL"),
2120
):
2221
self.token = None
2322
self.url = url

pori_python/ipr/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
DEFAULT_URL = "https://iprstaging-api.bcgsc.ca/api"
21
GERMLINE_BASE_TERMS = ("pharmacogenomic", "cancer predisposition") # based on graphkb.constants
32
VARIANT_CLASSES = {"Variant", "CategoryVariant", "PositionalVariant", "CatalogueVariant"}
43

pori_python/ipr/inputs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
from .constants import (
2727
COSMIC_SIGNATURE_VARIANT_TYPE,
28-
DEFAULT_URL,
2928
HLA_SIGNATURE_VARIANT_TYPE,
3029
MSI_MAPPING,
3130
HRD_MAPPING,
@@ -39,7 +38,7 @@
3938
SPECIFICATION = os.path.join(os.path.dirname(__file__), "content.spec.json")
4039

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

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

pori_python/ipr/main.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from .annotate import annotate_variants
2525
from .connection import IprConnection
26-
from .constants import DEFAULT_URL, TMB_SIGNATURE_HIGH_THRESHOLD
26+
from .constants import TMB_SIGNATURE_HIGH_THRESHOLD
2727
from .inputs import (
2828
check_comparators,
2929
check_variant_links,
@@ -86,7 +86,7 @@ def command_interface() -> None:
8686
"-c", "--content", required=True, type=file_path, help="Report Content as JSON"
8787
)
8888

89-
parser.add_argument("--ipr_url", default=os.environ.get("IPR_URL", DEFAULT_URL))
89+
parser.add_argument("--ipr_url", default=os.environ.get("IPR_URL"))
9090
parser.add_argument(
9191
"--graphkb_username",
9292
help="username to use connecting to graphkb if different from ipr",
@@ -294,7 +294,7 @@ def ipr_report(
294294
username: str,
295295
password: str,
296296
content: Dict,
297-
ipr_url: str = DEFAULT_URL,
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,13 +358,22 @@ def ipr_report(
358358
)
359359

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

363368
if validate_json:
369+
if not ipr_conn:
370+
raise ValueError("ipr_url required to validate json")
364371
ipr_result = ipr_conn.validate_json(content)
365372
return ipr_result
366373

367374
if upload_json:
375+
if not ipr_conn:
376+
raise ValueError("ipr_url required to upload json")
368377
ipr_result = ipr_conn.upload_report(
369378
content, mins_to_wait, async_upload, ignore_extra_fields
370379
)
@@ -492,6 +501,8 @@ def ipr_report(
492501
comments_list.append(graphkb_comments)
493502

494503
if include_ipr_variant_text:
504+
if not ipr_conn:
505+
raise ValueError("ipr_url required to to include ipr variant text")
495506
ipr_comments = get_ipr_analyst_comments(
496507
ipr_conn,
497508
gkb_matches,
@@ -557,13 +568,16 @@ def ipr_report(
557568
output['hrdScore'] = output['hrd']['score']
558569
output.pop('hrd') # kbmatches have already been made
559570

560-
ipr_spec = ipr_conn.get_spec()
561-
output = clean_unsupported_content(output, ipr_spec)
562571
ipr_result = {}
563572
upload_error = None
564573

565574
# UPLOAD TO IPR
575+
566576
if ipr_upload:
577+
if not ipr_conn:
578+
raise ValueError("ipr_url required to upload report")
579+
ipr_spec = ipr_conn.get_spec()
580+
output = clean_unsupported_content(output, ipr_spec)
567581
try:
568582
logger.info(f"Uploading to IPR {ipr_conn.url}")
569583
ipr_result = ipr_conn.upload_report(

0 commit comments

Comments
 (0)