1010 get_kb_matched_statements ,
1111 get_kb_statement_matched_conditions ,
1212 get_kb_variants ,
13+ get_kb_matches_sections ,
14+ create_key_alterations ,
1315)
1416from pori_python .types import Statement
1517
@@ -483,9 +485,9 @@ def test_germline_kb_matches(self):
483485 "kbContextId" : "#135:8764" ,
484486 "kbRelevanceId" : "#147:32" ,
485487 "kbStatementId" : "#155:13511" ,
486- "requiredKbMatches" : ["#159:5426 " , "#161:938 " ],
488+ "requiredKbMatches" : ["#159:54261 " , "#161:9381 " ],
487489 "kbVariant" : "BRCA1 mutation" ,
488- "kbVariantId" : "#161:938 " ,
490+ "kbVariantId" : "#161:9381 " ,
489491 "matchedCancer" : False ,
490492 "reference" : "MOAlmanac FDA-56" ,
491493 "relevance" : "therapy" ,
@@ -494,6 +496,13 @@ def test_germline_kb_matches(self):
494496 },
495497]
496498
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+
497506BASIC_GKB_MATCH = {
498507 "approvedTherapy" : False ,
499508 "category" : "test" ,
@@ -696,9 +705,12 @@ def test_partial_matches_omitted(self):
696705 for item in input_fields : # we don't care about these for this test
697706 item ["variantType" ] = "test"
698707 item ["kbVariant" ] = "test"
708+
699709 gkb_matches = create_gkb_matches (input_fields )
700- stmts = get_kb_matched_statements (gkb_matches )
701- kbcs = get_kb_statement_matched_conditions (gkb_matches )
710+ sections = get_kb_matches_sections (gkb_matches , allow_partial_matches = False )
711+
712+ stmts = sections ['kbMatchedStatements' ]
713+ kbcs = sections ['kbStatementMatchedConditions' ]
702714 assert len (stmts ) == 2
703715 assert len (kbcs ) == 1 # X only
704716 assert kbcs [0 ]["kbStatementId" ] == "X"
@@ -748,6 +760,53 @@ def test_partial_matches_omitted_even_when_var_used_elsewhere(self):
748760 assert len (kbcs ) == 2 # X and Z but not Y
749761 assert "Y" not in [item ["kbStatementId" ] for item in kbcs ]
750762
763+ def test_kbvariants_removed_from_set_when_not_part_of_full_conditionset_match (self ):
764+ """When there is a variant that fulfills one part of a statement's condition set,
765+ but isn't part of any fully satisfied condition set,
766+ the kbvariant record should be removed from the kbvariants list
767+ """
768+ input_fields = [
769+ {
770+ "variant" : "A" ,
771+ "kbVariantId" : "test1" ,
772+ "kbStatementId" : "X" ,
773+ "requiredKbMatches" : ["test1" , "test2" , "test3" ],
774+ },
775+ {
776+ "variant" : "B" ,
777+ "kbVariantId" : "test2" ,
778+ "kbStatementId" : "X" ,
779+ "requiredKbMatches" : ["test1" , "test2" , "test3" ],
780+ },
781+ {
782+ "variant" : "A" ,
783+ "kbVariantId" : "test1" ,
784+ "kbStatementId" : "Y" ,
785+ "requiredKbMatches" : ["test4" , "test1" ],
786+ },
787+ {
788+ "variant" : "D" ,
789+ "kbVariantId" : "test4" ,
790+ "kbStatementId" : "Y" ,
791+ "requiredKbMatches" : ["test4" , "test1" ],
792+ },
793+ ]
794+ for item in input_fields : # we don't care about these for this test
795+ item ["variantType" ] = "test"
796+ item ["kbVariant" ] = "test"
797+ gkb_matches = create_gkb_matches (input_fields )
798+ sections1 = get_kb_matches_sections (gkb_matches , allow_partial_matches = False )
799+ kbcs1 = sections1 ['kbStatementMatchedConditions' ]
800+ kbvars1 = sections1 ['kbMatches' ]
801+ assert len (kbcs1 ) == 1 # only fully matched condition sets included
802+ assert len (kbvars1 ) == 2 # therefore, kbvars associated with stmt X are pruned
803+
804+ sections2 = get_kb_matches_sections (gkb_matches , allow_partial_matches = True )
805+ kbcs2 = sections2 ['kbStatementMatchedConditions' ]
806+ kbvars2 = sections2 ['kbMatches' ]
807+ assert len (kbcs2 ) == 2 # all condition sets included
808+ assert len (kbvars2 ) == 3 # therefore, no pruning
809+
751810 def test_partial_matches_included (self ):
752811 """check statements that are only partially supported
753812 are included when allow_partial_matches=True"""
@@ -779,3 +838,21 @@ def test_partial_matches_included(self):
779838 kbcs = get_kb_statement_matched_conditions (gkb_matches , allow_partial_matches = True )
780839 assert len (stmts ) == 2 # X and Y
781840 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