def test_negative_gc_ratio(self, algorithm): """When the user submits a negative GC ratio, they are shown an error. """ with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record('ATGC'), 2, -1.5, 0.6) assert (str(exc_info.value) == 'Invalid GC ratio for ratio between zero and one: -1.5')
def test_greater_than_one_gc_ratio(self, algorithm): """When the user submits a GC ratio greater than one, they are shown an error. """ with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record('ATGC'), 2, 20, 0.6) assert (str(exc_info.value) == 'Invalid GC ratio for ratio between zero and one: 20')
def test_single_cpg(self, algorithm): seq_str = 'CG' computed = algorithm(make_seq_record(seq_str), 2, 1, 2) expected = make_algo_results(seq_str, [(0, 2, 1, 2)]) print computed.seq_record.features[0].extract(computed.seq_record.seq) for a in [computed, expected]: print a.island_metadata_list[0].gc_ratio assert computed == expected
def test_negative_obs_to_exp_ratio(self, algorithm): """When the user submits a negative observed-to-expected CpG ratio, they are shown an error. """ with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record('ATGC'), 2, 0.5, -1.5) assert (str(exc_info.value) == 'Invalid observed-to-expected CpG ratio ' 'for ratio greater than or equal to zero: -1.5')
def test_negative_obs_to_exp_ratio(self, algorithm): """When the user submits a negative observed-to-expected CpG ratio, they are shown an error. """ with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record('ATGC'), 2, 0.5, -1.5) assert (str( exc_info.value) == 'Invalid observed-to-expected CpG ratio ' 'for ratio greater than or equal to zero: -1.5')
def test_island_size_less_than_sequence_size(self, algorithm): """When the user submits an island size greater than the sequence size, they are shown an error. """ with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record('ATATGCGC'), 9, 0.5, 0.6) assert ((str(exc_info.value)) == 'Island size (9) must be less than or ' 'equal to sequence length (8)')
def test_island_size_less_than_sequence_size(self, algorithm): """When the user submits an island size greater than the sequence size, they are shown an error. """ with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record('ATATGCGC'), 9, 0.5, 0.6) assert ((str( exc_info.value)) == 'Island size (9) must be less than or ' 'equal to sequence length (8)')
def test_set_results_islands_computed_called(self, model): seq_str = 'ATATCGCGCGCGCATATA' feature_tuples = [(0, 3), (5, 7), (8, 13)] seq_record = make_seq_record(seq_str, feature_tuples) results = AlgoResults(seq_record, []) callback = MagicMock() model.islands_computed.append(callback) model.set_results(results, sentinel.algo_name, sentinel.exec_time) assert (callback.mock_calls == [ call(seq_str, feature_tuples, sentinel.algo_name, sentinel.exec_time) ])
def test_get_island_info(self, model): seq_record = make_seq_record( 'ATATCGCGCGCGCATATA', [(0, 3), (5, 7), (8, 13)]) island_metadata_list = [ IslandMetadata(0.57, 0.89), IslandMetadata(0.65, 2.13), IslandMetadata(0.78, 1.3)] results = AlgoResults(seq_record, island_metadata_list) model.set_results(results, sentinel.algo_name, sentinel.exec_time) computed = model.get_island_info(1) expected = IslandInfo(5, 7, 2, 'GC', 0.65, 2.13) assert computed == expected
def test_get_island_info(self, model): seq_record = make_seq_record('ATATCGCGCGCGCATATA', [(0, 3), (5, 7), (8, 13)]) island_metadata_list = [ IslandMetadata(0.57, 0.89), IslandMetadata(0.65, 2.13), IslandMetadata(0.78, 1.3) ] results = AlgoResults(seq_record, island_metadata_list) model.set_results(results, sentinel.algo_name, sentinel.exec_time) computed = model.get_island_info(1) expected = IslandInfo(5, 7, 2, 'GC', 0.65, 2.13) assert computed == expected
def test_set_results_islands_computed_called(self, model): seq_str = 'ATATCGCGCGCGCATATA' feature_tuples = [(0, 3), (5, 7), (8, 13)] seq_record = make_seq_record(seq_str, feature_tuples) results = AlgoResults(seq_record, []) callback = MagicMock() model.islands_computed.append(callback) model.set_results(results, sentinel.algo_name, sentinel.exec_time) assert (callback.mock_calls == [call(seq_str, feature_tuples, sentinel.algo_name, sentinel.exec_time)])
def test_file_loaded_called(self, model): seq_str = 'ATATGCGCATATA' with patch('cpg_islands.models.Entrez') as mock_entrez: with patch('cpg_islands.models.SeqIO') as mock_seqio: # call previously necessary methods mock_entrez.read.return_value = { 'IdList': [sentinel._, sentinel._, sentinel._, sentinel._], 'QueryTranslation': sentinel._} model.search(sentinel._) mock_seqio.read.return_value = make_seq_record(seq_str) model.get_seq_record(2) model.load_seq() assert model.seq_input_model.mock_calls == [ call.file_loaded(seq_str)]
def test_user_selected(self, presenter): seq_str = 'ATATACGCGCATATA' seq_id = 'NG_032827.2' seq_desc = "It's a pretty cool sequence" seq_record = make_seq_record(seq_str) seq_record.id = seq_id seq_record.description = seq_desc presenter.model.get_seq_record.return_value = seq_record presenter._user_selected(sentinel.index) assert presenter.model.mock_calls == [ call.get_seq_record(sentinel.index)] assert presenter.view.mock_calls == [ call.set_seq_locus( seq_id, 'http://www.ncbi.nlm.nih.gov/nuccore/NG_032827.2'), call.set_seq_desc(seq_desc), call.set_seq_len('15 bases'), call.set_selected_seq(seq_str)]
def test_file_loaded_called(self, model): seq_str = 'ATATGCGCATATA' with patch('cpg_islands.models.Entrez') as mock_entrez: with patch('cpg_islands.models.SeqIO') as mock_seqio: # call previously necessary methods mock_entrez.read.return_value = { 'IdList': [sentinel._, sentinel._, sentinel._, sentinel._], 'QueryTranslation': sentinel._ } model.search(sentinel._) mock_seqio.read.return_value = make_seq_record(seq_str) model.get_seq_record(2) model.load_seq() assert model.seq_input_model.mock_calls == [ call.file_loaded(seq_str) ]
def test_user_selected(self, presenter): seq_str = 'ATATACGCGCATATA' seq_id = 'NG_032827.2' seq_desc = "It's a pretty cool sequence" seq_record = make_seq_record(seq_str) seq_record.id = seq_id seq_record.description = seq_desc presenter.model.get_seq_record.return_value = seq_record presenter._user_selected(sentinel.index) assert presenter.model.mock_calls == [ call.get_seq_record(sentinel.index) ] assert presenter.view.mock_calls == [ call.set_seq_locus( seq_id, 'http://www.ncbi.nlm.nih.gov/nuccore/NG_032827.2'), call.set_seq_desc(seq_desc), call.set_seq_len('15 bases'), call.set_selected_seq(seq_str) ]
def test_zero_gc_ratio(self, algorithm): """The user can submit a GC ratio of zero.""" algorithm(make_seq_record('ATCG'), 2, 0, 0.6)
def test_island_at_end(self, algorithm): seq_str = 'GCATAACGGTAATCTATCGTATCATATT' computed = algorithm(make_seq_record(seq_str), 2, 0.5, 0.6) expected = make_algo_results(seq_str, [(6, 12, 0.5, 3), (17, 21, 0.5, 4)]) assert computed == expected
def test_island_at_end(self, algorithm): seq_str = 'ATATATTATTCAACGAGG' computed = algorithm(make_seq_record(seq_str), 5, 0.5, 0.6) expected = make_algo_results(seq_str, [(10, 18, 0.625, 4 / 3)]) assert computed == expected
def test_negative_island_size(self, algorithm): with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record(''), -1, 0, 0.6) assert str(exc_info.value) == 'Invalid island size: -1'
def test_island_at_beginning(self, algorithm): seq_str = 'CGGATATATA' computed = algorithm(make_seq_record(seq_str), 3, 0.5, 0.6) expected = make_algo_results(seq_str, [(0, 6, 0.5, 3)]) assert computed == expected
def test_greater_than_one_obs_to_exp_ratio(self, algorithm): """The user can submit an observed-to-expected CpG ratio greater than one. """ algorithm(make_seq_record('ATGC'), 2, 0.5, 1.5)
def test_island_in_middle(self, algorithm): seq_str = 'ATATACACGGAATATT' computed = algorithm(make_seq_record(seq_str), 4, 0.5, 0.6) expected = make_algo_results(seq_str, [(5, 13, 0.5, 2)]) assert computed == expected
def test_empty_sequence(self, algorithm): with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record(''), 1, 0, 0) assert (str(exc_info.value) == 'Island size (1) must be less than or ' 'equal to sequence length (0)')
def test_zero_island_size(self, algorithm): with pytest.raises(ValueError) as exc_info: algorithm(make_seq_record(''), 0, 0, 0) # exc_info.value returns the actual exception assert str(exc_info.value) == 'Invalid island size: 0'
def test_one_gc_ratio(self, algorithm): """The user can submit a GC ratio of one.""" algorithm(make_seq_record('ATCG'), 2, 1, 0.6)
def test_island_at_end(self, algorithm): seq_str = 'GCATAACGGTAATCTATCGTATCATATT' computed = algorithm(make_seq_record(seq_str), 2, 0.5, 0.6) expected = make_algo_results( seq_str, [(6, 12, 0.5, 3), (17, 21, 0.5, 4)]) assert computed == expected
def test_zero_obs_to_exp_ratio(self, algorithm): """The user can submit an observed-to-expected CpG ratio of zero.""" algorithm(make_seq_record('ATGC'), 2, 0.5, 0)