Skip to content

Commit

Permalink
implemented tests for ortholog-mapping functions in the filtering module
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyTeichman committed Oct 30, 2023
1 parent c9ef7fd commit e9abb02
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tests/test_files/test_map_orthologs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
,cond1,cond2,cond3,cond4
gene1,633,451,365,388
gene3,60,57,20,23
gene2,0,0,0,1
gene4,55,266,46,39
gene5,15,13,1,0
3 changes: 3 additions & 0 deletions tests/test_files/test_map_orthologs_remove_unmapped_truth.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,cond1,cond2,cond3,cond4
ortholog2,633,451,365,388
ortholog3,0,0,0,1
6 changes: 6 additions & 0 deletions tests/test_files/test_map_orthologs_truth.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
,cond1,cond2,cond3,cond4
ortholog2,633,451,365,388
gene3,60,57,20,23
ortholog3,0,0,0,1
gene4,55,266,46,39
gene5,15,13,1,0
137 changes: 135 additions & 2 deletions tests/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ def test_find_paralogs_panther(mock_mapper):
mock_mapper_instance.get_paralogs.return_value = io.OrthologDict(
{'gene1': ['paralog1', 'paralog2'], 'gene2': ['paralog3']})

filter_obj = Filter('tests/test_files/counted.csv')
filter_obj = Filter('tests/test_files/test_map_orthologs.csv')
result = filter_obj.find_paralogs_panther(organism='Homo sapiens', gene_id_type='UniProtKB')

assert result.equals(df_truth)
Expand All @@ -2196,11 +2196,144 @@ def test_find_paralogs_ensembl(mock_mapper, filter_percent_identity):
mock_mapper_instance.get_paralogs.return_value = io.OrthologDict(
{'gene1': ['paralog1', 'paralog2'], 'gene2': ['paralog3']})

filter_obj = Filter('tests/test_files/counted.csv')
filter_obj = Filter('tests/test_files/test_map_orthologs.csv')
result = filter_obj.find_paralogs_ensembl(organism='Homo sapiens', gene_id_type='UniProtKB',
filter_percent_identity=filter_percent_identity)

assert result.equals(df_truth)
mock_mapper.assert_called_once_with(9606, 9606, 'UniProtKB')
mock_mapper_instance.get_paralogs.assert_called_once_with(parsing.data_to_tuple(filter_obj.index_set),
filter_percent_identity)


@pytest.mark.parametrize('remove_unmapped', [True, False])
@pytest.mark.parametrize('non_unique_mode,filter_least_diverged', [
('first', True),
('last', False),
])
@patch('rnalysis.utils.io.PantherOrthologMapper')
def test_map_orthologs_panther(mock_mapper, non_unique_mode, filter_least_diverged, remove_unmapped):
if remove_unmapped:
filter_obj_path = 'tests/test_files/test_map_orthologs_remove_unmapped_truth.csv'
else:
filter_obj_path = 'tests/test_files/test_map_orthologs_truth.csv'
filter_obj_truth = Filter(filter_obj_path)
one2many_truth = pd.DataFrame(
{'gene': ['gene1', 'gene1', 'gene2'], 'ortholog': ['ortholog1', 'ortholog2', 'ortholog3']})
mock_mapper_instance = Mock()
mock_mapper.return_value = mock_mapper_instance
mock_mapper_instance.get_orthologs.return_value = (
io.OrthologDict({'gene1': 'ortholog2', 'gene2': 'ortholog3'})
, io.OrthologDict({'gene1': ['ortholog1', 'ortholog2'], 'gene2': ['ortholog3']}))

filter_obj = Filter('tests/test_files/test_map_orthologs.csv')
one2one, one2many = filter_obj.map_orthologs_panther('Homo sapiens', 'caenorhabditis elegans',
gene_id_type='UniProtKB', inplace=False,
non_unique_mode=non_unique_mode,
filter_least_diverged=filter_least_diverged,
remove_unmapped_genes=remove_unmapped)

assert one2many.equals(one2many_truth)
assert one2one == filter_obj_truth
mock_mapper.assert_called_once_with(9606, 6239, 'UniProtKB')
mock_mapper_instance.get_orthologs.assert_called_once_with(
parsing.data_to_tuple(filter_obj.index_set), non_unique_mode, filter_least_diverged)


@pytest.mark.parametrize('remove_unmapped', [True, False])
@pytest.mark.parametrize('non_unique_mode,filter_percent_identity', [
('first', True),
('last', False),
])
@patch('rnalysis.utils.io.EnsemblOrthologMapper')
def test_map_orthologs_ensembl(mock_mapper, non_unique_mode, filter_percent_identity, remove_unmapped):
if remove_unmapped:
filter_obj_path = 'tests/test_files/test_map_orthologs_remove_unmapped_truth.csv'
else:
filter_obj_path = 'tests/test_files/test_map_orthologs_truth.csv'
filter_obj_truth = Filter(filter_obj_path)
one2many_truth = pd.DataFrame(
{'gene': ['gene1', 'gene1', 'gene2'], 'ortholog': ['ortholog1', 'ortholog2', 'ortholog3']})
mock_mapper_instance = Mock()
mock_mapper.return_value = mock_mapper_instance
mock_mapper_instance.get_orthologs.return_value = (
io.OrthologDict({'gene1': 'ortholog2', 'gene2': 'ortholog3'})
, io.OrthologDict({'gene1': ['ortholog1', 'ortholog2'], 'gene2': ['ortholog3']}))

filter_obj = Filter('tests/test_files/test_map_orthologs.csv')
one2one, one2many = filter_obj.map_orthologs_ensembl('Homo sapiens', 'caenorhabditis elegans',
gene_id_type='UniProtKB', inplace=False,
non_unique_mode=non_unique_mode,
filter_percent_identity=filter_percent_identity,
remove_unmapped_genes=remove_unmapped)

assert one2many.equals(one2many_truth)
assert one2one == filter_obj_truth
mock_mapper.assert_called_once_with(9606, 6239, 'UniProtKB')
mock_mapper_instance.get_orthologs.assert_called_once_with(
parsing.data_to_tuple(filter_obj.index_set), non_unique_mode, filter_percent_identity)


@pytest.mark.parametrize('remove_unmapped', [True, False])
@pytest.mark.parametrize('non_unique_mode,filter_consistency_score,threshold', [
('first', True, 0.5),
('last', False, 0.93),
])
@patch('rnalysis.utils.io.PhylomeDBOrthologMapper')
def test_map_orthologs_phylomedb(mock_mapper, non_unique_mode, filter_consistency_score, remove_unmapped, threshold):
if remove_unmapped:
filter_obj_path = 'tests/test_files/test_map_orthologs_remove_unmapped_truth.csv'
else:
filter_obj_path = 'tests/test_files/test_map_orthologs_truth.csv'
filter_obj_truth = Filter(filter_obj_path)
one2many_truth = pd.DataFrame(
{'gene': ['gene1', 'gene1', 'gene2'], 'ortholog': ['ortholog1', 'ortholog2', 'ortholog3']})
mock_mapper_instance = Mock()
mock_mapper.return_value = mock_mapper_instance
mock_mapper_instance.get_orthologs.return_value = (
io.OrthologDict({'gene1': 'ortholog2', 'gene2': 'ortholog3'})
, io.OrthologDict({'gene1': ['ortholog1', 'ortholog2'], 'gene2': ['ortholog3']}))

filter_obj = Filter('tests/test_files/test_map_orthologs.csv')
one2one, one2many = filter_obj.map_orthologs_phylomedb('Homo sapiens', 'caenorhabditis elegans',
gene_id_type='UniProtKB', inplace=False,
non_unique_mode=non_unique_mode,
filter_consistency_score=filter_consistency_score,
consistency_score_threshold=threshold,
remove_unmapped_genes=remove_unmapped)

assert one2many.equals(one2many_truth)
assert one2one == filter_obj_truth
mock_mapper.assert_called_once_with(9606, 6239, 'UniProtKB')
mock_mapper_instance.get_orthologs.assert_called_once_with(
parsing.data_to_tuple(filter_obj.index_set), non_unique_mode, threshold, filter_consistency_score)


@pytest.mark.parametrize('remove_unmapped', [True, False])
@pytest.mark.parametrize('non_unique_mode', ['first', 'last'])
@patch('rnalysis.utils.io.OrthoInspectorOrthologMapper')
def test_map_orthologs_orthoinspector(mock_mapper, non_unique_mode, remove_unmapped):
if remove_unmapped:
filter_obj_path = 'tests/test_files/test_map_orthologs_remove_unmapped_truth.csv'
else:
filter_obj_path = 'tests/test_files/test_map_orthologs_truth.csv'
filter_obj_truth = Filter(filter_obj_path)
one2many_truth = pd.DataFrame(
{'gene': ['gene1', 'gene1', 'gene2'], 'ortholog': ['ortholog1', 'ortholog2', 'ortholog3']})
mock_mapper_instance = Mock()
mock_mapper.return_value = mock_mapper_instance
mock_mapper_instance.get_orthologs.return_value = (
io.OrthologDict({'gene1': 'ortholog2', 'gene2': 'ortholog3'})
, io.OrthologDict({'gene1': ['ortholog1', 'ortholog2'], 'gene2': ['ortholog3']}))

filter_obj = Filter('tests/test_files/test_map_orthologs.csv')
one2one, one2many = filter_obj.map_orthologs_orthoinspector('Homo sapiens', 'caenorhabditis elegans',
gene_id_type='UniProtKB', inplace=False,
non_unique_mode=non_unique_mode,
remove_unmapped_genes=remove_unmapped)

assert one2many.equals(one2many_truth)
assert one2one == filter_obj_truth
mock_mapper.assert_called_once_with(9606, 6239, 'UniProtKB')
mock_mapper_instance.get_orthologs.assert_called_once_with(
parsing.data_to_tuple(filter_obj.index_set), non_unique_mode)

0 comments on commit e9abb02

Please sign in to comment.