htslib icon indicating copy to clipboard operation
htslib copied to clipboard

hts_itr_t reuse

Open clwgg opened this issue 7 years ago • 0 comments

This is a follow-up to a question I asked in the samtools-devel mailinglist found here.

The problem in question arises if one wants to use an identical instance of a hts_itr_t struct multiple times (same file, same region). Since the struct gets changed during the iteration process (e.g. through sam_itr_next()) it would be ideal to have a sort of "source" iterator which stays in the iterators original state (e.g. created through sam_itr_queryi()), from which the iterator used within sam_itr_next() gets cloned so only the clone gets changed. Alternatively, if the iterator could be reset safely in between uses that would also solve the problem. At present, this seems to be not safe without destroying and recreating the struct.

The two scenarios I describe above could be handled with something like a hts_itr_clone()/hts_itr_fork() function, or with a hts_itr_reset() function as Rob proposes in his mailing list answer. Would an implementation of something like that be feasible?

Thanks!

clwgg avatar May 04 '17 15:05 clwgg