Skip to content

Commit

Permalink
Make repeated seeks possible
Browse files Browse the repository at this point in the history
Repeated seeks with implicitly created region list wouldn't initialize
all internal structures to the original clean state, as demonstrated by
the issue #1362, resolved by this commit
  • Loading branch information
pd3 committed Dec 16, 2021
1 parent f1ac6bb commit d356185
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion synced_bcf_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ static void bcf_sr_seek_start(bcf_srs_t *readers)
for (i=0; i<reg->nseqs; i++)
reg->regs[i].creg = -1;
reg->iseq = 0;
reg->prev_seq = -1;
}


Expand All @@ -851,8 +852,18 @@ int bcf_sr_seek(bcf_srs_t *readers, const char *seq, hts_pos_t pos)
bcf_sr_seek_start(readers);
return 0;
}
bcf_sr_regions_overlap(readers->regions, seq, pos, pos);

int i, nret = 0;

// Need to position both the readers and the regions. The latter is a bit of a mess
// because we can have in memory or external regions. The safe way is:
// - reset all regions as if they were not read from at all (bcf_sr_seek_start)
// - find the requested iseq (stored in the seq_hash)
// - position regions to the requested position (bcf_sr_regions_overlap)
bcf_sr_seek_start(readers);
if ( khash_str2int_get(readers->regions->seq_hash, seq, &i)>=0 ) readers->regions->iseq = i;
bcf_sr_regions_overlap(readers->regions, seq, pos, pos);

for (i=0; i<readers->nreaders; i++)
{
nret += _reader_seek(&readers->readers[i],seq,pos,MAX_CSI_COOR-1);
Expand Down

0 comments on commit d356185

Please sign in to comment.