1 #ifndef __gamgee_merged_vcf_lut__
2 #define __gamgee_merged_vcf_lut__
9 #include "../missing.h"
10 #include "../variant/variant_header.h"
13 template<
bool inputs_2_merged_LUT_is_input_ordered,
bool merged_2_inputs_LUT_is_input_ordered>
19 template<
bool fields_forward_LUT_ordering,
bool fields_reverse_LUT_ordering,
bool samples_forward_LUT_ordering,
bool samples_reverse_LUT_ordering>
58 template<
bool inputs_2_merged_LUT_is_input_ordered,
bool merged_2_inputs_LUT_is_input_ordered>
61 template<
bool fields_forward_LUT_ordering,
bool fields_reverse_LUT_ordering,
bool samples_forward_LUT_ordering,
bool samples_reverse_LUT_ordering>
63 template<
bool v1,
bool v2>
71 for(
auto& vec : m_inputs_2_merged_lut)
73 for(
auto& vec : m_merged_2_inputs_lut)
86 set_merged_idx_for_input(inputGVCFIdx, inputIdx, mergedIdx);
87 set_input_idx_for_merged(inputGVCFIdx, inputIdx, mergedIdx);
99 template <bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<M>::type* =
nullptr>
101 {
return get_lut_value(m_merged_2_inputs_lut, inputGVCFIdx, mergedIdx); }
102 template <bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M>::type* =
nullptr>
104 {
return get_lut_value(m_merged_2_inputs_lut, mergedIdx, inputGVCFIdx); }
115 template <bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<M>::type* =
nullptr>
117 {
return get_lut_value(m_inputs_2_merged_lut, inputGVCFIdx, inputIdx); }
118 template <bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M>::type* =
nullptr>
120 {
return get_lut_value(m_inputs_2_merged_lut, inputIdx, inputGVCFIdx); }
157 template <bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<M>::type* =
nullptr>
159 { resize_and_reset_lut(m_inputs_2_merged_lut, numInputGVCFs, numMergedFields, m_num_input_vcfs, m_num_merged_fields); }
161 template <bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M>::type* =
nullptr>
163 { resize_and_reset_lut(m_inputs_2_merged_lut, numMergedFields, numInputGVCFs, m_num_merged_fields, m_num_input_vcfs); }
165 template <bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<M>::type* =
nullptr>
167 { resize_and_reset_lut(m_merged_2_inputs_lut, numInputGVCFs, numMergedFields, m_num_input_vcfs, m_num_merged_fields); }
169 template <bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M>::type* =
nullptr>
171 { resize_and_reset_lut(m_merged_2_inputs_lut, numMergedFields, numInputGVCFs, m_num_merged_fields, m_num_input_vcfs); }
183 std::vector<std::vector<int>> m_inputs_2_merged_lut;
184 std::vector<std::vector<int>> m_merged_2_inputs_lut;
191 void reset_vector(std::vector<int>& vec,
unsigned from=0u);
196 void resize_and_reset_vector(std::vector<int>& vec,
unsigned new_size);
201 void resize_and_reset_lut(std::vector<std::vector<int>>& lut,
unsigned new_lut_size,
unsigned new_size,
unsigned& numRowsVar,
unsigned& numColsVar);
211 inline int get_lut_value(
const std::vector<std::vector<int>>& lut,
int rowIdx,
int columnIdx)
const
214 assert(rowIdx < static_cast<int>(lut.size()));
215 assert(columnIdx >= 0);
216 assert(columnIdx < static_cast<int>(lut[rowIdx].size()));
217 return lut[rowIdx][columnIdx];
228 inline void set_lut_value(std::vector<std::vector<int>>& lut,
int rowIdx,
int columnIdx,
int value)
231 assert(rowIdx < static_cast<int>(lut.size()));
232 assert(columnIdx >= 0);
233 assert(columnIdx < static_cast<int>(lut[rowIdx].size()));
234 lut[rowIdx][columnIdx] = value;
244 template <bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<M>::type* =
nullptr>
245 inline void set_merged_idx_for_input(
unsigned inputGVCFIdx,
int inputIdx,
int mergedIdx)
246 { set_lut_value(m_inputs_2_merged_lut, inputGVCFIdx, inputIdx, mergedIdx); }
248 template <bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M>::type* =
nullptr>
249 inline void set_merged_idx_for_input(
unsigned inputGVCFIdx,
int inputIdx,
int mergedIdx)
250 { set_lut_value(m_inputs_2_merged_lut, inputIdx, inputGVCFIdx, mergedIdx); }
259 template <bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<M>::type* =
nullptr>
260 inline void set_input_idx_for_merged(
unsigned inputGVCFIdx,
int inputIdx,
int mergedIdx)
261 { set_lut_value(m_merged_2_inputs_lut, inputGVCFIdx, mergedIdx, inputIdx); }
263 template <bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M>::type* =
nullptr>
264 inline void set_input_idx_for_merged(
unsigned inputGVCFIdx,
int inputIdx,
int mergedIdx)
265 { set_lut_value(m_merged_2_inputs_lut, mergedIdx, inputGVCFIdx, inputIdx); }
274 template<
bool inputs_2_merged_LUT_is_input_ordered,
bool merged_2_inputs_LUT_is_input_ordered>
276 :
public MergedVCFLUTBase<inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered>
279 static const auto m_DEFAULT_INIT_NUM_ALLELES=10u;
282 :
MergedVCFLUTBase<inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered>(numInputGVCFs,
283 m_DEFAULT_INIT_NUM_ALLELES)
284 { m_max_num_alleles = m_DEFAULT_INIT_NUM_ALLELES; }
287 if(numMergedAlleles > m_max_num_alleles)
291 m_max_num_alleles = numMergedAlleles;
295 unsigned m_max_num_alleles;
Base class to store look up information between fields of merged header and input headers...
Definition: merged_vcf_lut.h:59
void reset_input_idx_for_merged(unsigned inputGVCFIdx, int mergedIdx)
reset/invalidate the input field index for input VCF inputGVCFIdx for merged field mergedIdx ...
Definition: merged_vcf_lut.h:134
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
MergedVCFAllelesIdxLUT(unsigned numInputGVCFs)
Definition: merged_vcf_lut.h:281
void resize_inputs_2_merged_lut_if_needed(unsigned numInputGVCFs, unsigned numMergedFields)
resize LUT functions
Definition: merged_vcf_lut.h:158
void add_input_merged_idx_pair(unsigned inputGVCFIdx, int inputIdx, int mergedIdx)
Definition: merged_vcf_lut.h:84
void clear()
deallocates memory
Definition: merged_vcf_lut.cpp:27
MergedVCFLUTBase()
Definition: merged_vcf_lut.cpp:9
void resize_luts_if_needed(unsigned numInputGVCFs, unsigned numMergedFields)
Definition: merged_vcf_lut.h:176
constexpr auto int32
missing value for an int32
Definition: missing.h:18
void reset_merged_idx_for_input(unsigned inputGVCFIdx, int inputIdx)
reset/invalidate merged field index for field inputIdx of input VCF inputGVCFIdx
Definition: merged_vcf_lut.h:127
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
unsigned m_num_merged_fields
Definition: merged_vcf_lut.h:148
void resize_merged_2_inputs_lut_if_needed(unsigned numInputGVCFs, unsigned numMergedFields)
Definition: merged_vcf_lut.h:166
unsigned m_num_input_vcfs
Definition: merged_vcf_lut.h:147
~MergedVCFLUTBase()=default
LUT class for storing mappings between allele vectors in the merged file and input VCF files Since th...
Definition: merged_vcf_lut.h:275
void resize_luts_if_needed(unsigned numMergedAlleles)
Definition: merged_vcf_lut.h:285