Skip to content

Commit ddb48c4

Browse files
authored
Merge pull request #92 from bcgsc/bugfix/DEVSU-2793-prune-nostmt-matches-from-keyalts
exclude partial-only matched kbvars from key alts
2 parents 88d1133 + 99937a6 commit ddb48c4

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

pori_python/ipr/ipr.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,22 @@ def select_expression_plots(
269269

270270

271271
def create_key_alterations(
272-
kb_matches: List[Hashabledict], all_variants: Sequence[IprVariant]
272+
kb_matches: List[Hashabledict],
273+
all_variants: Sequence[IprVariant],
274+
included_kb_matches: List[KbVariantMatch],
273275
) -> Tuple[List[Dict], Dict]:
274276
"""Create the list of significant variants matched by the KB.
275277
276278
This list of matches is also used to create the variant counts.
279+
280+
kb_matches: the full list of matched kb objects found for the reported variants
281+
all_variants: the full list of all reported variants, matched or unmatched
282+
included_kb_matches: the list of kb_variant ids to be allowed in the key alterations table;
283+
this is all kb_variants if partially matched statements are allowed, or
284+
the subset of kb_variants that are conditions for at least one
285+
fully satisfied statement condition set, if partially matched statements
286+
are not allowed (ie, kb_variants that are not part of any fully satisfied
287+
statement condition set are excluded)
277288
"""
278289
alterations = []
279290
type_mapping = {
@@ -284,7 +295,12 @@ def create_key_alterations(
284295
}
285296
counts: Dict[str, Set] = {v: set() for v in type_mapping.values()}
286297
skipped_variant_types = []
298+
299+
included_kbvariant_ids = list(set([item['kbVariantId'] for item in included_kb_matches]))
300+
287301
for kb_match in kb_matches:
302+
if kb_match['kbVariantId'] not in included_kbvariant_ids:
303+
continue
288304
variant_type = kb_match["variantType"]
289305
variant_key = kb_match["variant"]
290306
if kb_match["category"] == "unknown":

pori_python/ipr/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,9 @@ def ipr_report(
512512
)
513513

514514
# KEY ALTERATIONS
515-
# must do after pruning of kbMatches for kb_matched_sections
516-
key_alterations, variant_counts = create_key_alterations(gkb_matches, all_variants)
515+
key_alterations, variant_counts = create_key_alterations(
516+
gkb_matches, all_variants, kb_matched_sections['kbMatches']
517+
)
517518

518519
# OUTPUT CONTENT
519520
# thread safe deep-copy the original content

tests/test_ipr/test_ipr.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_kb_statement_matched_conditions,
1212
get_kb_variants,
1313
get_kb_matches_sections,
14+
create_key_alterations,
1415
)
1516
from pori_python.types import Statement
1617

@@ -484,9 +485,9 @@ def test_germline_kb_matches(self):
484485
"kbContextId": "#135:8764",
485486
"kbRelevanceId": "#147:32",
486487
"kbStatementId": "#155:13511",
487-
"requiredKbMatches": ["#159:5426", "#161:938"],
488+
"requiredKbMatches": ["#159:54261", "#161:9381"],
488489
"kbVariant": "BRCA1 mutation",
489-
"kbVariantId": "#161:938",
490+
"kbVariantId": "#161:9381",
490491
"matchedCancer": False,
491492
"reference": "MOAlmanac FDA-56",
492493
"relevance": "therapy",
@@ -495,6 +496,13 @@ def test_germline_kb_matches(self):
495496
},
496497
]
497498

499+
ALL_VARIANTS = [
500+
{"variant": "var1", "key": '1', "variantType": 'mut'},
501+
{"variant": "var2", "key": '2', "variantType": 'mut'},
502+
{"variant": "var3", "key": '3', "variantType": 'mut'},
503+
{"variant": "var4", "key": '4', "variantType": 'mut'},
504+
]
505+
498506
BASIC_GKB_MATCH = {
499507
"approvedTherapy": False,
500508
"category": "test",
@@ -830,3 +838,21 @@ def test_partial_matches_included(self):
830838
kbcs = get_kb_statement_matched_conditions(gkb_matches, allow_partial_matches=True)
831839
assert len(stmts) == 2 # X and Y
832840
assert len(kbcs) == 2
841+
842+
def test_create_key_alterations_includes_only_pruned_kbmatches(self):
843+
gkb_matches = create_gkb_matches(GKB_MATCHES)
844+
845+
sections1 = get_kb_matches_sections(gkb_matches, allow_partial_matches=False)
846+
key_alts1, counts1 = create_key_alterations(
847+
gkb_matches, ALL_VARIANTS, sections1['kbMatches']
848+
)
849+
850+
sections2 = get_kb_matches_sections(gkb_matches, allow_partial_matches=True)
851+
key_alts2, counts2 = create_key_alterations(
852+
gkb_matches, ALL_VARIANTS, sections2['kbMatches']
853+
)
854+
855+
# check partial-match-only variants are not included in key alterations when
856+
# partial matches is false
857+
assert len(key_alts1) == 3
858+
assert len(key_alts2) == 4

0 commit comments

Comments
 (0)