1 #ifndef __gamgee_variant_header_merger__
2 #define __gamgee_variant_header_merger__
4 #include <boost/shared_ptr.hpp>
6 #include <unordered_map>
8 #include "../utils/merged_vcf_lut.h"
76 template<
bool fields_forward_LUT_ordering,
bool fields_reverse_LUT_ordering,
bool samples_forward_LUT_ordering,
bool samples_reverse_LUT_ordering>
77 class VariantHeaderMerger
80 static const auto m_DEFAULT_INIT_NUM_INPUT_VCFS = 10u;
81 static const auto m_DEFAULT_INIT_NUM_FIELDS = 30u;
82 static const auto m_DEFAULT_INIT_NUM_SAMPLES = 10u;
88 : m_header_fields_LUT{ m_DEFAULT_INIT_NUM_INPUT_VCFS, m_DEFAULT_INIT_NUM_FIELDS },
89 m_samples_LUT { m_DEFAULT_INIT_NUM_INPUT_VCFS, m_DEFAULT_INIT_NUM_SAMPLES },
90 m_merged_field_idx_enum_lut { 1u, m_DEFAULT_INIT_NUM_FIELDS }
93 m_num_input_vcfs_allocated = m_DEFAULT_INIT_NUM_INPUT_VCFS;
94 m_num_merged_fields_allocated = m_DEFAULT_INIT_NUM_FIELDS;
95 m_num_merged_samples_allocated = m_DEFAULT_INIT_NUM_SAMPLES;
96 m_num_enums_allocated = m_DEFAULT_INIT_NUM_FIELDS;
119 : m_header_fields_LUT{
static_cast<unsigned>(input_vcf_headers.size()), m_DEFAULT_INIT_NUM_FIELDS },
120 m_samples_LUT {
static_cast<unsigned>(input_vcf_headers.size()), m_DEFAULT_INIT_NUM_SAMPLES },
121 m_merged_field_idx_enum_lut { 1u, m_DEFAULT_INIT_NUM_FIELDS }
124 m_num_input_vcfs_allocated = input_vcf_headers.size();
125 m_num_merged_fields_allocated = m_DEFAULT_INIT_NUM_FIELDS;
126 m_num_merged_samples_allocated = m_DEFAULT_INIT_NUM_SAMPLES;
127 m_num_enums_allocated = m_DEFAULT_INIT_NUM_FIELDS;
135 : m_header_fields_LUT{
static_cast<unsigned>(input_vcf_headers.size()), m_DEFAULT_INIT_NUM_FIELDS },
136 m_samples_LUT {
static_cast<unsigned>(input_vcf_headers.size()), m_DEFAULT_INIT_NUM_SAMPLES },
137 m_merged_field_idx_enum_lut { 1u, m_DEFAULT_INIT_NUM_FIELDS }
140 m_num_input_vcfs_allocated = input_vcf_headers.size();
141 m_num_merged_fields_allocated = m_DEFAULT_INIT_NUM_FIELDS;
142 m_num_merged_samples_allocated = m_DEFAULT_INIT_NUM_SAMPLES;
143 m_num_enums_allocated = m_DEFAULT_INIT_NUM_FIELDS;
163 m_input_vcf_headers.clear();
164 m_sample2idx_merged.clear();
165 m_merged_vcf_header_ptr =
nullptr;
166 m_num_merged_fields_allocated = 0u;
167 m_num_merged_samples_allocated = 0u;
168 m_num_input_vcfs_allocated = 0u;
169 m_num_enums_allocated = 0u;
180 m_header_fields_LUT.
clear();
181 m_samples_LUT.
clear();
182 m_merged_field_idx_enum_lut.
clear();
188 void add_header(
const std::shared_ptr<bcf_hdr_t>& hdr);
198 void add_headers(
const std::vector<std::shared_ptr<bcf_hdr_t>>& headers);
203 void add_headers(
const std::vector<VariantHeader>& headers);
288 void resize_luts_if_needed();
294 void add_header_fields_mapping(
bcf_hdr_t* curr_header,
unsigned input_vcf_idx);
296 void add_samples_mapping(
bcf_hdr_t* curr_header,
unsigned input_vcf_idx);
298 std::unordered_map<std::string,int> m_sample2idx_merged;
300 std::vector<std::shared_ptr<bcf_hdr_t>> m_input_vcf_headers;
302 std::shared_ptr<bcf_hdr_t> m_merged_vcf_header_ptr;
304 unsigned m_num_merged_fields_allocated;
305 unsigned m_num_merged_samples_allocated;
306 unsigned m_num_input_vcfs_allocated;
307 unsigned m_num_enums_allocated;
int get_input_idx_for_merged(unsigned inputGVCFIdx, int mergedIdx) const
Get field idx for input VCF inputGVCFIdx corresponding to field idx mergedIdx in the mergedVCF file...
Definition: merged_vcf_lut.h:100
void clear()
deallocates memory
Definition: merged_vcf_lut.cpp:27
void reset_luts()
: clear all mappings
Definition: merged_vcf_lut.h:69
int get_merged_idx_for_input(unsigned inputGVCFIdx, int inputIdx) const
Get field idx for the merged VCF corresponding to field idx inputIdx in the input VCF of index inputG...
Definition: merged_vcf_lut.h:116
Definition: exceptions.h:9