A library for working with phylogenetic and population genetic data.
v0.32.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DiversityPoolProcessor Class Reference

#include <genesis/population/function/diversity_pool_processor.hpp>

Detailed Description

Helper class to iterate over Variants and process the samples (SampleCounts), using a set of DiversityPoolCalculator instances, one for each sample.

This mainly serves as a convenience tools that takes care of iterating the samples, and also offers parallelization for larger datasets.

Definition at line 67 of file diversity_pool_processor.hpp.

Public Member Functions

 DiversityPoolProcessor ()=default
 Default constructor. More...
 
 DiversityPoolProcessor (DiversityPoolProcessor &&)=default
 
 DiversityPoolProcessor (DiversityPoolProcessor const &)=default
 
 DiversityPoolProcessor (WindowAveragePolicy window_average_policy, std::shared_ptr< utils::ThreadPool > thread_pool=nullptr, size_t threading_threshold=4096)
 Construct a processor. More...
 
 ~DiversityPoolProcessor ()=default
 
void add_calculators (DiversityPoolSettings const &settings, std::vector< size_t > const &pool_sizes)
 Create and add a set of calculators for a given list of samples. More...
 
std::vector< DiversityPoolCalculator >::iterator begin ()
 
std::vector< DiversityPoolCalculator > const & calculators () const
 
std::vector< DiversityPoolCalculator >::iterator end ()
 
VariantFilterStats get_filter_stats () const
 Get the sum of filter statistics of all Variants processed here. More...
 
std::vector< DiversityPoolCalculator::Result > const & get_result () const
 Get a list of all resulting values for all samples. More...
 
template<class D >
std::vector< DiversityPoolCalculator::Result > const & get_result (BaseWindow< D > const &window, std::shared_ptr< GenomeLocusSet > provided_loci) const
 Get a list of all resulting values for all samples. More...
 
DiversityPoolProcessoroperator= (DiversityPoolProcessor &&)=default
 
DiversityPoolProcessoroperator= (DiversityPoolProcessor const &)=default
 
void process (Variant const &variant)
 
void reset ()
 
size_t size () const
 
std::shared_ptr< utils::ThreadPoolthread_pool () const
 Get the thread pool used for processing, if enough sample pairs are being processed. More...
 
DiversityPoolProcessorthread_pool (std::shared_ptr< utils::ThreadPool > value)
 Set the thread pool used for processing, if enough sample pairs are being processed. More...
 
size_t threading_threshold () const
 
DiversityPoolProcessorthreading_threshold (size_t value)
 Set the threshold of calculators after which the processing is done in threads. More...
 

Constructor & Destructor Documentation

◆ DiversityPoolProcessor() [1/4]

Default constructor.

We always want to make sure that the user provides a WindowAveragePolicy, so using this default constructor leads to an unusable instance. We provide it so that dummy processors can be constructed, but they have to be replaced by non-default-constructed instances befor usage.

◆ DiversityPoolProcessor() [2/4]

DiversityPoolProcessor ( WindowAveragePolicy  window_average_policy,
std::shared_ptr< utils::ThreadPool thread_pool = nullptr,
size_t  threading_threshold = 4096 
)
inline

Construct a processor.

This defaults to using the global thread pool of Options::get().global_thread_pool() If this is not desired, either pass a different thread_pool here, or, if no thread pool is to be used, deactivate by explicitly setting the thread_pool() function here to nullptr after construction.

Definition at line 93 of file diversity_pool_processor.hpp.

◆ ~DiversityPoolProcessor()

~DiversityPoolProcessor ( )
default

◆ DiversityPoolProcessor() [3/4]

◆ DiversityPoolProcessor() [4/4]

Member Function Documentation

◆ add_calculators()

void add_calculators ( DiversityPoolSettings const &  settings,
std::vector< size_t > const &  pool_sizes 
)
inline

Create and add a set of calculators for a given list of samples.

The function takes the settings, as well as a list of pool sizes, which are forwarded to a DiversityPoolCalculator each. We expect that the number of elements in pool_sizes is the number of samples expected when calling process() later.

Definition at line 165 of file diversity_pool_processor.hpp.

◆ begin()

std::vector<DiversityPoolCalculator>::iterator begin ( )
inline

Definition at line 302 of file diversity_pool_processor.hpp.

◆ calculators()

std::vector<DiversityPoolCalculator> const& calculators ( ) const
inline

Definition at line 293 of file diversity_pool_processor.hpp.

◆ end()

std::vector<DiversityPoolCalculator>::iterator end ( )
inline

Definition at line 307 of file diversity_pool_processor.hpp.

◆ get_filter_stats()

VariantFilterStats get_filter_stats ( ) const
inline

Get the sum of filter statistics of all Variants processed here.

With each call to process(), the filter stats are increased according to the filter status of the provided Variant. Here, we offer to read out the total of all filter tags that occurred in these Variants.

Definition at line 288 of file diversity_pool_processor.hpp.

◆ get_result() [1/2]

std::vector<DiversityPoolCalculator::Result> const& get_result ( ) const
inline

Get a list of all resulting values for all samples.

This overload does not consider the window averaging, and simply returns the sum of all per site values.

Definition at line 272 of file diversity_pool_processor.hpp.

◆ get_result() [2/2]

std::vector<DiversityPoolCalculator::Result> const& get_result ( BaseWindow< D > const &  window,
std::shared_ptr< GenomeLocusSet provided_loci 
) const
inline

Get a list of all resulting values for all samples.

This always takes the window and provided_loci as input, even if the WindowAveragePolicy does not require it. This is meant to make sure that we at least keep track of the right things when doing any computations, and cannot forget about this. For cases where the result is needed without averaging over windows (that is, just the sum of all per site values), there is an overload of this function.

Definition at line 252 of file diversity_pool_processor.hpp.

◆ operator=() [1/2]

DiversityPoolProcessor& operator= ( DiversityPoolProcessor &&  )
default

◆ operator=() [2/2]

DiversityPoolProcessor& operator= ( DiversityPoolProcessor const &  )
default

◆ process()

void process ( Variant const &  variant)
inline

Definition at line 199 of file diversity_pool_processor.hpp.

◆ reset()

void reset ( )
inline

Definition at line 189 of file diversity_pool_processor.hpp.

◆ size()

size_t size ( ) const
inline

Definition at line 184 of file diversity_pool_processor.hpp.

◆ thread_pool() [1/2]

std::shared_ptr<utils::ThreadPool> thread_pool ( ) const
inline

Get the thread pool used for processing, if enough sample pairs are being processed.

Definition at line 121 of file diversity_pool_processor.hpp.

◆ thread_pool() [2/2]

DiversityPoolProcessor& thread_pool ( std::shared_ptr< utils::ThreadPool value)
inline

Set the thread pool used for processing, if enough sample pairs are being processed.

See threading_threshold() for details on when we use the thread pool. Shall not be changed after calling process().

Definition at line 132 of file diversity_pool_processor.hpp.

◆ threading_threshold() [1/2]

size_t threading_threshold ( ) const
inline

Definition at line 138 of file diversity_pool_processor.hpp.

◆ threading_threshold() [2/2]

DiversityPoolProcessor& threading_threshold ( size_t  value)
inline

Set the threshold of calculators after which the processing is done in threads.

For small numbers of processors (small number of sample pairs), starting threads for each call of process() is more expensive than just doing the computation directly in the main thread. Hence, we only want to use the thread pool if the overhead is justified.

With this setting the number of sample pairs can be set after which we use the thread pool.

Definition at line 152 of file diversity_pool_processor.hpp.


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