Skip to content

Commit dbadfb2

Browse files
committed
fix new func
1 parent 7c48cb8 commit dbadfb2

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

pori_python/ipr/ipr.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def germline_kb_matches(
395395
def multi_variant_filtering(
396396
graphkb_conn: GraphKBConnection,
397397
gkb_matches: List[KbMatch],
398-
excludedTypes: List[str] = ['wildtype'],
398+
excludedTypes: List[str] = ["wildtype"],
399399
) -> List[KbMatch]:
400400
"""Filters out GraphKB matches that doesn't match to all required variants on multi-variant statements
401401
@@ -415,8 +415,10 @@ def multi_variant_filtering(
415415
filtered list of KbMatch statements
416416
"""
417417
# All matching statements & variants (GKB RIDs)
418-
matching_statement_rids = {match['kbStatementId'] for match in gkb_matches}
419-
matching_variant_rids = {match['kbVariantId'] for match in gkb_matches}
418+
matching_statement_rids = {
419+
stmt["kbStatementId"] for match in gkb_matches for stmt in match["kbMatchedStatements"]
420+
}
421+
matching_variant_rids = {match["kbVariantId"] for match in gkb_matches}
420422

421423
# Get conditions detail on all matching statements
422424
res = graphkb_conn.post(
@@ -425,7 +427,7 @@ def multi_variant_filtering(
425427
"target": "Statement",
426428
"filters": {
427429
"@rid": list(matching_statement_rids),
428-
"operator": 'IN',
430+
"operator": "IN",
429431
},
430432
"history": True,
431433
"returnProperties": [
@@ -436,21 +438,21 @@ def multi_variant_filtering(
436438
],
437439
},
438440
)
439-
statements = res['result']
441+
statements = res["result"]
440442

441443
# Get set of excluded Vocabulary RIDs for variant types
442444
excluded = {}
443-
if len(excludedTypes) != 0 and excludedTypes[0] != '':
445+
if len(excludedTypes) != 0 and excludedTypes[0] != "":
444446
excluded = gkb_vocab.get_terms_set(graphkb_conn, excludedTypes)
445447

446448
# Mapping statements to their conditional variants
447449
# (discarding non-variant conditions & variant conditions from excluded types)
448450
statement_to_variants = {}
449451
for statement in statements:
450-
statement_to_variants[statement['@rid']] = {
451-
el['@rid']
452-
for el in statement['conditions']
453-
if (el['@class'] in VARIANT_CLASSES and el.get('type', '') not in excluded)
452+
statement_to_variants[statement["@rid"]] = {
453+
el["@rid"]
454+
for el in statement["conditions"]
455+
if (el["@class"] in VARIANT_CLASSES and el.get("type", "") not in excluded)
454456
}
455457

456458
# Set of statements with complete matching
@@ -461,6 +463,13 @@ def multi_variant_filtering(
461463
}
462464

463465
# Filtering out incompleted matches of gkb_matches
464-
return [
465-
match for match in gkb_matches if match['kbStatementId'] in complete_matching_statements
466-
]
466+
output = []
467+
for match in gkb_matches:
468+
match["kbMatchedStatements"] = [
469+
stmt
470+
for stmt in match["kbMatchedStatements"]
471+
if stmt["kbStatementId"] in complete_matching_statements
472+
]
473+
# nb this can result in statement-less matches getting loaded to ipr
474+
output.append(match)
475+
return output

0 commit comments

Comments
 (0)