Skip to content

Commit

Permalink
Add tests to multi_variant_filtering()
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieulemieux committed Oct 29, 2024
1 parent ecead72 commit 1d18d54
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions tests/test_ipr/test_ipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

from pori_python.graphkb import statement as gkb_statement
from pori_python.graphkb import vocab as gkb_vocab
from pori_python.ipr.ipr import convert_statements_to_alterations, germline_kb_matches
from pori_python.ipr.ipr import (
convert_statements_to_alterations,
germline_kb_matches,
multi_variant_filtering,
)
from pori_python.types import Statement

DISEASE_RIDS = ["#138:12", "#138:13"]
Expand Down Expand Up @@ -142,6 +146,24 @@
},
]

KB_MATCHES_STATEMENTS = [
{
'@rid': SOMATIC_KB_MATCHES[0]['kbStatementId'],
'conditions': [
{'@class': 'PositionalVariant', '@rid': SOMATIC_KB_MATCHES[0]['kbVariantId']},
{'@class': 'CategoryVariant', '@rid': SOMATIC_KB_MATCHES[1]['kbVariantId']},
{'@class': 'Disease', '@rid': ''}, # non-variant condition
],
},
{
'@rid': SOMATIC_KB_MATCHES[1]['kbStatementId'],
'conditions': [
{'@class': 'CategoryVariant', '@rid': SOMATIC_KB_MATCHES[1]['kbVariantId']},
{'@class': 'PositionalVariant', '@rid': '157:0'}, # Unmatched variant
],
},
]


@pytest.fixture
def graphkb_conn():
Expand All @@ -157,10 +179,15 @@ def __call__(self, *args, **kwargs):
ret_val = self.return_values[self.index] if self.index < len(self.return_values) else []
return ret_val

class PostMock:
def __call__(self, *args, **kwargs):
# custom return tailored for multi_variant_filtering() testing
return {'result': KB_MATCHES_STATEMENTS}

def mock_get_source(source):
return {"@rid": 0}

conn = Mock(query=QueryMock(), cache={}, get_source=mock_get_source)
conn = Mock(query=QueryMock(), cache={}, get_source=mock_get_source, post=PostMock())

return conn

Expand Down Expand Up @@ -336,3 +363,8 @@ def test_germline_kb_matches(self):
assert not germline_kb_matches(
SOMATIC_KB_MATCHES, GERMLINE_VARIANTS
), "Germline variant matched to KB somatic statement."

def test_multi_variant_filtering(self, graphkb_conn):
gkb_matches = multi_variant_filtering(graphkb_conn, SOMATIC_KB_MATCHES)
assert len(SOMATIC_KB_MATCHES) == 2, 'Matches before filtering'
assert len(gkb_matches) == 1, 'Incomplete matches filtered'

0 comments on commit 1d18d54

Please sign in to comment.