Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
variant_reader.h
Go to the documentation of this file.
1 #ifndef gamgee__variant_reader__
2 #define gamgee__variant_reader__
3 
4 #include "variant_header.h"
5 #include "variant_iterator.h"
6 #include "utils/hts_memory.h"
7 
8 #include "htslib/vcf.h"
9 
10 #include <string>
11 #include <iostream>
12 #include <fstream>
13 #include <memory>
14 
15 
16 namespace gamgee {
17 
43 template<class ITERATOR>
45  public:
46 
53  VariantReader(const std::string& filename) :
54  m_variant_file_ptr {bcf_open(filename.empty() ? "-" : filename.c_str(), "r")},
55  m_variant_header_ptr { utils::make_shared_variant_header(bcf_hdr_read(m_variant_file_ptr)) }
56  {}
57 
62  m_variant_file_ptr {std::move(other.m_variant_file_ptr)},
63  m_variant_header_ptr {std::move(other.m_variant_header_ptr)}
64  {}
65 
70  bcf_close(m_variant_file_ptr);
71  }
72 
76  VariantReader(const VariantReader&) = delete;
77 
84  ITERATOR begin() {
85  return ITERATOR{m_variant_file_ptr, m_variant_header_ptr};
86  }
87 
93  ITERATOR end() {
94  return ITERATOR{};
95  }
96 
100  inline VariantHeader header() { return VariantHeader{m_variant_header_ptr}; }
101 
102  private:
103  vcfFile* m_variant_file_ptr;
104  const std::shared_ptr<bcf_hdr_t> m_variant_header_ptr;
105 };
106 
108 
109 } // end of namespace
110 
111 #endif /* defined(__gamgee__variant_iterator__) */
VariantReader(VariantReader &&other)
VariantReader should never be copied, but it can be moved around.
Definition: variant_reader.h:61
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:38
VariantHeader header()
returns the variant header of the file being read
Definition: variant_reader.h:100
~VariantReader()
closes the file stream if there is one (in case we are reading a variant file)
Definition: variant_reader.h:69
Utility class to read a VCF/BCF file with an appropriate Variant iterator from a stream (e...
Definition: variant_reader.h:44
ITERATOR end()
creates a ITERATOR with a nullified input stream (needed by for-each loop)
Definition: variant_reader.h:93
ITERATOR begin()
creates a ITERATOR pointing at the start of the input stream (needed by for-each loop) ...
Definition: variant_reader.h:84
VariantReader(const std::string &filename)
reads through all records in a file (vcf or bcf) parsing them into Variant objects ...
Definition: variant_reader.h:53
Utility class to hold a variant header.
Definition: variant_header.h:18