Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered > Class Template Reference

Base class to store look up information between fields of merged header and input headers. More...

#include <merged_vcf_lut.h>

Inheritance diagram for gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >:
gamgee::utils::MergedVCFAllelesIdxLUT< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >

Public Member Functions

void reset_luts ()
 : clear all mappings More...
 
void add_input_merged_idx_pair (unsigned inputGVCFIdx, int inputIdx, int mergedIdx)
 
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
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. More...
 
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
int get_input_idx_for_merged (unsigned inputGVCFIdx, int mergedIdx) const
 
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
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 inputGVCFIdx. More...
 
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
int get_merged_idx_for_input (unsigned inputGVCFIdx, int inputIdx) const
 
void reset_merged_idx_for_input (unsigned inputGVCFIdx, int inputIdx)
 reset/invalidate merged field index for field inputIdx of input VCF inputGVCFIdx More...
 
void reset_input_idx_for_merged (unsigned inputGVCFIdx, int mergedIdx)
 reset/invalidate the input field index for input VCF inputGVCFIdx for merged field mergedIdx More...
 

Protected Member Functions

 MergedVCFLUTBase ()
 
 MergedVCFLUTBase (unsigned numInputGVCFs, unsigned numMergedFields)
 
 ~MergedVCFLUTBase ()=default
 
void clear ()
 deallocates memory More...
 
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
void resize_inputs_2_merged_lut_if_needed (unsigned numInputGVCFs, unsigned numMergedFields)
 resize LUT functions More...
 
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
void resize_inputs_2_merged_lut_if_needed (unsigned numInputGVCFs, unsigned numMergedFields)
 
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
void resize_merged_2_inputs_lut_if_needed (unsigned numInputGVCFs, unsigned numMergedFields)
 
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
void resize_merged_2_inputs_lut_if_needed (unsigned numInputGVCFs, unsigned numMergedFields)
 
void resize_luts_if_needed (unsigned numInputGVCFs, unsigned numMergedFields)
 

Protected Attributes

unsigned m_num_input_vcfs
 
unsigned m_num_merged_fields
 

Friends

template<bool fields_forward_LUT_ordering, bool fields_reverse_LUT_ordering, bool samples_forward_LUT_ordering, bool samples_reverse_LUT_ordering>
class gamgee::VariantHeaderMerger
 

Detailed Description

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
class gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >

Base class to store look up information between fields of merged header and input headers.

LUT = Look Up Table (to avoid confusion with map, unordered_map etc)

Note
This is the helper class for VariantHeaderMerger to store mapping for fields and samples Each MergedVCFLUTBase object contains 2 matrices (vector of vector): one for mapping input field idx to merged field idx (m_inputs_2_merged_lut) and the second for mapping merged field idx to input field idx (m_merged_2_inputs_lut).

Missing field information is stored as bcf_int32_missing, but should be checked with gamgee::missing() function

The boolean template parameters specify how the 2 tables are laid out in memory - whether the outer vector corresponds to fields or input vcfs. For example, in object of type MergedVCFLUTBase<true, true>, both LUTs are laid out such that m_inputs_2_merged_lut[0] contains mappings for all fields for input VCF file 0. This would lead to fast traversal of all fields for a given input VCF (cache locality). However, traversing over all input VCFs for a given field would be slow (many cache misses). The object MergedVCFLUTBase<false,false> would have the exact opposite behavior

The 'best' value of the template parameters depends on the application using the LUT. Almost all the 'complexity' of the code comes from being able to handle the different layouts in a transparent manner

Alternate explanation: This class contains two matrices (vector<vector<int>>) to store the mapping information: m_inputs_2_merged_lut and m_merged_2_inputs_lut. You can layout each matrix in one of the 2 following ways: (a) LUT[i][j] corresponds to input VCF i and field j (b) LUT[i][j] corresponds to field i and input VCF j Option (a) is optimal where you are looking at all the fields of a VCF in quick succession, while (b) is optimal when you are looking at all VCFs for a particular field. The 2 boolean template parameters control the layout of the two matrices. If the parameter value is true, then option (a) is picked, else option (b)

Although the class provides functions to resize the tables, for obtaining good performance, reallocations should be extremely infrequent. Making the resize_luts_if_needed() a protected member forces developers to think twice instead of blindly calling this function.

Uses the enable_if trick from http://en.cppreference.com/w/cpp/types/enable_if (foo3) to handle different memory layouts

Constructor & Destructor Documentation

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::MergedVCFLUTBase ( )
protected
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::MergedVCFLUTBase ( unsigned  numInputGVCFs,
unsigned  numMergedFields 
)
protected
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::~MergedVCFLUTBase ( )
protecteddefault

Member Function Documentation

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::add_input_merged_idx_pair ( unsigned  inputGVCFIdx,
int  inputIdx,
int  mergedIdx 
)
inline
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::clear ( )
protected

deallocates memory

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
int gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::get_input_idx_for_merged ( unsigned  inputGVCFIdx,
int  mergedIdx 
) const
inline

Get field idx for input VCF inputGVCFIdx corresponding to field idx mergedIdx in the mergedVCF file.

Note
Uses the enable_if trick from http://en.cppreference.com/w/cpp/types/enable_if (foo3) to handle different memory layouts The enable_if<M> corresponds to the case where merged_2_inputs_LUT_is_input_ordered = true, hence, the rows correspond to input VCFs The enable_if<!M> corresponds to the case where merged_2_inputs_LUT_is_input_ordered = false, hence, the rows correspond to fields
Parameters
inputGVCFIdxindex of the input VCF file
mergedIdxindex of the field in the merged VCF file
Returns
index of the field in the input VCF file
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
int gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::get_input_idx_for_merged ( unsigned  inputGVCFIdx,
int  mergedIdx 
) const
inline
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
int gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::get_merged_idx_for_input ( unsigned  inputGVCFIdx,
int  inputIdx 
) const
inline

Get field idx for the merged VCF corresponding to field idx inputIdx in the input VCF of index inputGVCFIdx.

Note
Uses the enable_if trick from http://en.cppreference.com/w/cpp/types/enable_if (foo3) to handle different memory layouts The enable_if<M> corresponds to the case where inputs_2_merged_LUT_is_input_ordered = true, hence, the rows correspond to input VCFs The enable_if<!M> corresponds to the case where inputs_2_merged_LUT_is_input_ordered = false, hence, the rows correspond to fields
Parameters
inputGVCFIdxindex of the input VCF file
inputIdxindex of the field in the input VCF file
Returns
index of the field in the merged VCF file
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
int gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::get_merged_idx_for_input ( unsigned  inputGVCFIdx,
int  inputIdx 
) const
inline
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::reset_input_idx_for_merged ( unsigned  inputGVCFIdx,
int  mergedIdx 
)
inline

reset/invalidate the input field index for input VCF inputGVCFIdx for merged field mergedIdx

Parameters
inputGVCFIdxindex of the input VCF file
mergedIdxindex of the field in the merged VCF file
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::reset_luts ( )
inline

: clear all mappings

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::reset_merged_idx_for_input ( unsigned  inputGVCFIdx,
int  inputIdx 
)
inline

reset/invalidate merged field index for field inputIdx of input VCF inputGVCFIdx

Parameters
inputGVCFIdxindex of the input VCF file
inputIdxindex of the field in the input VCF file
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::resize_inputs_2_merged_lut_if_needed ( unsigned  numInputGVCFs,
unsigned  numMergedFields 
)
inlineprotected

resize LUT functions

Note
should be called relatively infrequently (more precisely, the reallocation code inside these resize functions should be called infrequently
Parameters
numInputGVCFsnumber of input VCFs
numMergedFieldsnumber of fields combined across all input VCFs
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = inputs_2_merged_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::resize_inputs_2_merged_lut_if_needed ( unsigned  numInputGVCFs,
unsigned  numMergedFields 
)
inlineprotected
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::resize_luts_if_needed ( unsigned  numInputGVCFs,
unsigned  numMergedFields 
)
inlineprotected
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if< M >::type * = nullptr>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::resize_merged_2_inputs_lut_if_needed ( unsigned  numInputGVCFs,
unsigned  numMergedFields 
)
inlineprotected
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool M = merged_2_inputs_LUT_is_input_ordered, typename std::enable_if<!M >::type * = nullptr>
void gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::resize_merged_2_inputs_lut_if_needed ( unsigned  numInputGVCFs,
unsigned  numMergedFields 
)
inlineprotected

Friends And Related Function Documentation

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
template<bool fields_forward_LUT_ordering, bool fields_reverse_LUT_ordering, bool samples_forward_LUT_ordering, bool samples_reverse_LUT_ordering>
friend class gamgee::VariantHeaderMerger
friend

Member Data Documentation

template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
unsigned gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::m_num_input_vcfs
protected
template<bool inputs_2_merged_LUT_is_input_ordered, bool merged_2_inputs_LUT_is_input_ordered>
unsigned gamgee::utils::MergedVCFLUTBase< inputs_2_merged_LUT_is_input_ordered, merged_2_inputs_LUT_is_input_ordered >::m_num_merged_fields
protected

The documentation for this class was generated from the following files: