1 #ifndef gamgee__multiple_variant_reader__guard
2 #define gamgee__multiple_variant_reader__guard
9 #include "../exceptions.h"
10 #include "../utils/hts_memory.h"
11 #include "../utils/variant_utils.h"
38 template<
class ITERATOR>
64 const std::vector<std::string>& samples,
const bool include =
true) :
78 void init_reader(
const std::vector<std::string>& filenames,
const bool validate_headers) {
79 m_variant_files.reserve(filenames.size());
80 m_variant_headers.reserve(filenames.size());
82 for (
const auto& filename : filenames) {
84 auto* file_ptr =
bcf_open(filename.empty() ?
"-" : filename.c_str(),
"r");
85 if ( file_ptr ==
nullptr ) {
91 if ( header_raw_ptr ==
nullptr ) {
95 m_variant_headers.push_back(header_ptr);
98 validate_header(header_ptr);
99 m_variant_header_merger.
add_header(header_ptr);
122 return ITERATOR{m_variant_files, m_variant_headers};
155 void validate_header(
const std::shared_ptr<bcf_hdr_t>& other_header_ptr) {
158 throw HeaderCompatibilityException{
"chromosomes in header files are inconsistent"};
161 std::vector<std::shared_ptr<htsFile>> m_variant_files;
162 std::vector<std::shared_ptr<bcf_hdr_t>> m_variant_headers;
MultipleVariantReader(const std::vector< std::string > &filenames, const bool validate_headers=true)
enables reading records in multiple files (vcf or bcf)
Definition: multiple_variant_reader.h:48
bcf_hdr_t * bcf_hdr_read(htsFile *fp)
Definition: vcf.c:736
ITERATOR begin() const
creates an ITERATOR pointing at the start of the input streams (needed by for-each loop) ...
Definition: multiple_variant_reader.h:121
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
void init_reader(const std::vector< std::string > &filenames, const bool validate_headers)
helper function for constructors
Definition: multiple_variant_reader.h:78
ITERATOR end() const
creates a default ITERATOR (needed by for-each loop)
Definition: multiple_variant_reader.h:130
Exception for the case where there is an error opening a file for reading/writing.
Definition: exceptions.h:14
void subset_variant_samples(bcf_hdr_t *hdr_ptr, const std::vector< std::string > &samples, const bool include)
allows the caller to include only selected samples in a Variant Reader. To create a sites only file...
Definition: variant_utils.cpp:15
MultipleVariantReader & operator=(MultipleVariantReader &&other)=default
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
const std::vector< std::shared_ptr< bcf_hdr_t > > & get_input_vcf_headers() const
return vector of input VCF headers
Definition: multiple_variant_reader.h:150
Definition: exceptions.h:9
VariantHeaderMerger< true, true, true, true > InputOrderedVariantHeaderMerger
Definition: variant_header_merger.h:315
InputOrderedVariantHeaderMerger & get_variant_header_merger()
return VariantHeaderMerger object
Definition: multiple_variant_reader.h:144
MultipleVariantReader(const std::vector< std::string > &filenames, const bool validate_headers, const std::vector< std::string > &samples, const bool include=true)
enables reading records in multiple files (vcf or bcf)
Definition: multiple_variant_reader.h:63
const VariantHeader combined_header() const
returns a combined header for the files being read
Definition: multiple_variant_reader.h:138
Utility class to read multiple VCF/BCF files with an appropriate iterator in a for-each loop...
Definition: multiple_variant_reader.h:39
#define bcf_open(fn, mode)
Definition: vcf.h:274