1 #ifndef gamgee__indexed_variant_reader__guard
2 #define gamgee__indexed_variant_reader__guard
6 #include "../exceptions.h"
7 #include "../utils/hts_memory.h"
30 template<
class ITERATOR>
43 m_variant_file_ptr {},
44 m_variant_index_ptr {},
45 m_variant_header_ptr {},
46 m_interval_list { interval_list }
48 init_reader(filename);
66 return ITERATOR{ m_variant_file_ptr, m_variant_index_ptr, m_variant_header_ptr, m_interval_list };
69 ITERATOR
end()
const {
79 std::shared_ptr<vcfFile> m_variant_file_ptr;
80 std::shared_ptr<hts_idx_t> m_variant_index_ptr;
81 std::shared_ptr<bcf_hdr_t> m_variant_header_ptr;
82 std::vector<std::string> m_interval_list;
84 void init_reader(
const std::string& filename) {
88 auto* variant_file_ptr =
bcf_open(filename.c_str(),
"r");
89 if ( variant_file_ptr ==
nullptr ) {
95 if ( index_file_ptr ==
nullptr ) {
96 throw IndexLoadException{filename};
100 auto* header_ptr =
bcf_hdr_read(m_variant_file_ptr.get());
101 if ( header_ptr ==
nullptr ) {
102 throw HeaderReadException{filename};
IndexedVariantReader(const std::string &filename, const std::vector< std::string > &interval_list)
reads through all records in a file matching one of the given intervals, parsing them into Variant ob...
Definition: indexed_variant_reader.h:42
bcf_hdr_t * bcf_hdr_read(htsFile *fp)
Definition: vcf.c:736
shared_ptr< bcf_hdr_t > make_shared_variant_header(bcf_hdr_t *bcf_hdr_ptr)
wraps a pre-allocated bcf_hdr_t in a shared_ptr with correct deleter
Definition: hts_memory.cpp:63
Exception for the case where there is an error opening a file for reading/writing.
Definition: exceptions.h:14
IndexedVariantReader & operator=(const IndexedVariantReader &other)=delete
shared_ptr< htsFile > make_shared_hts_file(htsFile *hts_file_ptr)
wraps a pre-allocated htsFile in a shared_ptr with correct deleter
Definition: hts_memory.cpp:15
ITERATOR begin() const
Definition: indexed_variant_reader.h:65
VariantHeader header() const
returns the variant header of the file being read
Definition: indexed_variant_reader.h:76
Definition: exceptions.h:9
shared_ptr< hts_idx_t > make_shared_hts_index(hts_idx_t *hts_index_ptr)
wraps a pre-allocated hts_idx_t in a shared_ptr with correct deleter
Definition: hts_memory.cpp:23
ITERATOR end() const
Definition: indexed_variant_reader.h:69
Utility class to read an indexed BCF file by intervals using an appropriate Variant iterator in a for...
Definition: indexed_variant_reader.h:31
#define bcf_index_load(fn)
Definition: vcf.h:724
#define bcf_open(fn, mode)
Definition: vcf.h:274