1 #ifndef gamgee__variant_reader__guard
2 #define gamgee__variant_reader__guard
7 #include "../exceptions.h"
8 #include "../utils/hts_memory.h"
9 #include "../utils/variant_utils.h"
46 template<
class ITERATOR>
57 m_variant_file_ptr {},
58 m_variant_header_ptr {}
60 init_reader(filename);
70 m_variant_file_ptr {},
71 m_variant_header_ptr {}
73 if (filenames.size() > 1)
74 throw SingleInputException{
"filenames", filenames.size()};
75 if (!filenames.empty())
76 init_reader(filenames.front());
88 VariantReader(
const std::string& filename,
const std::vector<std::string>& samples,
const bool include =
true) :
89 m_variant_file_ptr {},
90 m_variant_header_ptr {}
92 init_reader(filename);
105 VariantReader(
const std::vector<std::string>& filenames,
const std::vector<std::string>& samples,
const bool include =
true) :
106 m_variant_file_ptr {},
107 m_variant_header_ptr {}
109 if (filenames.size() > 1)
110 throw SingleInputException{
"filenames", filenames.size()};
111 if (!filenames.empty()){
112 init_reader(filenames.front());
138 return ITERATOR{ m_variant_file_ptr, m_variant_header_ptr };
156 std::shared_ptr<htsFile> m_variant_file_ptr;
157 std::shared_ptr<bcf_hdr_t> m_variant_header_ptr;
164 void init_reader (
const std::string& filename) {
168 auto* file_ptr =
bcf_open(filename.empty() ?
"-" : filename.c_str(),
"r");
169 if ( file_ptr ==
nullptr ) {
175 if ( header_ptr ==
nullptr ) {
176 throw HeaderReadException{filename};
VariantReader(const std::vector< std::string > &filenames)
reads through all records in a file (vcf or bcf) parsing them into Variant objects ...
Definition: variant_reader.h:69
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
VariantReader & operator=(const VariantReader &other)=delete
ITERATOR begin() const
creates a ITERATOR pointing at the start of the input stream (needed by for-each loop) ...
Definition: variant_reader.h:137
VariantHeader header() const
returns the variant header of the file being read
Definition: variant_reader.h:153
ITERATOR end() const
creates a ITERATOR with a nullified input stream (needed by for-each loop)
Definition: variant_reader.h:146
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
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
VariantReader(const std::string &filename, const std::vector< std::string > &samples, const bool include=true)
reads through all records in a file (vcf or bcf) parsing them into Variant objects but only including...
Definition: variant_reader.h:88
Utility class to read a VCF/BCF file with an appropriate Variant iterator from a stream (e...
Definition: variant_reader.h:47
Definition: exceptions.h:9
VariantReader(const std::string &filename)
reads through all records in a file (vcf or bcf) parsing them into Variant objects ...
Definition: variant_reader.h:56
VariantReader(const std::vector< std::string > &filenames, const std::vector< std::string > &samples, const bool include=true)
reads through all records in a file (vcf or bcf) parsing them into Variant objects but only including...
Definition: variant_reader.h:105
#define bcf_open(fn, mode)
Definition: vcf.h:274