Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
synced_variant_reader.h
Go to the documentation of this file.
1 #ifndef gamgee__synced_variant_reader__guard
2 #define gamgee__synced_variant_reader__guard
3 
4 #include "htslib/vcf.h"
6 
7 #include "../exceptions.h"
8 #include "../utils/hts_memory.h"
9 
10 #include <string>
11 #include <iostream>
12 
13 using namespace std;
14 
15 namespace gamgee {
16 
41 template<class ITERATOR>
43  public:
44 
52  SyncedVariantReader(const std::vector<std::string>& filenames, const std::string& interval_list) :
54  {
55  auto success = 0;
56  if (interval_list.empty()) {
57  m_synced_readers->require_index = 1;
58  }
59  else {
60  success = bcf_sr_set_regions(m_synced_readers.get(), interval_list.c_str(), 0);
61  if (success != 0)
62  throw HtslibException(success);
63  }
64 
65  for (const auto& filename : filenames) {
66  success = bcf_sr_add_reader(m_synced_readers.get(), filename.c_str());
67  if (success != 1) { // returns 1 on success to indicate 1 file added
68  throw FileOpenException{filename};
69  }
70  }
71  }
72 
76  SyncedVariantReader(SyncedVariantReader&& other) = default;
77  SyncedVariantReader& operator=(SyncedVariantReader&& other) = default;
78 
82  SyncedVariantReader(const SyncedVariantReader&) = delete;
83  SyncedVariantReader& operator=(const SyncedVariantReader&) = delete;
84 
91  ITERATOR begin() const {
92  return ITERATOR{m_synced_readers};
93  }
94 
100  ITERATOR end() const {
101  return ITERATOR{};
102  }
103 
104  private:
105  std::shared_ptr<bcf_srs_t> m_synced_readers;
106 };
107 
108 } // end namespace gamgee
109 
110 #endif /* gamgee__synced_variant_reader__guard */
Utility class to read multiple VCF.GZ/BCF files with an appropriate iterator in a for-each loop...
Definition: synced_variant_reader.h:42
SyncedVariantReader(const std::vector< std::string > &filenames, const std::string &interval_list)
opens multiple files (vcf or bcf) and allows an iterator to parse them
Definition: synced_variant_reader.h:52
ITERATOR begin() const
creates a ITERATOR pointing at the start of the input stream (needed by for-each loop) ...
Definition: synced_variant_reader.h:91
int bcf_sr_add_reader(bcf_srs_t *readers, const char *fname)
Definition: synced_bcf_reader.c:132
bcf_srs_t * bcf_sr_init(void)
Definition: synced_bcf_reader.c:245
int bcf_sr_set_regions(bcf_srs_t *readers, const char *regions, int is_file)
Definition: synced_bcf_reader.c:104
Definition: exceptions.h:9
std::shared_ptr< bcf_srs_t > make_shared_synced_variant_reader(bcf_srs_t *synced_reader_ptr)
wraps a pre-allocated bcf_srs_t in a shared_ptr with correct deleter
Definition: hts_memory.cpp:71
ITERATOR end() const
creates a ITERATOR with a nullified input stream (needed by for-each loop)
Definition: synced_variant_reader.h:100