1 #ifndef gamgee__sam_reader__guard
2 #define gamgee__sam_reader__guard
7 #include "../exceptions.h"
8 #include "../utils/hts_memory.h"
45 template<
class ITERATOR>
59 init_reader(filename);
68 SamReader(
const std::vector<std::string>& filenames) :
72 if (filenames.size() > 1)
73 throw SingleInputException{
"filenames", filenames.size()};
74 if (!filenames.empty())
75 init_reader(filenames.front());
97 return ITERATOR{m_sam_file_ptr, m_sam_header_ptr};
112 std::shared_ptr<htsFile> m_sam_file_ptr;
113 std::shared_ptr<bam_hdr_t> m_sam_header_ptr;
120 void init_reader (
const std::string& filename) {
121 auto* file_ptr =
sam_open(filename.empty() ?
"-" : filename.c_str(),
"r");
122 if ( file_ptr ==
nullptr ) {
128 if ( header_ptr ==
nullptr ) {
129 throw HeaderReadException{filename};
ITERATOR end()
creates a ITERATOR with a nullified input stream (needed by for-each loop)
Definition: sam_reader.h:105
bam_hdr_t * sam_hdr_read(samFile *fp)
Definition: sam.c:633
Exception for the case where there is an error opening a file for reading/writing.
Definition: exceptions.h:14
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
Utility class to read a SAM/BAM/CRAM file with an appropriate Sam iterator from a stream (e...
Definition: sam_reader.h:46
shared_ptr< bam_hdr_t > make_shared_sam_header(bam_hdr_t *sam_header_ptr)
wraps a pre-allocated bam_hdr_t in a shared_ptr with correct deleter
Definition: hts_memory.cpp:47
SamHeader header()
Definition: sam_reader.h:109
SamReader & operator=(const SamIterator &)=delete
Definition: exceptions.h:9
ITERATOR begin()
creates a ITERATOR pointing at the start of the input stream (needed by for-each loop) ...
Definition: sam_reader.h:96
SamReader(const std::string &filename)
reads through all records in a file ( or sam) parsing them into Sam objects
Definition: sam_reader.h:55
SamReader(const std::vector< std::string > &filenames)
reads through all records in a file ( or sam) parsing them into Sam objects
Definition: sam_reader.h:68
#define sam_open(fn, mode)
Definition: sam.h:317