Don't error when making an iterator on a tid not in the index #1545
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Don't error when making an iterator on a tid not in the index, instead return one that instantly finishes.
Fixes #1534, which was an edge case where an index did not include an entry for a chromosome that was mentioned in the file header but had no data records. Normally these would be present but empty, but it was possible to use the
IDX=
key in a VCF file to make an index where the chromosome simply did not appear. In this case, rather than an error, we want to return the equivalent ofHTS_IDX_NONE
so the iterator produces no data.Another scenario where this is useful is if you build an index, and then try to use it immediately without first saving and reading it back in again. Such an index will have NULL entries in
bidx[]
for any chromosomes with no data. Again we want to return anHTS_IDX_NONE
iterator if one of those chromosomes is queried. (This issue didn't usually occur because most programs are loading in an existing index, andidx_read_core()
makesbidx[]
entries for everything even if there's nothing in the index for the chromosome.)Note that this changes
vcf_loop()
intest_view.c
so that it now treatsbcf_itr_querys()
failures as an error. The new behaviour matchessam_loop()
and is needed to detect the problem being fixed here. All the other tests still work after this change so nothing was relying on the old behaviour of ignoring the errors.