Skip to content

Commit 7978384

Browse files
committed
Fix for #137
pyintervaltree overlaps method doesn't behave well with variant ends. Adding one to the ends when doing `addi` produces desired behavior
1 parent 64b5109 commit 7978384

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed
-9 Bytes
Binary file not shown.
-38 Bytes
Binary file not shown.

truvari/region_vcf_iter.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __build_tree(self, vcfA, vcfB):
5151
if not length:
5252
logging.error("Contig %s has no length definition. Fix header.", name)
5353
sys.exit(10)
54-
all_regions[name].addi(0, length)
54+
all_regions[name].addi(0, length + 1)
5555
return all_regions
5656

5757
def merge_overlaps(self):
@@ -93,11 +93,9 @@ def include(self, entry):
9393
# Filter these early so we don't have to keep checking overlaps
9494
if self.max_span is None or aend - astart > self.max_span:
9595
return False
96-
overlaps = self.tree[entry.chrom].overlaps(astart) \
97-
and self.tree[entry.chrom].overlaps(aend)
98-
if astart == aend:
99-
return overlaps
100-
return overlaps and len(self.tree[entry.chrom].overlap(astart, aend)) == 1
96+
if astart == aend - 1:
97+
return self.tree[entry.chrom].overlaps(astart)
98+
return len(self.tree[entry.chrom].overlap(astart, aend)) == 1
10199

102100
def extend(self, pad):
103101
"""
@@ -131,6 +129,6 @@ def build_anno_tree(filename, chrom_col=0, start_col=1, end_col=2, one_based=Fal
131129
m_idx = idxfmt.format(idx)
132130
else:
133131
m_idx = idx
134-
tree[chrom].addi(start, end, data=m_idx)
132+
tree[chrom].addi(start, end + 1, data=m_idx)
135133
idx += 1
136134
return tree, idx

0 commit comments

Comments
 (0)