Skip to content

Commit

Permalink
Treat regions [-1,n) as [0,n) when indexing
Browse files Browse the repository at this point in the history
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 samtools#406.
  • Loading branch information
jmarshall committed Sep 7, 2016
1 parent e79775f commit 71db687
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,12 @@ int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int
if ( tid>=0 )
{
if (idx->bidx[tid] == 0) idx->bidx[tid] = kh_init(bin);
if ( is_mapped)
if (is_mapped) {
// shoehorn [-1,0) (VCF POS=0) into the leftmost bottom-level bin
if (beg < 0) beg = 0;
if (end <= 0) end = 1;
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
}
}
else idx->n_no_coor++;
bin = hts_reg2bin(beg, end, idx->min_shift, idx->n_lvls);
Expand Down

0 comments on commit 71db687

Please sign in to comment.