@@ -395,7 +395,7 @@ def germline_kb_matches(
395
395
def multi_variant_filtering (
396
396
graphkb_conn : GraphKBConnection ,
397
397
gkb_matches : List [KbMatch ],
398
- excludedTypes : List [str ] = [' wildtype' ],
398
+ excludedTypes : List [str ] = [" wildtype" ],
399
399
) -> List [KbMatch ]:
400
400
"""Filters out GraphKB matches that doesn't match to all required variants on multi-variant statements
401
401
@@ -415,8 +415,10 @@ def multi_variant_filtering(
415
415
filtered list of KbMatch statements
416
416
"""
417
417
# 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 }
420
422
421
423
# Get conditions detail on all matching statements
422
424
res = graphkb_conn .post (
@@ -425,7 +427,7 @@ def multi_variant_filtering(
425
427
"target" : "Statement" ,
426
428
"filters" : {
427
429
"@rid" : list (matching_statement_rids ),
428
- "operator" : 'IN' ,
430
+ "operator" : "IN" ,
429
431
},
430
432
"history" : True ,
431
433
"returnProperties" : [
@@ -436,21 +438,21 @@ def multi_variant_filtering(
436
438
],
437
439
},
438
440
)
439
- statements = res [' result' ]
441
+ statements = res [" result" ]
440
442
441
443
# Get set of excluded Vocabulary RIDs for variant types
442
444
excluded = {}
443
- if len (excludedTypes ) != 0 and excludedTypes [0 ] != '' :
445
+ if len (excludedTypes ) != 0 and excludedTypes [0 ] != "" :
444
446
excluded = gkb_vocab .get_terms_set (graphkb_conn , excludedTypes )
445
447
446
448
# Mapping statements to their conditional variants
447
449
# (discarding non-variant conditions & variant conditions from excluded types)
448
450
statement_to_variants = {}
449
451
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 )
454
456
}
455
457
456
458
# Set of statements with complete matching
@@ -461,6 +463,13 @@ def multi_variant_filtering(
461
463
}
462
464
463
465
# 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