|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_POPULATION_FUNCTION_DIVERSITY_POOL_CALCULATOR_H_
2 #define GENESIS_POPULATION_FUNCTION_DIVERSITY_POOL_CALCULATOR_H_
47 #include <type_traits>
52 namespace population {
142 double theta_pi = std::numeric_limits<double>::quiet_NaN();
144 double tajima_d = std::numeric_limits<double>::quiet_NaN();
152 : settings_( settings )
153 , pool_size_( pool_size )
156 throw std::invalid_argument(
157 "In DiversityPoolCalculator, settings.min_count == 0 is not allowed."
160 if( pool_size == 0 ) {
161 throw std::invalid_argument(
162 "In DiversityPoolCalculator, pool_size == 0 is not allowed."
182 only_passing_samples_ = value;
188 return only_passing_samples_;
193 enable_theta_pi_ = value;
199 return enable_theta_pi_;
204 enable_theta_watterson_ = value;
210 return enable_theta_watterson_;
215 enable_tajima_d_ = value;
221 return enable_tajima_d_;
230 theta_pi_sum_.
reset();
231 theta_watterson_sum_.
reset();
232 filter_stats_.
clear();
233 empirical_min_read_depth_ = std::numeric_limits<size_t>::max();
257 double tp = std::numeric_limits<double>::quiet_NaN();
258 double tw = std::numeric_limits<double>::quiet_NaN();
259 if( enable_theta_pi_ || enable_tajima_d_ ) {
261 if( std::isfinite( tp )) {
266 if( enable_theta_watterson_ || enable_tajima_d_ ) {
268 if( std::isfinite( tw )) {
269 theta_watterson_sum_ += tw;
278 if( cov > 0 && cov < empirical_min_read_depth_ ) {
279 empirical_min_read_depth_ = cov;
294 if( enable_theta_pi_ ) {
295 result.
theta_pi = theta_pi_sum_.
get() / window_avg_denom;
297 if( enable_theta_watterson_ ) {
300 if( enable_tajima_d_ ) {
317 theta_pi_sum_.
get(), theta_watterson_sum_.
get(),
318 pool_size_, tajimas_window_avg_denom, empirical_min_read_depth_
332 return filter_stats_;
343 size_t pool_size_ = 0;
345 bool only_passing_samples_ =
true;
346 bool enable_theta_pi_ =
true;
347 bool enable_theta_watterson_ =
true;
348 bool enable_tajima_d_ =
true;
356 size_t empirical_min_read_depth_ = std::numeric_limits<size_t>::max();
362 #endif // include guard
bool only_passing_samples() const
void process(SampleCounts const &sample)
Process a sample, by computing its Theta Pi and Theta Watterson values, respectively.
Compensated summation algorithmm, such as Kahan, Neumaier, and Klein summation.
One set of nucleotide sample counts, for example for a given sample that represents a pool of sequenc...
Result get_result(double window_avg_denom) const
Convenience function to obtain all results at once.
constexpr size_t nucleotide_sum(SampleCounts const &sample)
Count of the pure nucleotide bases at this position, that is, the sum of all A, C,...
FilterStatus status
Status to indicate whether any applied filters failed to pass.
self_type & only_passing_samples(bool value)
self_type & enable_theta_pi(bool value)
Data struct to collect all diversity statistics computed here.
bool enable_theta_watterson() const
@ kPassed
Sample has passed all filters.
SampleCountsFilterStats get_filter_stats() const
Get the sum of filter statistics of all sample pairs processed here.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
DiversityPoolCalculator & operator=(DiversityPoolCalculator const &)=default
bool enable_tajima_d() const
bool enable_theta_pi() const
double theta_pi_pool(DiversityPoolSettings const &settings, size_t poolsize, ForwardIterator begin, ForwardIterator end, bool only_passing_samples=true)
Compute theta pi with pool-sequencing correction according to Kofler et al, that is,...
~DiversityPoolCalculator()=default
self_type & enable_tajima_d(bool value)
self_type & enable_theta_watterson(bool value)
double theta_watterson_pool(DiversityPoolSettings const &settings, size_t poolsize, ForwardIterator begin, ForwardIterator end, bool only_passing_samples=true)
Compute theta watterson with pool-sequencing correction according to Kofler et al.
DiversityPoolCalculator(DiversityPoolSettings const &settings, size_t pool_size)
Compute Theta Pi, Theta Watterson, and Tajia's D in their pool-sequencing corrected versions accordin...
Settings used by different pool-sequencing corrected diversity statistics.
double tajima_d_pool(DiversityPoolSettings const &settings, double theta_pi, double theta_watterson, size_t poolsize, double window_avg_denom, size_t empirical_min_read_depth)
Compute the pool-sequencing corrected version of Tajima's D according to Kofler et al.