Skip to content

Commit 2832eb5

Browse files
DEVSU-2477 Add support for excludedTypes in test_multi_variant_filtering()
1 parent eac4171 commit 2832eb5

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

pori_python/ipr/ipr.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ def germline_kb_matches(
393393
def multi_variant_filtering(
394394
graphkb_conn: GraphKBConnection,
395395
gkb_matches: List[KbMatch],
396+
excludedTypes: List[str] = ['wildtype'],
396397
) -> List[KbMatch]:
397398
"""Filters out GraphKB matches that doesn't match to all required variants on multi-variant statements
398399
@@ -402,9 +403,12 @@ def multi_variant_filtering(
402403
variants is matching the observed ones, making de facto an 'OR' operator between conditions. The current
403404
function is filtering out these incomplete matches.
404405
406+
Note: Wildtype variants are not taken into account at the moment.
407+
405408
Params:
406409
graphkb_conn: the graphkb connection object
407410
gkb_matches: KbMatch statements to be filtered
411+
excludedTypes: List of variant type terms to exclude from filtering. Default to Wildtype
408412
Returns:
409413
filtered list of KbMatch statements
410414
"""
@@ -426,17 +430,25 @@ def multi_variant_filtering(
426430
"@rid",
427431
"conditions.@rid",
428432
"conditions.@class",
433+
"conditions.type",
429434
],
430435
},
431436
)
432437
statements = res['result']
433438

439+
# Get set of excluded Vocabulary RIDs for variant types
440+
excluded = {}
441+
if len(excludedTypes) != 0 and excludedTypes[0] != '':
442+
excluded = gkb_vocab.get_terms_set(graphkb_conn, excludedTypes)
443+
434444
# Mapping statements to their conditional variants
435-
# (discarding non-variant conditions)
445+
# (discarding non-variant conditions & variant conditions from excluded types)
436446
statement_to_variants = {}
437447
for statement in statements:
438448
statement_to_variants[statement['@rid']] = {
439-
el['@rid'] for el in statement['conditions'] if el['@class'] in VARIANT_CLASSES
449+
el['@rid']
450+
for el in statement['conditions']
451+
if (el['@class'] in VARIANT_CLASSES and el.get('type', '') not in excluded)
440452
}
441453

442454
# Set of statements with complete matching

tests/test_ipr/test_ipr.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@
152152
'conditions': [
153153
{'@class': 'PositionalVariant', '@rid': SOMATIC_KB_MATCHES[0]['kbVariantId']},
154154
{'@class': 'CategoryVariant', '@rid': SOMATIC_KB_MATCHES[1]['kbVariantId']},
155-
{'@class': 'Disease', '@rid': ''}, # non-variant condition
155+
{'@class': 'Disease', '@rid': ''},
156156
],
157157
},
158158
{
159159
'@rid': SOMATIC_KB_MATCHES[1]['kbStatementId'],
160160
'conditions': [
161161
{'@class': 'CategoryVariant', '@rid': SOMATIC_KB_MATCHES[1]['kbVariantId']},
162-
{'@class': 'PositionalVariant', '@rid': '157:0'}, # Unmatched variant
162+
{'@class': 'PositionalVariant', '@rid': '157:0', 'type': '#999:99'},
163163
],
164164
},
165165
]
@@ -230,6 +230,14 @@ def mock_func(*pos, **kwargs):
230230
monkeypatch.setattr(gkb_vocab, "get_term_tree", mock_func)
231231

232232

233+
@pytest.fixture(autouse=True)
234+
def get_terms_set(monkeypatch):
235+
def mock_func(*pos, **kwargs):
236+
return {'#999:99'}
237+
238+
monkeypatch.setattr(gkb_vocab, "get_terms_set", mock_func)
239+
240+
233241
@pytest.fixture(autouse=True)
234242
def mock_categorize_relevance(monkeypatch):
235243
def mock_func(_, relevance_id):
@@ -365,6 +373,9 @@ def test_germline_kb_matches(self):
365373
), "Germline variant matched to KB somatic statement."
366374

367375
def test_multi_variant_filtering(self, graphkb_conn):
368-
gkb_matches = multi_variant_filtering(graphkb_conn, SOMATIC_KB_MATCHES)
369-
assert len(SOMATIC_KB_MATCHES) == 2, 'Matches before filtering'
370-
assert len(gkb_matches) == 1, 'Incomplete matches filtered'
376+
assert (
377+
len(multi_variant_filtering(graphkb_conn, SOMATIC_KB_MATCHES, [])) == 1
378+
), 'Incomplete matches filtered, without excluded types'
379+
assert (
380+
len(multi_variant_filtering(graphkb_conn, SOMATIC_KB_MATCHES)) == 2
381+
), 'Incomplete matches filtered, with default excluded types'

0 commit comments

Comments
 (0)