After using hts_open in SAMFile, the htsFile.fp.bgzf pointer is not set. Below are some work-arounds for dealing with this as the BGZF pointer is required for using the query iterator functions hts_itr_queryi and hts_itr_querys. Another side effect (or a potentially separate issue) is that the BGZF created in the workaround below cannot be closed using bgzf_close without segfault.
After using hts_open in SAMFile, the htsFile.fp.bgzf pointer is not set. Below are some work-arounds for dealing with this as the BGZF pointer is required for using the query iterator functions hts_itr_queryi and hts_itr_querys. Another side effect (or a potentially separate issue) is that the BGZF created in the workaround below cannot be closed using bgzf_close without segfault.
https://github.com/blachlylab/dhtslib/blob/bab86a8286819623c1d8ab5bcab674f6e514eb27/source/dhtslib/sam.d#L288-L310