def test_contiguous_gaps(self): """Test the counting of contiguous gaps in the coverage array. """ region_start = 0 region_end = 100 intervals = [] intervals.append(interval_tree.Interval(50, 55)) cov_arr = summarize_coverage.project_into_region( intervals, region_start, region_end) n_gaps, tot_gaps = summarize_coverage.get_gaps_from_coverage(cov_arr) self.assertEqual(n_gaps, 2) self.assertEqual(tot_gaps, 95) intervals.append(interval_tree.Interval(75, 80)) cov_arr = summarize_coverage.project_into_region( intervals, region_start, region_end) n_gaps, tot_gaps = summarize_coverage.get_gaps_from_coverage(cov_arr) self.assertEqual(n_gaps, 3) self.assertEqual(tot_gaps, 90)
def test_random_gaps(self): """Test random coverage arrays for contiguous gap counting.""" n_cases = 25 full_interval_size = 10000 n_regions_to_test = 50 max_intervals = 10 for case in xrange(n_cases): n_intervals = random.randrange(1, max_intervals) interval_list = [] for i in xrange(n_intervals): ival_length = random.randrange(full_interval_size / 20) ival_start = random.randrange(full_interval_size - ival_length) ival_end = ival_start + ival_length interval_list.append( interval_tree.Interval(ival_start, ival_end)) cov_arr = summarize_coverage.project_into_region( interval_list, 0, full_interval_size) n_gaps, tot_gaps = summarize_coverage.get_gaps_from_coverage( cov_arr) exp_n_gaps, exp_tot_gaps = 0, 0 for i in xrange(len(cov_arr) - 1): if cov_arr[i] == 0: exp_tot_gaps += 1 if cov_arr[i] != 0 and cov_arr[i + 1] == 0: exp_n_gaps += 1 if cov_arr[-1] == 0: exp_tot_gaps += 1 if cov_arr[0] == 0: exp_n_gaps += 1 self.assertEqual(n_gaps, exp_n_gaps) self.assertEqual(tot_gaps, exp_tot_gaps)