A library for working with phylogenetic and population genetic data.
v0.32.0
FstPoolProcessor Class Reference

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

Detailed Description

Helper class to iterate over Variants and process pairs of FST between their samples (SampleCounts), using a set of BaseFstPoolCalculator.

Definition at line 67 of file fst_pool_processor.hpp.

Public Member Functions

 FstPoolProcessor (FstPoolProcessor &&)=default
 
 FstPoolProcessor (FstPoolProcessor const &)=default
 
 FstPoolProcessor (std::shared_ptr< utils::ThreadPool > thread_pool=nullptr, size_t threading_threshold=4096)
 Construct a processor. More...
 
 ~FstPoolProcessor ()=default
 
void add_calculator (size_t index_p1, size_t index_p2, std::unique_ptr< BaseFstPoolCalculator > calculator)
 Add a calculator, that is, an instance to compute FST for a pair of samples. More...
 
std::vector< std::unique_ptr< BaseFstPoolCalculator > > const & calculators () const
 
VariantFilterStats get_filter_stats () const
 Get the sum of filter statistics of all Variants processed here. More...
 
PiVectorTuple const & get_pi_vectors () const
 Get lists of all the three intermediate pi values (within, between, total) that are part of our unbiased estimators. More...
 
template<class D >
PiVectorTuple const & get_pi_vectors (BaseWindow< D > const &window, std::shared_ptr< GenomeLocusSet > provided_loci) const
 Get lists of all the three intermediate pi values (within, between, total) that are part of our unbiased estimators. More...
 
std::vector< double > const & get_result () const
 Get a list of all resulting FST values for all pairs of samples. More...
 
template<class D >
std::vector< double > const & get_result (BaseWindow< D > const &window, std::shared_ptr< GenomeLocusSet > provided_loci) const
 Get a list of all resulting FST values for all pairs of samples. More...
 
FstPoolProcessoroperator= (FstPoolProcessor &&)=default
 
FstPoolProcessoroperator= (FstPoolProcessor const &)=default
 
void process (Variant const &variant)
 
void reset ()
 
std::vector< std::pair< size_t, size_t > > const & sample_pairs () const
 
size_t size () const
 Get the total number of calculates, i.e., the number of pairs of samples for which we comute FST here. More...
 
std::shared_ptr< utils::ThreadPoolthread_pool () const
 Get the thread pool used for processing, if enough sample pairs are being processed. More...
 
FstPoolProcessorthread_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
 
FstPoolProcessorthreading_threshold (size_t value)
 Set the threshold of calculators after which the processing is done in threads. More...
 

Public Types

using PiVectorTuple = std::tuple< std::vector< double >, std::vector< double >, std::vector< double > >
 

Constructor & Destructor Documentation

◆ FstPoolProcessor() [1/3]

FstPoolProcessor ( 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.

Definition at line 88 of file fst_pool_processor.hpp.

◆ ~FstPoolProcessor()

~FstPoolProcessor ( )
default

◆ FstPoolProcessor() [2/3]

FstPoolProcessor ( FstPoolProcessor const &  )
default

◆ FstPoolProcessor() [3/3]

Member Function Documentation

◆ add_calculator()

void add_calculator ( size_t  index_p1,
size_t  index_p2,
std::unique_ptr< BaseFstPoolCalculator calculator 
)
inline

Add a calculator, that is, an instance to compute FST for a pair of samples.

Definition at line 153 of file fst_pool_processor.hpp.

◆ calculators()

std::vector<std::unique_ptr<BaseFstPoolCalculator> > const& calculators ( ) const
inline

Definition at line 391 of file fst_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 381 of file fst_pool_processor.hpp.

◆ get_pi_vectors() [1/2]

PiVectorTuple const& get_pi_vectors ( ) const
inline

Get lists of all the three intermediate pi values (within, between, total) that are part of our unbiased estimators.

This overload ignores the window average policy, and just returns the sum.

Definition at line 352 of file fst_pool_processor.hpp.

◆ get_pi_vectors() [2/2]

PiVectorTuple const& get_pi_vectors ( BaseWindow< D > const &  window,
std::shared_ptr< GenomeLocusSet provided_loci 
) const
inline

Get lists of all the three intermediate pi values (within, between, total) that are part of our unbiased estimators.

This computes the window-average-corrected values for pi within, pi between, and pi total (in that order in the tuple), for each sample pair (order in the three vectors). This uses the same window averaging policy as the get_result() function.

This only works when all calculators are of type FstPoolCalculatorUnbiased, and throws an exception otherwise. It is merely meant as a convenience function for that particular case.

Definition at line 317 of file fst_pool_processor.hpp.

◆ get_result() [1/2]

std::vector<double> const& get_result ( ) const
inline

Get a list of all resulting FST values for all pairs of samples.

This overload does not use window averaging, and always returns the sum.

Definition at line 294 of file fst_pool_processor.hpp.

◆ get_result() [2/2]

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

Get a list of all resulting FST values for all pairs of samples.

This always takes the window and provided_loci as input, which are components needed for some of the window averaging policies, 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. There is an overload of this function which does not need this, and always returns the sum.

Definition at line 266 of file fst_pool_processor.hpp.

◆ operator=() [1/2]

FstPoolProcessor& operator= ( FstPoolProcessor &&  )
default

◆ operator=() [2/2]

FstPoolProcessor& operator= ( FstPoolProcessor const &  )
default

◆ process()

void process ( Variant const &  variant)
inline

Definition at line 213 of file fst_pool_processor.hpp.

◆ reset()

void reset ( )
inline

Definition at line 179 of file fst_pool_processor.hpp.

◆ sample_pairs()

std::vector<std::pair<size_t, size_t> > const& sample_pairs ( ) const
inline

Definition at line 386 of file fst_pool_processor.hpp.

◆ size()

size_t size ( ) const
inline

Get the total number of calculates, i.e., the number of pairs of samples for which we comute FST here.

Definition at line 172 of file fst_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 113 of file fst_pool_processor.hpp.

◆ thread_pool() [2/2]

FstPoolProcessor& 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 124 of file fst_pool_processor.hpp.

◆ threading_threshold() [1/2]

size_t threading_threshold ( ) const
inline

Definition at line 130 of file fst_pool_processor.hpp.

◆ threading_threshold() [2/2]

FstPoolProcessor& 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 144 of file fst_pool_processor.hpp.

Member Typedef Documentation

◆ PiVectorTuple

using PiVectorTuple = std::tuple<std::vector<double>, std::vector<double>, std::vector<double> >

Definition at line 75 of file fst_pool_processor.hpp.


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