FFPopSim  2.0
Library for Population Genetics
 All Classes Files Functions Variables Macros Pages
haploid_lowd Class Reference

Low-dimensional population evolving on the hypercube_lowd. More...

#include <ffpopsim_lowd.h>

Collaboration diagram for haploid_lowd:

Public Member Functions

 haploid_lowd (int L=1, int rng_seed=0)
 Default constructor. More...
 
virtual ~haploid_lowd ()
 Default destructor. More...
 
int L ()
 
int get_number_of_loci ()
 
double N ()
 
double get_population_size ()
 
double get_generation ()
 
void set_generation (double g)
 
double get_mutation_rate (int locus, int direction)
 
int get_recombination_model ()
 
double get_recombination_rate (int locus)
 Get the recombination rate between a locus and the next one. More...
 
int set_allele_frequencies (double *frequencies, unsigned long N)
 Initialize population in linkage equilibrium. More...
 
int set_genotypes (vector< index_value_pair_t > gt)
 Initialize the population with genotype counts. More...
 
int set_wildtype (unsigned long N)
 Initialize a wildtype population (00...0) More...
 
int set_recombination_model (int rec_model)
 Set a new recombination model. More...
 
int set_recombination_rates (double *rec_rates, int rec_model=-1)
 calculate recombination patterns More...
 
int set_mutation_rates (double m)
 Set a uniform mutation rate for all loci and both directions. More...
 
int set_mutation_rates (double m1, double m2)
 Set two mutation rates (forward / backward) for all loci. More...
 
int set_mutation_rates (double *m)
 Set mutation rates (locus specific, both directions the same) More...
 
int set_mutation_rates (double **m)
 Set mutation rates (locus and direction specific) More...
 
int evolve (int gen=1)
 Evolve the population for some generations. More...
 
int evolve_norec (int gen=1)
 Evolve the population for some generations, without recombination. More...
 
int evolve_deterministic (int gen=1)
 Evolve the population for some generations, without resampling (deterministic) More...
 
double get_genotype_frequency (int genotype)
 
double get_allele_frequency (int locus)
 
double get_pair_frequency (int locus1, int locus2)
 
double get_chi (int locus)
 
double get_chi2 (int locus1, int locus2)
 
double get_LD (int locus1, int locus2)
 
double get_moment (int locus1, int locus2)
 
double genotype_entropy ()
 Get the genotype entropy. More...
 
double allele_entropy ()
 Get the allele entropy. More...
 
double get_fitness (int genotype)
 
stat_t get_fitness_statistics ()
 Get fitness mean and variance in the population. More...
 

Public Attributes

hypercube_lowd fitness
 
hypercube_lowd population
 
double carrying_capacity
 
double outcrossing_rate
 
bool circular
 

Protected Member Functions

int get_random_seed ()
 Get a random seed from /dev/urandom. More...
 
int select ()
 Selection step. More...
 
int mutate ()
 Mutation step. More...
 
int recombine ()
 Recombination step. More...
 
int resample ()
 Resample the population according to the carrying capacity. More...
 
int set_recombination_rates_general (double *rec_rates)
 Set the recombination rates for the general model. More...
 
int set_recombination_patterns (vector< index_value_pair_t > iv)
 set recombination patterns with a list of index value pairs More...
 
int marginalize_recombination_patterns ()
 Starting from a fully specified set of probabilities of recombination patterns, compute all sub patterns. More...
 
int set_recombination_rates_single_crossover (double *rec_rates)
 Set the recombination rates for the single crossover model. More...
 
int calculate_recombinants_free ()
 Calculate the recombinant distribution for the free recombination case. More...
 
int calculate_recombinants_single ()
 Calculate the recombinant distribution for the single crossover case. More...
 
int calculate_recombinants_general ()
 Calculate the recombinant distribution for the general case. More...
 

Protected Attributes

gsl_rng * rng
 
int seed
 
hypercube_lowd recombinants
 
hypercube_lowd mutants
 
double ** recombination_patterns
 
int recombination_model
 
int number_of_loci
 
double population_size
 
int generation
 
double long_time_generation
 
double ** mutation_rates
 

Detailed Description

Low-dimensional population evolving on the hypercube_lowd.

This class enables simulation of short genomes ( \(L \lesssim 20\)) but potentially large populations. Random mutation, recombination and selection are supported. A number of properties of the population can be obtained using methods of this class, including:

  • genotype and allele frequencies;
  • statistics on fitness and phenotypic traits;
  • linkage disequilibrium.

Constructor & Destructor Documentation

haploid_lowd::haploid_lowd ( int  L_in = 1,
int  rng_seed = 0 
)

Default constructor.

Parameters
L_innumber of loci (at least 1)
rngseedseed for the random number generator. If this is zero, time(NULL)+getpid() is used.

Here is the call graph for this function:

haploid_lowd::~haploid_lowd ( )
virtual

Default destructor.

Release memory.

Member Function Documentation

double haploid_lowd::allele_entropy ( )

Get the allele entropy.

Returns
the allele entropy of the population

The allele entropy is defined as follows:

\[ S := - \sum_{i=1}^L \nu_i\log \nu_i + (1 - \nu_i)\log (1 - \nu_i), \]

where \(\nu_i\) is the frequency of the i-th allele.

Here is the call graph for this function:

int haploid_lowd::calculate_recombinants_free ( )
protected

Calculate the recombinant distribution for the free recombination case.

Returns
zero if successful, nonzero otherwise

Almost the same as for the more general case below, but kept separate for performance reasons - this is the most expensive part (3^L).

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::calculate_recombinants_general ( )
protected

Calculate the recombinant distribution for the general case.

Returns
zero if successful, nonzero otherwise

Calculate the distribution after recombination assumed in random mating with pairs sampled with replacement.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::calculate_recombinants_single ( )
protected

Calculate the recombinant distribution for the single crossover case.

Returns
zero if successful, nonzero otherwise

Calculate the distribution after recombination assumed in random mating with pairs sampled with replacement.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::evolve ( int  gen = 1)

Evolve the population for some generations.

Parameters
gennumber of generations
Returns
zero if successful, error code in the faulty step otherwise

Note: the order of selection, mutation, recombination, and resampling could be changed according to needs and beliefs. Note that only recombination calculates the inverse fourier transform of the population. It does so BEFORE the recombination step. To evaluate all allele frequencies and linkage disequilibria, call population.fft_func_to_coeff()

Here is the call graph for this function:

int haploid_lowd::evolve_deterministic ( int  gen = 1)

Evolve the population for some generations, without resampling (deterministic)

Parameters
gennumber of generations
Returns
zero if successful, error code in the faulty step otherwise

Note: the order of selection, mutation, and recombination could be changed according to needs and beliefs. Note that only recombination calculates the inverse fourier transform of the population. It does so BEFORE the recombination step. To evaluate all allele frequencies and linkage disequilibria, call population.fft_func_to_coeff()

Here is the call graph for this function:

int haploid_lowd::evolve_norec ( int  gen = 1)

Evolve the population for some generations, without recombination.

Parameters
gennumber of generations
Returns
zero if successful, error code in the faulty step otherwise

Note: the order of selection, mutation, and resampling could be changed according to needs and beliefs.

Here is the call graph for this function:

double haploid_lowd::genotype_entropy ( )

Get the genotype entropy.

Returns
the genotype entropy of the population

The genotype entropy is defined as follows:

\[ S := - \sum_{g} \nu_g \cdot \log \nu_g, \]

where \(g\) runs over all possible genomes, and \(\nu_g\) is the frequency of that genome in the population.

Here is the call graph for this function:

double haploid_lowd::get_allele_frequency ( int  locus)
inline
double haploid_lowd::get_chi ( int  locus)
inline
double haploid_lowd::get_chi2 ( int  locus1,
int  locus2 
)
inline
double haploid_lowd::get_fitness ( int  genotype)
inline
stat_t haploid_lowd::get_fitness_statistics ( )

Get fitness mean and variance in the population.

Returns
stat_t with the requested statistics

Here is the call graph for this function:

double haploid_lowd::get_generation ( )
inline
double haploid_lowd::get_genotype_frequency ( int  genotype)
inline
double haploid_lowd::get_LD ( int  locus1,
int  locus2 
)
inline
double haploid_lowd::get_moment ( int  locus1,
int  locus2 
)
inline
double haploid_lowd::get_mutation_rate ( int  locus,
int  direction 
)
inline
int haploid_lowd::get_number_of_loci ( )
inline
double haploid_lowd::get_pair_frequency ( int  locus1,
int  locus2 
)
inline
double haploid_lowd::get_population_size ( )
inline
int haploid_lowd::get_random_seed ( )
protected

Get a random seed from /dev/urandom.

Returns
non-deterministic, random seed

Here is the caller graph for this function:

int haploid_lowd::get_recombination_model ( )
inline
double haploid_lowd::get_recombination_rate ( int  locus)

Get the recombination rate between a locus and the next one.

Parameters
locusthe locus AFTER which the recombination rate is seeked
Returns
the recombination rate, -1 for FREE_RECOMBINATION

Note: for SINGLE_CROSSOVER, the recombination rate after the last locus is the rate of no recombination at all.

int haploid_lowd::L ( )
inline
int haploid_lowd::marginalize_recombination_patterns ( )
protected

Starting from a fully specified set of probabilities of recombination patterns, compute all sub patterns.

Parameters
@returnszero if successful, error codes otherwise

Here is the caller graph for this function:

int haploid_lowd::mutate ( )
protected

Mutation step.

Returns
zero if successful, nonzero otherwise

Calculate the distribution of mutants and update the population distribution

Here is the call graph for this function:

Here is the caller graph for this function:

double haploid_lowd::N ( )
inline
int haploid_lowd::recombine ( )
protected

Recombination step.

Returns
zero if successful, error codes otherwise

Calculate the distribution of recombinants and update the population, a fraction (outcrossing_rate) of the population is replaced by the recombinant distribution, calculated differently depending on whether free recombination or general recombination is used

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::resample ( )
protected

Resample the population according to the carrying capacity.

Returns
zero if successful, error codes otherwise

Note: genotypes with few individuals are sampled using the Poisson distribution, allowing for strict zero; genotypes with many individuals are resampled using a Gaussian distribution, for performance reasons.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::select ( )
protected

Selection step.

Returns
zero if successful, nonzero otherwise

Note: Population distribution is reweighted with exp(fitness) and renormalized.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::set_allele_frequencies ( double *  freq,
unsigned long  N_in 
)

Initialize population in linkage equilibrium.

Parameters
freqallele frequencies
N_inpopulation size
Returns
zero if successful, error codes otherwise

Note: when this function is used to initialize the population, it is likely that the fitness distribution has a very large width. In turn, this can result in an immediate and dramatic drop in diversity within the first few generations. Please check fitness statistics before starting the evolution if this worries you.

Note: the population size will be set. If not set yet, the carrying capacity will be set to the same number.

Here is the call graph for this function:

void haploid_lowd::set_generation ( double  g)
inline
int haploid_lowd::set_genotypes ( vector< index_value_pair_t gt)

Initialize the population with genotype counts.

Parameters
gtvector of index_value_pair_t type with indices and counts
Returns
zero if successful, error codes otherwise

Note: the population size will be set as the total sum of counts of all genotypes. If not set yet, the carrying capacity will be set to the same number.

Here is the call graph for this function:

int haploid_lowd::set_mutation_rates ( double  m)

Set a uniform mutation rate for all loci and both directions.

Parameters
mmutation rate
Returns
zero if successful, error codes otherwise
int haploid_lowd::set_mutation_rates ( double  mforward,
double  mbackward 
)

Set two mutation rates (forward / backward) for all loci.

Parameters
mforwardforward mutation rate
mbackwardbackward mutation rate
Returns
zero if successful, error codes otherwise
int haploid_lowd::set_mutation_rates ( double *  m)

Set mutation rates (locus specific, both directions the same)

Parameters
marray of mutation rates
Returns
zero if successful, error codes otherwise
int haploid_lowd::set_mutation_rates ( double **  m)

Set mutation rates (locus and direction specific)

Parameters
marray of mutation rates
Returns
zero if successful, error codes otherwise
int haploid_lowd::set_recombination_model ( int  rec_model)

Set a new recombination model.

Parameters
rec_modelthe new recombination model
Returns
zero if successful, error codes otherwise

The allowed models are FREE_RECOMBINATION, SINGLE_CROSSOVER, and CROSSOVERS.

Note: this function call involves memory release and allocation.

Here is the caller graph for this function:

int haploid_lowd::set_recombination_patterns ( vector< index_value_pair_t iv)
protected

set recombination patterns with a list of index value pairs

Parameters
vectorof index_value_pair_t structures
Returns
zero if successful, error code otherwise

Here is the call graph for this function:

int haploid_lowd::set_recombination_rates ( double *  rec_rates,
int  rec_model = -1 
)

calculate recombination patterns

Parameters
rec_ratesa vector of recombination rates.
rec_modelan int with the model of recombination to use

Note: rec_rates must have length L-1 for linear chromosomes, length L for circular ones. Note: rec_model must be either CROSSOVERS or, for linear genomes, SINGLE_CROSSOVER

Returns
zero if successful, error codes otherwise (e.g. out of memory)

A routine the calculates the probability of all possible recombination patterns and subpatterns thereof from a vector of recombination rates (rec_rates) passed as argument. It allocated the memory ( \(3^L\) or \(L \: 2^L\)) and calculates the entire distribution.

Note: the default value for rec_model is the current recombination model or, if that is FREE_RECOMBINATION, then it's CROSSOVERS.

Here is the call graph for this function:

int haploid_lowd::set_recombination_rates_general ( double *  rec_rates)
protected

Set the recombination rates for the general model.

Parameters
rec_ratesarray with the recombination rates
Returns
zero if successful, error codes otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_lowd::set_recombination_rates_single_crossover ( double *  rec_rates)
protected

Set the recombination rates for the single crossover model.

Parameters
rec_ratesarray with the recombination rates
Returns
zero if successful, error codes otherwise

Here is the caller graph for this function:

int haploid_lowd::set_wildtype ( unsigned long  N_in)

Initialize a wildtype population (00...0)

Parameters
N_innumber of individuals
Returns
0 if successful, nonzero otherwise.

Note: the population size will be set. If not set yet, the carrying capacity will be set to the same number.

Here is the call graph for this function:

Member Data Documentation

double haploid_lowd::carrying_capacity
bool haploid_lowd::circular
hypercube_lowd haploid_lowd::fitness
int haploid_lowd::generation
protected
double haploid_lowd::long_time_generation
protected
hypercube_lowd haploid_lowd::mutants
protected
double** haploid_lowd::mutation_rates
protected
int haploid_lowd::number_of_loci
protected
double haploid_lowd::outcrossing_rate
hypercube_lowd haploid_lowd::population
double haploid_lowd::population_size
protected
hypercube_lowd haploid_lowd::recombinants
protected
int haploid_lowd::recombination_model
protected
double** haploid_lowd::recombination_patterns
protected
gsl_rng* haploid_lowd::rng
protected
int haploid_lowd::seed
protected

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