Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pori_python/ipr/ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ def select_expression_plots(


def create_key_alterations(
kb_matches: List[Hashabledict], all_variants: Sequence[IprVariant]
kb_matches: List[Hashabledict],
all_variants: Sequence[IprVariant],
included_kb_matches: List[KbVariantMatch],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document what included_kb_matches is used for? I fear we'll forget about it after a while

) -> Tuple[List[Dict], Dict]:
"""Create the list of significant variants matched by the KB.

Expand All @@ -284,7 +286,12 @@ def create_key_alterations(
}
counts: Dict[str, Set] = {v: set() for v in type_mapping.values()}
skipped_variant_types = []

included_kbvariant_ids = list(set([item['kbVariantId'] for item in included_kb_matches]))

for kb_match in kb_matches:
if kb_match['kbVariantId'] not in included_kbvariant_ids:
continue
variant_type = kb_match["variantType"]
variant_key = kb_match["variant"]
if kb_match["category"] == "unknown":
Expand Down
5 changes: 3 additions & 2 deletions pori_python/ipr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,9 @@ def ipr_report(
)

# KEY ALTERATIONS
# must do after pruning of kbMatches for kb_matched_sections
key_alterations, variant_counts = create_key_alterations(gkb_matches, all_variants)
key_alterations, variant_counts = create_key_alterations(
gkb_matches, all_variants, kb_matched_sections['kbMatches']
)

# OUTPUT CONTENT
# thread safe deep-copy the original content
Expand Down
30 changes: 28 additions & 2 deletions tests/test_ipr/test_ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get_kb_statement_matched_conditions,
get_kb_variants,
get_kb_matches_sections,
create_key_alterations,
)
from pori_python.types import Statement

Expand Down Expand Up @@ -484,9 +485,9 @@ def test_germline_kb_matches(self):
"kbContextId": "#135:8764",
"kbRelevanceId": "#147:32",
"kbStatementId": "#155:13511",
"requiredKbMatches": ["#159:5426", "#161:938"],
"requiredKbMatches": ["#159:54261", "#161:9381"],
"kbVariant": "BRCA1 mutation",
"kbVariantId": "#161:938",
"kbVariantId": "#161:9381",
"matchedCancer": False,
"reference": "MOAlmanac FDA-56",
"relevance": "therapy",
Expand All @@ -495,6 +496,13 @@ def test_germline_kb_matches(self):
},
]

ALL_VARIANTS = [
{"variant": "var1", "key": '1', "variantType": 'mut'},
{"variant": "var2", "key": '2', "variantType": 'mut'},
{"variant": "var3", "key": '3', "variantType": 'mut'},
{"variant": "var4", "key": '4', "variantType": 'mut'},
]

BASIC_GKB_MATCH = {
"approvedTherapy": False,
"category": "test",
Expand Down Expand Up @@ -830,3 +838,21 @@ def test_partial_matches_included(self):
kbcs = get_kb_statement_matched_conditions(gkb_matches, allow_partial_matches=True)
assert len(stmts) == 2 # X and Y
assert len(kbcs) == 2

def test_create_key_alterations_includes_only_pruned_kbmatches(self):
gkb_matches = create_gkb_matches(GKB_MATCHES)

sections1 = get_kb_matches_sections(gkb_matches, allow_partial_matches=False)
key_alts1, counts1 = create_key_alterations(
gkb_matches, ALL_VARIANTS, sections1['kbMatches']
)

sections2 = get_kb_matches_sections(gkb_matches, allow_partial_matches=True)
key_alts2, counts2 = create_key_alterations(
gkb_matches, ALL_VARIANTS, sections2['kbMatches']
)

# check partial-match-only variants are not included in key alterations when
# partial matches is false
assert len(key_alts1) == 3
assert len(key_alts2) == 4