def test_overlap_crosstest(self): count, min_start, max_start, max_len = 250, 1, 10000, 20 step_size = 25 ivs = self.create_intervals(count, min_start, max_start, max_len) loop_iv_start = min_start - step_size - 1 tree = IVTree() for iv in ivs: tree.insert(iv) for i in range(loop_iv_start, max_start, step_size): test_iv = GenomicInterval(i, i + step_size) naive_ovl_count = 0 for iv in ivs: if test_iv.overlaps(iv): naive_ovl_count += 1 ovl_all = list(tree.query_all_overlaps(test_iv)) ovl_all_count = len(ovl_all) self.assertEqual(ovl_all_count, naive_ovl_count) ovl_iv = tree.query_overlap(test_iv) ovl = tree.has_overlap(test_iv) if ovl_all_count > 0: self.assertIsNotNone(ovl_iv) self.assertTrue(ovl) else: self.assertIsNone(ovl_iv) self.assertFalse(ovl)
def test_iv_overlap(self): iv1 = GenomicInterval(1, 3) iv2 = GenomicInterval(4, 5) iv3 = GenomicInterval(5, 6) iv4 = GenomicInterval(1, 2) iv5 = GenomicInterval(1, 1) iv6 = GenomicInterval(3, 3) self.assertFalse(iv1.overlaps(iv2)) self.assertTrue(iv2.overlaps(iv3)) self.assertFalse(iv4.overlaps(iv2)) self.assertTrue(iv2.overlaps(iv3)) self.assertTrue(iv5.overlaps(iv1)) self.assertTrue(iv6.overlaps(iv1))