Skip to content

Commit d599b95

Browse files
authored
Merge pull request #87 from bcgsc/feat/DEVSU-2769-load-hrd-score
Feat/devsu 2769 load hrd score
2 parents 4ad7fb9 + 37cae0a commit d599b95

File tree

7 files changed

+95
-1
lines changed

7 files changed

+95
-1
lines changed

pori_python/ipr/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@
2626
"variantTypeName": "signature present",
2727
},
2828
}
29+
# Mapping hrd from pipeline terms to GraphKB terms
30+
HRD_MAPPING = {
31+
"homologous recombination deficiency strong signature": {
32+
"displayName": "homologous recombination deficiency strong signature",
33+
"signatureName": "homologous recombination deficiency",
34+
"variantTypeName": "strong signature",
35+
},
36+
"homologous recombination deficiency moderate signature": {
37+
"displayName": "homologous recombination deficiency moderate signature",
38+
"signatureName": "homologous recombination deficiency",
39+
"variantTypeName": "moderate signature",
40+
},
41+
}

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DEFAULT_URL,
2929
HLA_SIGNATURE_VARIANT_TYPE,
3030
MSI_MAPPING,
31+
HRD_MAPPING,
3132
TMB_SIGNATURE,
3233
TMB_SIGNATURE_VARIANT_TYPE,
3334
)
@@ -557,6 +558,23 @@ def preprocess_msi(msi: Any) -> Iterable[Dict]:
557558
return []
558559

559560

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

pori_python/ipr/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
preprocess_expression_variants,
3333
preprocess_hla,
3434
preprocess_msi,
35+
preprocess_hrd,
3536
preprocess_signature_variants,
3637
preprocess_small_mutations,
3738
preprocess_structural_variants,
@@ -387,6 +388,7 @@ def ipr_report(
387388
content.get("genomeTmb", ""), # newer tmb pipeline
388389
),
389390
*preprocess_msi(content.get("msi", None)),
391+
*preprocess_hrd(content.get("hrd", None)),
390392
]
391393
)
392394
small_mutations: List[IprSmallMutationVariant] = preprocess_small_mutations(
@@ -515,7 +517,6 @@ def ipr_report(
515517
# OUTPUT CONTENT
516518
# thread safe deep-copy the original content
517519
output = json.loads(json.dumps(content))
518-
519520
output.update(kb_matched_sections)
520521
output.update(
521522
{
@@ -547,6 +548,13 @@ def ipr_report(
547548
)
548549
output.setdefault("images", []).extend(select_expression_plots(gkb_matches, all_variants))
549550

551+
# if input includes hrdScore field, that is ok to pass to db
552+
# but prefer the 'hrd' field if it exists
553+
if output.get('hrd'):
554+
if output.get('hrd').get('score'):
555+
output['hrdScore'] = output['hrd']['score']
556+
output.pop('hrd') # kbmatches have already been made
557+
550558
ipr_spec = ipr_conn.get_spec()
551559
output = clean_unsupported_content(output, ipr_spec)
552560
ipr_result = {}

tests/test_ipr/test_inputs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pori_python.graphkb.match import INPUT_COPY_CATEGORIES
99
from pori_python.ipr.constants import (
1010
MSI_MAPPING,
11+
HRD_MAPPING,
1112
TMB_SIGNATURE,
1213
TMB_SIGNATURE_HIGH_THRESHOLD,
1314
)
@@ -21,6 +22,7 @@
2122
preprocess_expression_variants,
2223
preprocess_hla,
2324
preprocess_msi,
25+
preprocess_hrd,
2426
preprocess_signature_variants,
2527
preprocess_small_mutations,
2628
preprocess_structural_variants,
@@ -49,6 +51,9 @@
4951
}
5052
EXPECTED_TMB = {TMB_SIGNATURE}
5153
EXPECTED_MSI = {MSI_MAPPING.get("microsatellite instability")["signatureName"]}
54+
EXPECTED_HRD = {
55+
HRD_MAPPING.get("homologous recombination deficiency strong signature")["signatureName"]
56+
}
5257

5358

5459
def read_data_file(filename):
@@ -234,6 +239,13 @@ class TestPreProcessSignatureVariants:
234239
}
235240
]
236241
)
242+
hrd = preprocess_hrd(
243+
{
244+
"score": 9999,
245+
"kbCategory": "homologous recombination deficiency strong signature",
246+
"key": "homologous recombination deficiency strong signature",
247+
}
248+
)
237249

238250
# tests on preprocessed records
239251
def test_preprocess_cosmic(self) -> None:
@@ -272,6 +284,15 @@ def test_preprocess_msi(self) -> None:
272284
signatureNames = {r.get("signatureName", "") for r in self.msi}
273285
assert len(EXPECTED_MSI.symmetric_difference(signatureNames)) == 0
274286

287+
def test_preprocess_hrd(self) -> None:
288+
assert self.hrd
289+
assert len(self.hrd) == len(EXPECTED_HRD)
290+
assert "variantTypeName" in self.hrd[0]
291+
assert "displayName" in self.hrd[0]
292+
293+
signatureNames = {r.get("signatureName", "") for r in self.hrd}
294+
assert len(EXPECTED_HRD.symmetric_difference(signatureNames)) == 0
295+
275296
def test_preprocess_signature_variants(self) -> None:
276297
records = preprocess_signature_variants(
277298
[

tests/test_ipr/test_main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def report_upload_content(tmp_path_factory) -> Dict:
6666
pd.read_csv(get_test_file("fusions.tab"), sep="\t").to_json(orient="records")
6767
),
6868
"kbDiseaseMatch": "colorectal cancer",
69+
"msi": [
70+
{
71+
"score": 1000.0,
72+
"kbCategory": "microsatellite instability",
73+
}
74+
],
75+
"hrd": {
76+
"score": 9999.0,
77+
"kbCategory": "homologous recombination deficiency strong signature",
78+
},
6979
},
7080
allow_nan=False,
7181
)

tests/test_ipr/test_upload.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def loaded_reports(tmp_path_factory) -> Generator:
6666
"collectionDate": "12-12-12",
6767
},
6868
],
69+
"msi": [
70+
{
71+
"score": 1000.0,
72+
"kbCategory": "microsatellite instability",
73+
}
74+
],
75+
"hrd": {
76+
"score": 9999.0,
77+
"kbCategory": "homologous recombination deficiency strong signature",
78+
},
6979
"expressionVariants": json.loads(
7080
pd.read_csv(get_test_file("expression.short.tab"), sep="\t").to_json(orient="records")
7181
),

0 commit comments

Comments
 (0)