Skip to content

Commit 71db687

Browse files
committed
Treat regions [-1,n) as [0,n) when indexing
In VCF files, 1-based POS=0 represents an event in a telomere. POS=0 is represented as 0-based [-1,0), which previously led to a crash during indexing. Instead treat [-1,0) as [0,1) and larger [-1,n) as [0,n) so that such regions will be placed in an appropriately-sized leftmost bin. (Treat [-1,0) slightly more specially as [0,0) winds up in bin 0.) The previous crash occurred within insert_to_l(); this fixes the crash and alters beg/end for [-1,n) regions for both insert_to_l() and insert_to_b(). Fixes #406.
1 parent e79775f commit 71db687

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

hts.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,12 @@ int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int
13661366
if ( tid>=0 )
13671367
{
13681368
if (idx->bidx[tid] == 0) idx->bidx[tid] = kh_init(bin);
1369-
if ( is_mapped)
1369+
if (is_mapped) {
1370+
// shoehorn [-1,0) (VCF POS=0) into the leftmost bottom-level bin
1371+
if (beg < 0) beg = 0;
1372+
if (end <= 0) end = 1;
13701373
insert_to_l(&idx->lidx[tid], beg, end, idx->z.last_off, idx->min_shift); // last_off points to the start of the current record
1374+
}
13711375
}
13721376
else idx->n_no_coor++;
13731377
bin = hts_reg2bin(beg, end, idx->min_shift, idx->n_lvls);

0 commit comments

Comments
 (0)