Skip to content

Commit abcc23e

Browse files
committed
Merge branch 'feat/DEVSU-2797-remove-gsc-defaults_dustin' of https://github.com/bcgsc/pori_python into improvement/SDEV-5193_mypy_type_fixes
2 parents 4261381 + 686511d commit abcc23e

21 files changed

+295
-51
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: 11 additions & 4 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,
@@ -143,6 +143,8 @@ def request(self, endpoint: str, method: str = "GET", **kwargs) -> Dict:
143143
Returns:
144144
dict: the json response as a python dict
145145
"""
146+
if not self.url:
147+
raise ValueError("no GraphKBConnection url set - cannot make a login demo")
146148
url = join_url(self.url, endpoint)
147149
self.request_count += 1
148150
connect_timeout = 7
@@ -222,6 +224,8 @@ def login_demo(self) -> None:
222224
1. get a first token from KeyCloak using username and password; self.login_demo()
223225
2. get a second token from the GraphKB API using keyCloakToken; self.login()
224226
"""
227+
if not self.url:
228+
raise ValueError("no GraphKBConnection url set - cannot make a login demo")
225229
url_parts = urlsplit(self.url)
226230
base_url = f"{url_parts.scheme}://{url_parts.netloc}"
227231

@@ -250,8 +254,11 @@ def login(self, username: str, password: str, pori_demo: bool = False) -> None:
250254
connect_timeout = 7
251255
read_timeout = 61
252256

253-
# KBDEV-1328. Alt. GraphKB login for GSC's PORI online demo
254-
if pori_demo or "pori-demo" in self.url:
257+
if not self.url:
258+
raise ValueError("no GraphKBConnection url set - cannot login")
259+
elif pori_demo or "pori-demo" in self.url:
260+
# KBDEV-1328. Alt. GraphKB login for GSC's PORI online demo
261+
logger.warning("login demo")
255262
self.login_demo()
256263

257264
# use requests package directly to avoid recursion loop on login failure

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: 13 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

@@ -26,3 +25,16 @@
2625
"variantTypeName": "signature present",
2726
},
2827
}
28+
# Mapping hrd from pipeline terms to GraphKB terms
29+
HRD_MAPPING = {
30+
"homologous recombination deficiency strong signature": {
31+
"displayName": "homologous recombination deficiency strong signature",
32+
"signatureName": "homologous recombination deficiency",
33+
"variantTypeName": "strong signature",
34+
},
35+
"homologous recombination deficiency moderate signature": {
36+
"displayName": "homologous recombination deficiency moderate signature",
37+
"signatureName": "homologous recombination deficiency",
38+
"variantTypeName": "moderate signature",
39+
},
40+
}

pori_python/ipr/content.spec.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,20 @@
541541
},
542542
"type": "array"
543543
},
544+
"hrd": {
545+
"properties": {
546+
"kbCategory": {
547+
"type": "string"
548+
},
549+
"score": {
550+
"type": "number"
551+
}
552+
},
553+
"required": [
554+
"score"
555+
],
556+
"type": "object"
557+
},
544558
"images": {
545559
"items": {
546560
"example": {

pori_python/ipr/inputs.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
from .constants import (
2727
COSMIC_SIGNATURE_VARIANT_TYPE,
28-
DEFAULT_URL,
2928
HLA_SIGNATURE_VARIANT_TYPE,
29+
HRD_MAPPING,
3030
MSI_MAPPING,
3131
TMB_SIGNATURE,
3232
TMB_SIGNATURE_VARIANT_TYPE,
@@ -38,7 +38,7 @@
3838
SPECIFICATION = os.path.join(os.path.dirname(__file__), "content.spec.json")
3939

4040
# content in the local specification should match the values in IPR_API_SPEC_JSON_URL
41-
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'
4242

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

@@ -560,6 +560,23 @@ def preprocess_msi(msi: Any) -> Sequence[Dict]:
560560
return []
561561

562562

563+
def preprocess_hrd(hrd: Any) -> Iterable[Dict]:
564+
"""
565+
Process hrd input into preformatted signature input.
566+
HRD gets mapped to corresponding GraphKB Signature CategoryVariants.
567+
"""
568+
if hrd:
569+
hrd_cat = hrd.get("kbCategory", "")
570+
571+
hrd_variant = HRD_MAPPING.get(hrd_cat, None)
572+
573+
# Signature CategoryVariant created either for msi or mss
574+
if hrd_variant:
575+
return [hrd_variant]
576+
577+
return []
578+
579+
563580
def check_variant_links(
564581
small_mutations: List[IprSmallMutationVariant],
565582
expression_variants: List[IprExprVariant],

0 commit comments

Comments
 (0)