Skip to content

Commit a4a0157

Browse files
committed
don't re-opening index file every time setRegion is called
1 parent b703214 commit a4a0157

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

vcfpp.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file https://github.com/Zilong-Li/vcfpp/vcfpp.h
33
* @author Zilong Li
44
5-
* @version v0.6.1
5+
* @version v0.6.2
66
* @breif a single C++ file for manipulating VCF
77
* Copyright (C) 2022-2023.The use of this code is governed by the LICENSE file.
88
******************************************************************************/
@@ -1633,6 +1633,14 @@ class BcfReader
16331633
header.hdr = bcf_hdr_read(fp.get());
16341634
nsamples = bcf_hdr_nsamples(header.hdr);
16351635
SamplesName = header.getSamples();
1636+
if(isBcf)
1637+
{
1638+
hidx = std::shared_ptr<hts_idx_t>(bcf_index_load(fname.c_str()), details::hts_idx_close());
1639+
}
1640+
else
1641+
{
1642+
tidx = std::shared_ptr<tbx_t>(tbx_index_load(fname.c_str()), details::tabix_idx_close());
1643+
}
16361644
}
16371645

16381646
/** @brief set the number of threads to use */
@@ -1714,7 +1722,6 @@ class BcfReader
17141722
// 3. if region is empty, use "."
17151723
if(isBcf)
17161724
{
1717-
hidx = std::shared_ptr<hts_idx_t>(bcf_index_load(fname.c_str()), details::hts_idx_close());
17181725
if(itr) itr.reset(); // reset current region.
17191726
if(region.empty())
17201727
itr = std::shared_ptr<hts_itr_t>(bcf_itr_querys(hidx.get(), header.hdr, "."),
@@ -1725,7 +1732,6 @@ class BcfReader
17251732
}
17261733
else
17271734
{
1728-
tidx = std::shared_ptr<tbx_t>(tbx_index_load(fname.c_str()), details::tabix_idx_close());
17291735
if(tidx.get() == NULL) throw std::invalid_argument(" no tabix index found!");
17301736
if(itr) itr.reset(); // reset
17311737
if(region.empty())

0 commit comments

Comments
 (0)