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 | List of all members
gamgee::VariantBuilderSharedRegion Class Reference

Helper class for VariantBuilder to manage the fields belonging to the shared region of Variant records. More...

#include <variant_builder_shared_region.h>

Public Member Functions

 VariantBuilderSharedRegion (const VariantHeader &header, const bool enable_validation)
 
 VariantBuilderSharedRegion (VariantBuilderSharedRegion &&other)=default
 
VariantBuilderSharedRegionoperator= (VariantBuilderSharedRegion &&other)=default
 
 VariantBuilderSharedRegion (const VariantBuilderSharedRegion &other)=delete
 
VariantBuilderSharedRegionoperator= (const VariantBuilderSharedRegion &other)=delete
 
 ~VariantBuilderSharedRegion ()
 
void set_enable_validation (const bool enable_validation)
 
uint32_t ref_allele_length () const
 
uint32_t num_alt_alleles () const
 
uint32_t num_present_info_fields () const
 
bool modified () const
 
void set_id (const std::string &id)
 
void set_ref_allele (const std::string &ref_allele)
 
void set_alt_allele (const std::string &alt_allele)
 
void set_alt_alleles (const std::vector< std::string > &alt_alleles)
 
void set_filters (const std::vector< std::string > &filters)
 
void set_filters (const std::vector< int32_t > &filters)
 
template<class FIELD_ID_TYPE , class FIELD_VALUE_TYPE >
void set_info_field (const FIELD_ID_TYPE &field_id, const FIELD_VALUE_TYPE &field_value, const int32_t provided_type, const uint32_t num_values)
 
void remove_id ()
 
void remove_alt_alleles ()
 
void remove_filters ()
 
template<class FIELD_ID_TYPE >
void remove_info_field (const FIELD_ID_TYPE &field_id)
 
uint32_t estimate_total_size () const
 Produce a slight overestimate of the number of bytes required to hold all encoded data for this shared region. More...
 
void encode_into (kstring_t *destination) const
 Copy all encoded data for all shared fields into the provided byte buffer in the proper order and format for final insertion into a Variant object. More...
 
void clear ()
 Reset the shared region to a pristine state with no field data. More...
 

Detailed Description

Helper class for VariantBuilder to manage the fields belonging to the shared region of Variant records.

The shared region includes the ID, reference allele, alt alleles, filters, and INFO fields. This class manages the validation, encoding, and storage of these fields.

STORAGE STRATEGY: This class pre-allocates a large block of C memory (m_shared_buffer). When we set a shared field we tell htslib to encode it directly into the end of this buffer, keeping track of the buffer span used by each field. htslib can resize the buffer if needed.

Old field values remain in the buffer as unused sections (garbage). If too much garbage accumulates we compact the buffer to restore locality, but in general if the user of VariantBuilder is calling clear() regularly this won't happen.

When we encode the final shared byte buffer, we traverse the used regions of m_shared_buffer to copy the encoded data for each field into the right place in the final buffer.

This approach to storage has the advantage of performing no allocations or de-allocations in normal use, and most of the time the encoded data for all fields will be adjacent in memory, albeit possibly out-of-order, allowing for very cache-efficient encode operations.

Constructor & Destructor Documentation

gamgee::VariantBuilderSharedRegion::VariantBuilderSharedRegion ( const VariantHeader header,
const bool  enable_validation 
)
explicit
gamgee::VariantBuilderSharedRegion::VariantBuilderSharedRegion ( VariantBuilderSharedRegion &&  other)
default
gamgee::VariantBuilderSharedRegion::VariantBuilderSharedRegion ( const VariantBuilderSharedRegion other)
delete
gamgee::VariantBuilderSharedRegion::~VariantBuilderSharedRegion ( )

Member Function Documentation

void gamgee::VariantBuilderSharedRegion::clear ( )

Reset the shared region to a pristine state with no field data.

void gamgee::VariantBuilderSharedRegion::encode_into ( kstring_t destination) const

Copy all encoded data for all shared fields into the provided byte buffer in the proper order and format for final insertion into a Variant object.

uint32_t gamgee::VariantBuilderSharedRegion::estimate_total_size ( ) const

Produce a slight overestimate of the number of bytes required to hold all encoded data for this shared region.

bool gamgee::VariantBuilderSharedRegion::modified ( ) const
inline
uint32_t gamgee::VariantBuilderSharedRegion::num_alt_alleles ( ) const
inline
uint32_t gamgee::VariantBuilderSharedRegion::num_present_info_fields ( ) const
inline
VariantBuilderSharedRegion& gamgee::VariantBuilderSharedRegion::operator= ( VariantBuilderSharedRegion &&  other)
default
VariantBuilderSharedRegion& gamgee::VariantBuilderSharedRegion::operator= ( const VariantBuilderSharedRegion other)
delete
uint32_t gamgee::VariantBuilderSharedRegion::ref_allele_length ( ) const
inline
void gamgee::VariantBuilderSharedRegion::remove_alt_alleles ( )
inline
void gamgee::VariantBuilderSharedRegion::remove_filters ( )
inline
void gamgee::VariantBuilderSharedRegion::remove_id ( )
inline
template<class FIELD_ID_TYPE >
void gamgee::VariantBuilderSharedRegion::remove_info_field ( const FIELD_ID_TYPE &  field_id)
inline
void gamgee::VariantBuilderSharedRegion::set_alt_allele ( const std::string &  alt_allele)
void gamgee::VariantBuilderSharedRegion::set_alt_alleles ( const std::vector< std::string > &  alt_alleles)
void gamgee::VariantBuilderSharedRegion::set_enable_validation ( const bool  enable_validation)
inline
void gamgee::VariantBuilderSharedRegion::set_filters ( const std::vector< std::string > &  filters)
void gamgee::VariantBuilderSharedRegion::set_filters ( const std::vector< int32_t > &  filters)
void gamgee::VariantBuilderSharedRegion::set_id ( const std::string &  id)
template<class FIELD_ID_TYPE , class FIELD_VALUE_TYPE >
void gamgee::VariantBuilderSharedRegion::set_info_field ( const FIELD_ID_TYPE &  field_id,
const FIELD_VALUE_TYPE &  field_value,
const int32_t  provided_type,
const uint32_t  num_values 
)
inline
void gamgee::VariantBuilderSharedRegion::set_ref_allele ( const std::string &  ref_allele)

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