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::IndividualFieldValue< VALUE_TYPE > Class Template Reference

A class template to hold the values a format field for a particular sample. More...

#include <individual_field_value.h>

Public Member Functions

 IndividualFieldValue (const std::shared_ptr< bcf1_t > &body, const bcf_fmt_t *const format_ptr, uint8_t *const data_ptr)
 creates a new IndividualFieldValue poiinting to the shared byte array inside the variant object More...
 
 IndividualFieldValue (const IndividualFieldValue &other)=delete
 copying of the IndividualFieldValue object is not allowed. More...
 
 IndividualFieldValue (IndividualFieldValue &&other)
 safely moves the data from one IndividualFieldValue to a new one without making any copies More...
 
IndividualFieldValueoperator= (const IndividualFieldValue &other)=delete
 
IndividualFieldValueoperator= (IndividualFieldValue &&other)
 safely moves the data from one IndividualField to the other without making any copies More...
 
bool operator== (const IndividualFieldValue &other) const
 compares two IndividualFieldValue objects in the following order: memory address, size and values. More...
 
bool operator!= (const IndividualFieldValue &other) const
 compares two IndividualFieldValue objects in the following order: memory address, size and values. More...
 
VALUE_TYPE operator[] (const uint32_t index) const
 random access to the value of a given sample for reading or writing More...
 
IndividualFieldValueIterator
< VALUE_TYPE > 
begin () const
 create a new begin iterator over the values for this sample More...
 
IndividualFieldValueIterator
< VALUE_TYPE > 
end () const
 create a new end iterator over the values for this sample More...
 
uint32_t size () const
 the number of values in this IndividualFieldValue (values per sample) More...
 
VALUE_TYPE front () const
 convenience function to access the first element More...
 
VALUE_TYPE back () const
 convenience function to access the last element More...
 
bool missing () const
 returns true if all of the values are missing More...
 
template<>
std::string operator[] (const uint32_t index) const
 

Detailed Description

template<class VALUE_TYPE>
class gamgee::IndividualFieldValue< VALUE_TYPE >

A class template to hold the values a format field for a particular sample.

The role of this class is to perform the pointer manipulations behind the scenes that permit the user to navigate the values of a field in a sample without making any copies and benefiting from data locality (all the data is stored contiguously in memory).

A typical use of the IndividualFieldValue can be exemplified by the phred likelihood accessor in Variant:

const auto all_pls = record.integer_individual_field("PL");
const auto my_pls = all_pls[2] // take the second sample
for_each(my_pls.begin(), my_pls.end(), [](const auto pl) { cout << pl << endl; });

IndividualFieldValue objects can also be used in for loops like so:

for (const auto pl : my_pls)
cout << pl << endl;

While the IndividualFieldValue objects are not really intended to be created by the user, they are the returned by the IndividualField iterator for types that don't have a specialized object. Utilizing them correctly can really simplify your work by leveraging the power of the STL functions.

Note
all methods are inlined on purpose because they are so simple
Template Parameters
TYPEthe object type that holds the values for each sample. For example for GQ it's a uint8_t, some types like GT can have specialized classes like Genotype. For all other types it can be the IndividualFieldValue.

Constructor & Destructor Documentation

template<class VALUE_TYPE >
gamgee::IndividualFieldValue< VALUE_TYPE >::IndividualFieldValue ( const std::shared_ptr< bcf1_t > &  body,
const bcf_fmt_t *const  format_ptr,
uint8_t *const  data_ptr 
)
inline

creates a new IndividualFieldValue poiinting to the shared byte array inside the variant object

Parameters
bodythe full Variant object where all the values of the field are stored (shared ownership)
format_ptra structure with a pointer to the location in the raw byte array (m_body->indiv) where the format field starts and information about the values (size, type, number,...)
Note
this implementation doesn't make any copies, simply manages the access to the raw byte array in Variant giving iterator interfaces to the users
Parameters
bodythe the bcf1_t structure to hold a shared pointer to
format_ptrthe format field pointer inside the body
data_ptrthe location in the specific value inside the format_ptr byte array
template<class VALUE_TYPE >
gamgee::IndividualFieldValue< VALUE_TYPE >::IndividualFieldValue ( const IndividualFieldValue< VALUE_TYPE > &  other)
delete

copying of the IndividualFieldValue object is not allowed.

template<class VALUE_TYPE >
gamgee::IndividualFieldValue< VALUE_TYPE >::IndividualFieldValue ( IndividualFieldValue< VALUE_TYPE > &&  other)
inline

safely moves the data from one IndividualFieldValue to a new one without making any copies

Parameters
otheranother IndividualFieldValue object

Member Function Documentation

template<class VALUE_TYPE >
VALUE_TYPE gamgee::IndividualFieldValue< VALUE_TYPE >::back ( ) const
inline

convenience function to access the last element

template<class VALUE_TYPE >
IndividualFieldValueIterator<VALUE_TYPE> gamgee::IndividualFieldValue< VALUE_TYPE >::begin ( ) const
inline

create a new begin iterator over the values for this sample

template<class VALUE_TYPE >
IndividualFieldValueIterator<VALUE_TYPE> gamgee::IndividualFieldValue< VALUE_TYPE >::end ( ) const
inline

create a new end iterator over the values for this sample

template<class VALUE_TYPE >
VALUE_TYPE gamgee::IndividualFieldValue< VALUE_TYPE >::front ( ) const
inline

convenience function to access the first element

template<class VALUE_TYPE >
bool gamgee::IndividualFieldValue< VALUE_TYPE >::missing ( ) const
inline

returns true if all of the values are missing

template<class VALUE_TYPE >
bool gamgee::IndividualFieldValue< VALUE_TYPE >::operator!= ( const IndividualFieldValue< VALUE_TYPE > &  other) const
inline

compares two IndividualFieldValue objects in the following order: memory address, size and values.

Parameters
othersomething to compare to
Returns
true if the objects are not the same (memory address-wise), or contain different number of values, or the values are not exactly the same. Value comparison is dictated by TYPE's operator== implementation
template<class VALUE_TYPE >
IndividualFieldValue& gamgee::IndividualFieldValue< VALUE_TYPE >::operator= ( const IndividualFieldValue< VALUE_TYPE > &  other)
delete

template<class VALUE_TYPE >
IndividualFieldValue& gamgee::IndividualFieldValue< VALUE_TYPE >::operator= ( IndividualFieldValue< VALUE_TYPE > &&  other)
inline

safely moves the data from one IndividualField to the other without making any copies

Parameters
otheranother IndividualFieldValue object
template<class VALUE_TYPE >
bool gamgee::IndividualFieldValue< VALUE_TYPE >::operator== ( const IndividualFieldValue< VALUE_TYPE > &  other) const
inline

compares two IndividualFieldValue objects in the following order: memory address, size and values.

Parameters
othersomething to compare to
Returns
true if the objects are the same (memory address-wise), or contain exactly the same values. Value comparison is dictated by TYPE's operator== implementation
template<class VALUE_TYPE >
VALUE_TYPE gamgee::IndividualFieldValue< VALUE_TYPE >::operator[] ( const uint32_t  index) const
inline

random access to the value of a given sample for reading or writing

Parameters
indexmust be between 0 and the number of values per sample for this record
Note
implementation guarantees this operation to be O(1)
Exceptions
std::out_of_rangeif sample is out of range
Returns
the value in that index
template<>
std::string gamgee::IndividualFieldValue< std::string >::operator[] ( const uint32_t  index) const
inline
template<class VALUE_TYPE >
uint32_t gamgee::IndividualFieldValue< VALUE_TYPE >::size ( ) const
inline

the number of values in this IndividualFieldValue (values per sample)


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