Skip to content
Merged
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
15 changes: 15 additions & 0 deletions pori_python/ipr/ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def convert_statements_to_alterations(
diseases = [c for c in statement["conditions"] if c["@class"] == "Disease"]
disease_match = len(diseases) == 1 and diseases[0]["@rid"] in disease_matches
reference = ";".join([e["displayName"] for e in statement["evidence"]])

if statement['relevance']['name'] == 'eligibility':
reference = ";".join([e["sourceId"] for e in statement["evidence"]])

Expand Down Expand Up @@ -624,6 +625,20 @@ def get_kb_matches_sections(
kb_statement_matched_conditions = get_kb_statement_matched_conditions(
gkb_matches, allow_partial_matches
)

if not allow_partial_matches:
# remove kb_matches that are not part of any fully matched condition set
unique_kb_variant_ids = list(
set(
[
item['kbVariantId']
for conditionSet in kb_statement_matched_conditions
for item in conditionSet['matchedConditions']
]
)
)
kb_variants = [item for item in kb_variants if item['kbVariantId'] in unique_kb_variant_ids]

return {
"kbMatches": kb_variants,
"kbMatchedStatements": kb_matched_statements,
Expand Down
7 changes: 4 additions & 3 deletions pori_python/ipr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,6 @@ def ipr_report(
gkb_matches = [Hashabledict(match) for match in custom_kb_match_filter(gkb_matches)]
logger.info(f"\t custom_kb_match_filter left {len(gkb_matches)} variants")

# KEY ALTERATIONS
key_alterations, variant_counts = create_key_alterations(gkb_matches, all_variants)

# GENE INFORMATION
logger.info("fetching gene annotations")
gene_information = get_gene_information(graphkb_conn, sorted(genes_with_variants))
Expand Down Expand Up @@ -514,6 +511,10 @@ def ipr_report(
gkb_matches, allow_partial_matches=allow_partial_matches
)

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

# OUTPUT CONTENT
# thread safe deep-copy the original content
output = json.loads(json.dumps(content))
Expand Down
1 change: 1 addition & 0 deletions tests/test_ipr/test_data/expression.short.tab
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ KLHL25 27.39 outlier_high increased expression 100.0 6.97 46.01 100.0 210.66 8.
ZNRF3-IT1 0.2 no_category 6.75 0.12 34 -1.816 2.225 -2.505 1.744 26 0.623 -1.272 0.2 0.3 0.4 0.5
PTP4A3 1.33 high_percentile increased expression 100.0 9.74 99.62 100.0 32.2 6.09 -2.217 87 1.863 2.013 0.286 -0.767 66 -0.091 -1.824 0.2 0.3 0.4 0.5
ERBB2 0.05 no_category 67.0 0.62 51.71 100.0 1.01 4.8 -0.551 61 -2.009 -2.216 0.147 -2.385 86 2.299 -0.953 0.2 0.3 0.4 0.5
DPYD 1.12 increased rna expression increased expression 97.0 4.75 73.38 100.0 50.19 0.99 -0.193 92 2.786 0.537 2.113 1.888 31 0.915 0.861 0.2 0.3 0.4 0.5
55 changes: 53 additions & 2 deletions tests/test_ipr/test_ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_kb_matched_statements,
get_kb_statement_matched_conditions,
get_kb_variants,
get_kb_matches_sections,
)
from pori_python.types import Statement

Expand Down Expand Up @@ -696,9 +697,12 @@ def test_partial_matches_omitted(self):
for item in input_fields: # we don't care about these for this test
item["variantType"] = "test"
item["kbVariant"] = "test"

gkb_matches = create_gkb_matches(input_fields)
stmts = get_kb_matched_statements(gkb_matches)
kbcs = get_kb_statement_matched_conditions(gkb_matches)
sections = get_kb_matches_sections(gkb_matches, allow_partial_matches=False)

stmts = sections['kbMatchedStatements']
kbcs = sections['kbStatementMatchedConditions']
assert len(stmts) == 2
assert len(kbcs) == 1 # X only
assert kbcs[0]["kbStatementId"] == "X"
Expand Down Expand Up @@ -748,6 +752,53 @@ def test_partial_matches_omitted_even_when_var_used_elsewhere(self):
assert len(kbcs) == 2 # X and Z but not Y
assert "Y" not in [item["kbStatementId"] for item in kbcs]

def test_kbvariants_removed_from_set_when_not_part_of_full_conditionset_match(self):
"""When there is a variant that fulfills one part of a statement's condition set,
but isn't part of any fully satisfied condition set,
the kbvariant record should be removed from the kbvariants list
"""
input_fields = [
{
"variant": "A",
"kbVariantId": "test1",
"kbStatementId": "X",
"requiredKbMatches": ["test1", "test2", "test3"],
},
{
"variant": "B",
"kbVariantId": "test2",
"kbStatementId": "X",
"requiredKbMatches": ["test1", "test2", "test3"],
},
{
"variant": "A",
"kbVariantId": "test1",
"kbStatementId": "Y",
"requiredKbMatches": ["test4", "test1"],
},
{
"variant": "D",
"kbVariantId": "test4",
"kbStatementId": "Y",
"requiredKbMatches": ["test4", "test1"],
},
]
for item in input_fields: # we don't care about these for this test
item["variantType"] = "test"
item["kbVariant"] = "test"
gkb_matches = create_gkb_matches(input_fields)
sections1 = get_kb_matches_sections(gkb_matches, allow_partial_matches=False)
kbcs1 = sections1['kbStatementMatchedConditions']
kbvars1 = sections1['kbMatches']
assert len(kbcs1) == 1 # only fully matched condition sets included
assert len(kbvars1) == 2 # therefore, kbvars associated with stmt X are pruned

sections2 = get_kb_matches_sections(gkb_matches, allow_partial_matches=True)
kbcs2 = sections2['kbStatementMatchedConditions']
kbvars2 = sections2['kbMatches']
assert len(kbcs2) == 2 # all condition sets included
assert len(kbvars2) == 3 # therefore, no pruning

def test_partial_matches_included(self):
"""check statements that are only partially supported
are included when allow_partial_matches=True"""
Expand Down