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

Population class for high-dimensional simulations. More...

#include <ffpopsim_highd.h>

Inheritance diagram for haploid_highd:
Collaboration diagram for haploid_highd:

Public Member Functions

 haploid_highd (int L=0, int rng_seed=0, int number_of_traits=1, bool all_polymorphic=false)
 Default constructor. More...
 
virtual ~haploid_highd ()
 Destructor. More...
 
double get_mutation_rate ()
 
void set_mutation_rate (double m)
 
bool is_all_polymorphic ()
 
vector< poly_tget_polymorphisms ()
 
vector< poly_tget_fixed_mutations ()
 
vector< int > get_number_of_mutations ()
 
int L ()
 
int get_number_of_loci ()
 
int N ()
 
int get_population_size ()
 
int get_generation ()
 
void set_generation (int g)
 
int get_number_of_clones ()
 
int get_number_of_traits ()
 
double get_participation_ratio ()
 
int set_allele_frequencies (double *frequencies, unsigned long N)
 Initialize population in linkage equilibrium. More...
 
int set_genotypes (vector< genotype_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 track_locus_genealogy (vector< int > loci)
 Designates as set of loci to have their genealogy tracked. More...
 
void add_genotype (boost::dynamic_bitset<> genotype, int n=1)
 Add the genotype specified by a bitset to the current population in in n copies. More...
 
int add_trait_coefficient (double value, vector< int > loci, int t=0)
 
void clear_trait (int t=0)
 
void clear_traits ()
 
void set_random_trait_epistasis (double epistasis_std, int traitnumber=0)
 
int add_fitness_coefficient (double value, vector< int > loci)
 
void clear_fitness ()
 
void set_random_epistasis (double epistasis_std)
 
int evolve (int gen=1)
 Evolve for some generations under the specified conditions. More...
 
int bottleneck (int size_of_bottleneck)
 Cause a bottleneck in the population size. More...
 
unsigned int flip_single_locus (int locus)
 Flip a spin at a specific locus in random individual. More...
 
void calc_stat ()
 Calculate trait and fitness statistics and allele frequences. More...
 
void unique_clones ()
 Remove duplicate clones. More...
 
vector< int > get_nonempty_clones ()
 Obtain a list of the good clones. More...
 
int random_clone ()
 Get a random clone from the population. More...
 
int random_clones (unsigned int n_o_individuals, vector< int > *sample)
 Sample random individuals from the population. More...
 
string get_genotype_string (unsigned int i)
 
int distance_Hamming (unsigned int clone1, unsigned int clone2, vector< unsigned int * > *chunks=NULL, unsigned int every=1)
 
int distance_Hamming (boost::dynamic_bitset<> gt1, boost::dynamic_bitset<> gt2, vector< unsigned int * > *chunks=NULL, unsigned int every=1)
 Calculate Hamming distance between two sequences. More...
 
stat_t get_diversity_statistics (unsigned int n_sample=1000)
 Calculate diversity in the current population (Hamming distance between pairs of sequences) More...
 
stat_t get_divergence_statistics (unsigned int n_sample=1000)
 Calculate mean and variance of the divergence from the [00...0] bitset. More...
 
double get_allele_frequency (int l)
 
double get_derived_allele_frequency (int l)
 
double get_pair_frequency (int locus1, int locus2)
 Get the joint frequency of two alleles. More...
 
vector< double > get_pair_frequencies (vector< vector< int > > *loci)
 Get the joint frequency of two alleles, for a vector of allele pairs. More...
 
double get_chi (int l)
 
double get_derived_chi (int l)
 
double get_chi2 (int locus1, int locus2)
 
double get_LD (int locus1, int locus2)
 
double get_moment (int locus1, int locus2)
 
void set_trait_weights (double *weights)
 
double get_trait_weight (int t)
 
double get_fitness (int n)
 
int get_clone_size (int n)
 
double get_trait (int n, int t=0)
 
vector< coeff_tget_trait_epistasis (int t=0)
 
stat_t get_fitness_statistics ()
 
stat_t get_trait_statistics (int t=0)
 
double get_trait_covariance (int t1, int t2)
 
double get_max_fitness ()
 
void update_traits ()
 For each clone, recalculate its traits. More...
 
void update_fitness ()
 For each clone, update fitness assuming traits are already up to date. More...
 
int get_divergence_histogram (gsl_histogram **hist, unsigned int bins=10, vector< unsigned int * > *chunks=NULL, unsigned int every=1, unsigned int n_sample=1000)
 Get histogram of divergence from the [00...0] bitset. More...
 
int get_diversity_histogram (gsl_histogram **hist, unsigned int bins=10, vector< unsigned int * > *chunks=NULL, unsigned int every=1, unsigned int n_sample=1000)
 Get histogram of diversity in the population (mutual Hamming distance) More...
 
int get_fitness_histogram (gsl_histogram **hist, unsigned int bins=10, unsigned int n_sample=1000)
 Calculate histogram of fitness from traits. More...
 
int print_allele_frequencies (ostream &out)
 Print all allele frequencies into a stream provided. More...
 
int read_ms_sample (istream &gts, int skip_locus, int multiplicity)
 Read the output of Hudson's ms and use it to initialize the genotype distribution. More...
 
int read_ms_sample_sparse (istream &gts, int skip_locus, int multiplicity, int distance)
 Read the output of Hudson's ms and use it to initialize the genotype distribution. More...
 

Public Attributes

hypercube_highdtrait
 
vector< clone_tpopulation
 
int carrying_capacity
 
double outcrossing_rate
 
double crossover_rate
 
int recombination_model
 
bool circular
 
double growth_rate
 
multi_locus_genealogy genealogy
 

Protected Member Functions

int get_random_seed ()
 Get a random seed from /dev/urandom. More...
 
void produce_random_sample (int size=1000)
 Produce and store a random sample of the population for stochastic processes. More...
 
int mutate ()
 Mutate random clones at random loci (all loci) More...
 
int select_gametes ()
 Generate offspring according to fitness (selection) and segregate some for sexual mating. More...
 
double relaxation_value ()
 Get the log of the exp-average fitness plus relaxation term. More...
 
double get_logmean_expfitness ()
 Get the population exp-average of fitness, used for keeping the population size fixed. More...
 
unsigned int flip_single_locus (unsigned int clonenum, int locus)
 Flip a spin (locus) in individual. More...
 
void shuffle_genotypes ()
 
int new_generation ()
 
int partition_cumulative (vector< unsigned int > &partition_cum)
 Calculate the cumulative partition of sequences into clones. More...
 
int provide_at_least (int n)
 : allocates memory for a sufficient number of clones More...
 
void calc_allele_freqs ()
 calculate and store allele frequencies More...
 
void reassortment_pattern ()
 Produce a random reassortement pattern. More...
 
void crossover_pattern ()
 Choose a number of crossover points and produce a crossover pattern. More...
 
int add_recombinants ()
 Pair and mate sexual gametes. More...
 
int recombine (int parent1, int parent2)
 Recombine two genotypes parent1 and parent2 to produce two new genotypes. More...
 
int recombine_crossover (int parent1, int parent2, int ng)
 
void calc_fitness_stat ()
 Calculate and store fitness population statistics. More...
 
void calc_trait_stat ()
 Calculate and store trait population statistics and covariances. More...
 
void calc_individual_traits (clone_t &tempgt)
 Calculate traits of the chosen clone. More...
 
void calc_individual_fitness (clone_t &tempgt)
 Calculate fitness of a particular clone. More...
 
void calc_individual_traits (int clonenum)
 
void calc_individual_fitness (int clonenum)
 
void check_individual_maximal_fitness (clone_t &tempgt)
 
double get_trait_difference (clone_t &tempgt1, clone_t &tempgt2, vector< int > &diffpos, int traitnum)
 Calculate trait difference between two clones. More...
 
virtual void calc_individual_fitness_from_traits (clone_t &tempgt)
 Calculate fitness from traits of the chosen clone. More...
 
virtual void calc_individual_fitness_from_traits (int clonenum)
 
void add_clone_to_genealogy (int locus, int dest, int parent, int left, int right, int cs, int n)
 

Protected Attributes

gsl_rng * evo_generator
 
gsl_rng * label_generator
 
int seed
 
vector< int > random_sample
 
int number_of_loci
 
int population_size
 
int number_of_traits
 
int generation
 
int number_of_clones
 
double mutation_rate
 
double participation_ratio
 
int last_clone
 
bool allele_frequencies_up_to_date
 
double * allele_frequencies
 
double * gamete_allele_frequencies
 
double * chi1
 
double ** chi2
 
bool all_polymorphic
 
vector< int > ancestral_state
 
vector< poly_tpolymorphism
 
vector< poly_tfixed_mutations
 
vector< int > number_of_mutations
 
double outcrossing_rate_effective
 
int * genome
 
int * crossovers
 
vector< int > sex_gametes
 
double fitness_max
 
stat_t fitness_stat
 
stat_ttrait_stat
 
double ** trait_covariance
 
double * trait_weights
 
bool track_genealogy
 

Detailed Description

Population class for high-dimensional simulations.

This class is the main object storing the state of and enabling the manipulation of populations with long genomes ( \(L\)) larger than 20.

Both asexual and sexual populations can be simulated. Since asexual populations under selection are often structured as a small list of large clones, the class stores the clones and their sizes instead of the individuals.

Class methods give access to a variety of information on the population, including:

  • the fitness distribution;
  • summary statistics of fitness and other phenotypic trits;
  • genetic structure (linkage disequilibrium, allele frequencies, number of clones).

Constructor & Destructor Documentation

haploid_highd::haploid_highd ( int  L_in = 0,
int  rng_seed = 0,
int  n_o_traits = 1,
bool  all_polymorphic_in = false 
)

Default constructor.

The population objects are initialized, but neither the random generator is initialized nor the memory for traits, gametes etc. is allocated. Please call set_up() before using the class.

Note: The sequence is assumed to be linear (not circular). You can change this by hand if you wish so.

Here is the call graph for this function:

haploid_highd::~haploid_highd ( )
virtual

Destructor.

Memory is released here.

Member Function Documentation

void haploid_highd::add_clone_to_genealogy ( int  locus,
int  dest,
int  parent,
int  left,
int  right,
int  cs,
int  n 
)
protected

Here is the caller graph for this function:

int haploid_highd::add_fitness_coefficient ( double  value,
vector< int >  loci 
)
inline
void haploid_highd::add_genotype ( boost::dynamic_bitset<>  genotype,
int  n = 1 
)

Add the genotype specified by a bitset to the current population in in n copies.

Parameters
genotypegenotype being added
nnumber of copies of that genotype

Note: this function also calculates the traits and fitness of the new individual.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::add_recombinants ( )
protected

Pair and mate sexual gametes.

Returns
zero if successful, nonzero otherwise

Using the previously produced list of sex_gametes, pair them at random and mate

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::add_trait_coefficient ( double  value,
vector< int >  loci,
int  t = 0 
)
inline

Here is the caller graph for this function:

int haploid_highd::bottleneck ( int  size_of_bottleneck)

Cause a bottleneck in the population size.

Parameters
size_of_bottlenecknumber of individuals to leave alive (approximate)
Returns
zero if successful, error codes otherwise

The bottleneck is performed as follows. Each clone is traded in for a smaller one with size given by a Poisson random number around the new population size times the clone frequency. This function should therefore almost conserve genotype frequencies, except for rare genotypes that are lost.

Here is the call graph for this function:

void haploid_highd::calc_allele_freqs ( )
protected

calculate and store allele frequencies

Note: the allele frequencies are available in the allele_frequencies attribute.

Here is the caller graph for this function:

void haploid_highd::calc_fitness_stat ( )
protected

Calculate and store fitness population statistics.

The fitness statistics are stored in fitness_stat.

Note: this function assumes that fitness is up to date. If you are not sure, call update_traits() and update_fitness() first.

Here is the caller graph for this function:

void haploid_highd::calc_individual_fitness ( clone_t tempgt)
protected

Calculate fitness of a particular clone.

Parameters
tempgtclone whose fitness is being calculated

Note: this function also updates the traits information for the same clone, because the phenotype is needed to calculate fitness. If you have already calculated the traits, you can rely calc_individual_fitness_from_traits.

Here is the call graph for this function:

void haploid_highd::calc_individual_fitness ( int  clonenum)
inlineprotected

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::calc_individual_fitness_from_traits ( clone_t tempgt)
protectedvirtual

Calculate fitness from traits of the chosen clone.

Parameters
tempgtclone whose fitness is to be calculated

This function is linear in the traits with weights equal to trait_weights. By default, only the first weight is different from zero.

Here is the caller graph for this function:

virtual void haploid_highd::calc_individual_fitness_from_traits ( int  clonenum)
inlineprotectedvirtual

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::calc_individual_traits ( clone_t tempgt)
protected

Calculate traits of the chosen clone.

Parameters
tempgtclone whose traits are to be calculated

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::calc_individual_traits ( int  clonenum)
inlineprotected

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::calc_stat ( )

Calculate trait and fitness statistics and allele frequences.

Four things are done in a row:

  1. traits are updated
  2. fitness is updated based on the new traits
  3. statistics of traits and fitness are calculated
  4. allele freqs are calculated

Note: This function is quite expensive. Please use its subblocks whenever possible, and rely on this only when you want to make sure, at the expense of performance, that everything is up to date.

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::calc_trait_stat ( )
protected

Calculate and store trait population statistics and covariances.

The traits statistics are stored in traits_stat.

Note: this function assumes that traits are up to date. If you are not sure, call update_traits() first.

Here is the caller graph for this function:

void haploid_highd::check_individual_maximal_fitness ( clone_t tempgt)
inlineprotected

Here is the caller graph for this function:

void haploid_highd::clear_fitness ( )
inline
void haploid_highd::clear_trait ( int  t = 0)
inline
void haploid_highd::clear_traits ( )
inline
void haploid_highd::crossover_pattern ( )
protected

Choose a number of crossover points and produce a crossover pattern.

Returns
crossover pattern

A typical crossover pattern would be 0000111100011111101101.

Here is the caller graph for this function:

int haploid_highd::distance_Hamming ( unsigned int  clone1,
unsigned int  clone2,
vector< unsigned int * > *  chunks = NULL,
unsigned int  every = 1 
)
inline

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::distance_Hamming ( boost::dynamic_bitset<>  gt1,
boost::dynamic_bitset<>  gt2,
vector< unsigned int * > *  chunks = NULL,
unsigned int  every = 1 
)

Calculate Hamming distance between two sequences.

Parameters
gt1first sequence
gt2second sequence
chunks(pointer to) vector of ranges (C pairs), e.g. ((0,10), (25, 28), (68, 70))
everycheck only every X sites, starting from the first of each chunk

Note: you cannot use every without chunks.

Note: every chunk is a C array of length 2, i.e. a pointer to lower boundary of the interval. Thus we have the following situation:

  • chunks is of type vector <unsigned int *> *
  • *chunks is of type vector <unsigned int *>
  • (*chunks)[i] is of type *unsigned int
  • (*chunks)[i][0] is of type unsigned int, and indicates the initial site for this chunk
  • (*chunks)[i][1] is of type unsigned int, and indicates the (final site +1) for this chunk

As a consequence, for each chunk, chunk[1] - chunk[0] is the length of the chunk.

Returns
Hamming distance, not normalized

When you prepare the vector of chunks for this function, please use C++ methods (new) that take care of memory management, or be very careful about memory leaks.

Note: this function is overloaded with simpler arguments (e.g. if you want to use clone indices).

int haploid_highd::evolve ( int  gen = 1)

Evolve for some generations under the specified conditions.

The order of steps performed is

  1. selection
  2. recombination
  3. mutation but should not be important except for extremely high selection coefficients and/or very short times, for which the discrete nature of the Fisher-Wright model becomes relevant.
Parameters
gennumber of generations.
Returns
zero if successful, error code in the faulty step otherwise

Note: if an error in encountered, evolution is stopped after the function that created the problem. Typical errors include extinction or the opposite, offspring explosion.

Here is the call graph for this function:

unsigned int haploid_highd::flip_single_locus ( int  locus)

Flip a spin at a specific locus in random individual.

Parameters
locusposition of the locus to flip
Returns
index of the new clone

Note: this function calls flip_single_locus(unsigned int clonenum, int locus).

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int haploid_highd::flip_single_locus ( unsigned int  clonenum,
int  locus 
)
protected

Flip a spin (locus) in individual.

Parameters
clonenumthe individual whose locus is being flipped
locusposition of the locus to flip

This function creates a new clone and adds it to the population, and assigns it a fitness.

Note: This might produce duplicate clones since the mutant clone produced might already exist. Duplicates can be merged by the member unique_clones()

Here is the call graph for this function:

double haploid_highd::get_allele_frequency ( int  l)
inline
double haploid_highd::get_chi ( int  l)
inline
double haploid_highd::get_chi2 ( int  locus1,
int  locus2 
)
inline
int haploid_highd::get_clone_size ( int  n)
inline
double haploid_highd::get_derived_allele_frequency ( int  l)
inline
double haploid_highd::get_derived_chi ( int  l)
inline
int haploid_highd::get_divergence_histogram ( gsl_histogram **  hist,
unsigned int  bins = 10,
vector< unsigned int * > *  chunks = NULL,
unsigned int  every = 1,
unsigned int  n_sample = 1000 
)

Get histogram of divergence from the [00...0] bitset.

Parameters
histpointer to the gsl_histogram to fill
binsnumber of bins in the histogram

Note: an antialiasing algorithm is used to enforce integer bin widths. Note: because of the antialiasing requirement, the last bin might be underrepresented. Note: the number of used bins in the output might be smaller than requested, depending on sample size and antialiasing.

Parameters
chunks(pointer to) vector of ranges (C pairs), e.g. ((0,10), (25, 28), (68, 70))
everycheck only every X sites, starting from the first of each chunk

Note: you cannot use every without chunks.

Note: every chunk is a C array of length 2, i.e. a pointer to lower boundary of the interval. Thus we have the following situation:

  • chunks is of type vector <unsigned int *> *
  • *chunks is of type vector <unsigned int *>
  • (*chunks)[i] is of type *unsigned int
  • (*chunks)[i][0] is of type unsigned int, and indicates the initial site for this chunk
  • (*chunks)[i][1] is of type unsigned int, and indicates the (final site +1) for this chunk

As a consequence, for each chunk, chunk[1] - chunk[0] is the length of the chunk.

Parameters
n_samplesize of the random sample to use (the whole population is often too large)
Returns
zero if successful, error codes otherwise

Here is the call graph for this function:

stat_t haploid_highd::get_divergence_statistics ( unsigned int  n_sample = 1000)

Calculate mean and variance of the divergence from the [00...0] bitset.

Parameters
n_samplesize of the statistical sample to use (the whole pop is often too large)
Returns
mean and variance of the divergence in a stat_t

Here is the call graph for this function:

int haploid_highd::get_diversity_histogram ( gsl_histogram **  hist,
unsigned int  bins = 10,
vector< unsigned int * > *  chunks = NULL,
unsigned int  every = 1,
unsigned int  n_sample = 1000 
)

Get histogram of diversity in the population (mutual Hamming distance)

Parameters
histpointer to the gsl_histogram to fill
binsnumber of bins in the histogram

Note: an antialiasing algorithm is used to enforce integer bin widths. Note: because of the antialiasing requirement, the last bin might be underrepresented. Note: the number of used bins in the output might be smaller than requested, depending on sample size and antialiasing.

Parameters
chunks(pointer to) vector of ranges (C pairs), e.g. ((0,10), (25, 28), (68, 70))
everycheck only every X sites, starting from the first of each chunk

Note: you cannot use every without chunks.

Note: every chunk is a C array of length 2, i.e. a pointer to lower boundary of the interval. Thus we have the following situation:

  • chunks is of type vector <unsigned int *> *
  • *chunks is of type vector <unsigned int *>
  • (*chunks)[i] is of type *unsigned int
  • (*chunks)[i][0] is of type unsigned int, and indicates the initial site for this chunk
  • (*chunks)[i][1] is of type unsigned int, and indicates the (final site +1) for this chunk

As a consequence, for each chunk, chunk[1] - chunk[0] is the length of the chunk.

Parameters
n_samplesize of the random sample to use (the whole population is often too large)
Returns
zero if successful, error codes otherwise

Here is the call graph for this function:

stat_t haploid_highd::get_diversity_statistics ( unsigned int  n_sample = 1000)

Calculate diversity in the current population (Hamming distance between pairs of sequences)

Parameters
n_samplesize of the statistical sample to use (the whole pop is often too large)
Returns
mean and variance of the diversity in a stat_t

Here is the call graph for this function:

double haploid_highd::get_fitness ( int  n)
inline
int haploid_highd::get_fitness_histogram ( gsl_histogram **  hist,
unsigned int  bins = 10,
unsigned int  n_sample = 1000 
)

Calculate histogram of fitness from traits.

Parameters
histpointer to the gsl_histogram to fill
binsnumber of bins in the histogram

Note: the output histogram might have less bins than requested if the sample size is too small.

Parameters
n_samplesize of the random sample to use (the whole population is often too large)
Returns
zero if successful, error codes otherwise

There is a small problem here, namely that sometimes the fitness distribution has a horrible tail which messes up the calculation of the bin width. Thus we first calculate the fitness average and variance, and then set the bin width so that the deleterious tail is within 2 sigma or so.

Note: this function allocates memory for the histogram only if there is no binning error. If you get HP_NOBINSERR, no memory is allocated. The user is expected to release the memory manually.

Here is the call graph for this function:

stat_t haploid_highd::get_fitness_statistics ( )
inline
vector<poly_t> haploid_highd::get_fixed_mutations ( )
inline
int haploid_highd::get_generation ( )
inline

Here is the caller graph for this function:

string haploid_highd::get_genotype_string ( unsigned int  i)
inline
double haploid_highd::get_LD ( int  locus1,
int  locus2 
)
inline
double haploid_highd::get_logmean_expfitness ( )
protected

Get the population exp-average of fitness, used for keeping the population size fixed.

Returns
the population exp-average of fitness

Mathematically, this is \( \log\left( \left< e^(F-F_{max}) \right> \right) \). The baseline is \( F_{max} \) in order to avoid exponentiating large numbers.

Here is the caller graph for this function:

double haploid_highd::get_max_fitness ( )
inline
double haploid_highd::get_moment ( int  locus1,
int  locus2 
)
inline
double haploid_highd::get_mutation_rate ( )
inline
vector< int > haploid_highd::get_nonempty_clones ( )

Obtain a list of the good clones.

Returns
vector of clone indices
int haploid_highd::get_number_of_clones ( )
inline

Here is the caller graph for this function:

int haploid_highd::get_number_of_loci ( )
inline

Here is the caller graph for this function:

vector<int> haploid_highd::get_number_of_mutations ( )
inline
int haploid_highd::get_number_of_traits ( )
inline
vector< double > haploid_highd::get_pair_frequencies ( vector< vector< int > > *  loci)

Get the joint frequency of two alleles, for a vector of allele pairs.

Parameters
locipointer to a vector of allele pairs. Each element of loci must be a vector of length 2.
Returns
vector of joint frequencies.

Here is the call graph for this function:

double haploid_highd::get_pair_frequency ( int  locus1,
int  locus2 
)

Get the joint frequency of two alleles.

Parameters
locus1position of the first allele.
locus2position of the second allele.
Returns
the joint frequency of the two alleles.

Here is the caller graph for this function:

double haploid_highd::get_participation_ratio ( )
inline
vector<poly_t> haploid_highd::get_polymorphisms ( )
inline
int haploid_highd::get_population_size ( )
inline

Here is the caller graph for this function:

int haploid_highd::get_random_seed ( )
protected

Get a random seed from /dev/urandom.

Returns
non-deterministic, random seed

Here is the caller graph for this function:

double haploid_highd::get_trait ( int  n,
int  t = 0 
)
inline
double haploid_highd::get_trait_covariance ( int  t1,
int  t2 
)
inline
double haploid_highd::get_trait_difference ( clone_t tempgt1,
clone_t tempgt2,
vector< int > &  diffpos,
int  traitnum 
)
protected

Calculate trait difference between two clones.

Parameters
tempgt1first clone
tempgt2second clone
diffpospositions at which the genotypes differ
traitnumnumber of the trait to calculate
Returns
vector of differences

The operation is, for each trait, tempgt1 - tempgt2.

Here is the call graph for this function:

Here is the caller graph for this function:

vector<coeff_t> haploid_highd::get_trait_epistasis ( int  t = 0)
inline
stat_t haploid_highd::get_trait_statistics ( int  t = 0)
inline
double haploid_highd::get_trait_weight ( int  t)
inline
bool haploid_highd::is_all_polymorphic ( )
inline
int haploid_highd::L ( )
inline

Here is the caller graph for this function:

int haploid_highd::mutate ( )
protected

Mutate random clones at random loci (all loci)

Note: for efficiency reasons, if the mutation rate is zero, an if cycle skips the body altogether. The user can therefore call this function safely even if in non-mutating populations, without loss of performance.

Function is now rewritten to allow for multiple mutants. TODO: Poisson conditional on at least one FIXME!: all_polymorphic assumes that all additive effects are set, i.e. that locus equals the index of the coefficient in the vector of additive effects

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::N ( )
inline
int haploid_highd::new_generation ( )
protected
int haploid_highd::partition_cumulative ( vector< unsigned int > &  partition_cum)
protected

Calculate the cumulative partition of sequences into clones.

Parameters
partition_cumthe vector to be filled
Returns
vector of cumulative clone sizes

Example: if there are three clones of sizes (100, 22, 3) this function will fill the vector (100, 122, 125). The last element is of course the population size See also get_population_size.

Note: the vector is taken in input by reference for performance reasons, since it can get huge.

int haploid_highd::print_allele_frequencies ( ostream &  out)

Print all allele frequencies into a stream provided.

Parameters
outstream to put the allele frequencies (usually a file or stdout)
Returns
zero if successful, nonzero otherwise

Here is the call graph for this function:

void haploid_highd::produce_random_sample ( int  size = 1000)
protected

Produce and store a random sample of the population for stochastic processes.

Parameters
sizesize of the sample

Produce a random sample of genotypes (labeled by their clone of origin) which is to be used for mutations and sampling. The vector random_sample exists for efficiency reasons, for it is faster to call the random number generator once than many times.

Note: if you want to get random clones, please use random_clone().

Here is the caller graph for this function:

int haploid_highd::provide_at_least ( int  n)
protected

: allocates memory for a sufficient number of clones

: number of empty clones required

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::random_clone ( )

Get a random clone from the population.

Returns
the index of the random clone

The probability density function from which the individual is chosen is flat over the population (larger clones are proportionally more likely to be returned here).

Note: for efficiency reasons, the class keeps a storage of random clone indices. If you need much more than, say, 1000 random clones at a time, please call produce_random_sample with the required size in advance.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::random_clones ( unsigned int  n_o_individuals,
vector< int > *  sample 
)

Sample random individuals from the population.

Parameters
n_o_individualsnumber of individuals to sample
samplepointer to vector where to put the result
Returns
zero if successful, nonzero otherwise

The results are not returned as a vector for performance reasons, as one might want to get a lot of random clones. *sample may be not empty (but must be allocated). In any case, clone numbers of the sampled individuals are appended to *sample. Hence, you can use this function iteratively (although there might not be a good reason to do so).

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::read_ms_sample ( istream &  gts,
int  skip_locus,
int  multiplicity 
)

Read the output of Hudson's ms and use it to initialize the genotype distribution.

Parameters
gtsgenotypes output of ms
skip_locusposition of the locus to be skipped
multiplicitynumber of times each genotype is added
Returns
zero if successful, error codes otherwise

ms loci are fed into the genotype with a locus that is skipped. Each ms genotype is added multiple times.

Here is the call graph for this function:

int haploid_highd::read_ms_sample_sparse ( istream &  gts,
int  skip_locus,
int  multiplicity,
int  distance 
)

Read the output of Hudson's ms and use it to initialize the genotype distribution.

Parameters
gtsgenotypes output of ms
skip_locuspositionof the locus to be skipped
multiplicitynumber of times each genotype must be added
distancedistance between two polymorphic sites
Returns
zero if successful, error codes otherwise

ms loci are fed into the genotype at distance "distance", i.e. there are distance-1 monomorphic loci. One locus is skipped. Each ms genotype is added multiple times.

Here is the call graph for this function:

void haploid_highd::reassortment_pattern ( )
protected

Produce a random reassortement pattern.

Returns
reassortement pattern

Here is the caller graph for this function:

int haploid_highd::recombine ( int  parent1,
int  parent2 
)
protected

Recombine two genotypes parent1 and parent2 to produce two new genotypes.

Parameters
parent1first parent
parent2second parent
Returns
zero if successful

The new genotypes are stored in new_pop at positions ng and ng+1.

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::recombine_crossover ( int  parent1,
int  parent2,
int  ng 
)
protected
double haploid_highd::relaxation_value ( )
protected

Get the log of the exp-average fitness plus relaxation term.

Returns
baseline relative to which growth rates are measured, i.e. the current mean fitness plus the term that causes the population size to relax to carrying_capacity

Here is the call graph for this function:

Here is the caller graph for this function:

int haploid_highd::select_gametes ( )
protected

Generate offspring according to fitness (selection) and segregate some for sexual mating.

Returns
zero if successful, error codes otherwise

Random Poisson offspring numbers are drawn from all parents, proportionally to their fitness. A fraction r of all offspring are designated for sexual reproduction, while the remainder (1-r) reproduces by exact duplication (mutations are introduced later). The population size relaxes to a carrying capacity, i.e. selection is soft but the population size is not exactly fixed.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Initialize population in linkage equilibrium.

Parameters
freqtarget allele frequencies
N_innumber of individuals to be created
Returns
zero if successful, error codes otherwise

Note: the carrying capacity is set equal to N_in if it is still unset.

Here is the call graph for this function:

void haploid_highd::set_generation ( int  g)
inline
int haploid_highd::set_genotypes ( vector< genotype_value_pair_t gt)

Initialize the population with genotype counts.

Parameters
gtvector of genotype_value_pair with genotypes and sizes
Returns
0 if successful, nonzero otherwise.

Note: the population size is set as the total sum of counts of all genotypes. The carrying capacity is also set to the same number if it is still unset.

Here is the call graph for this function:

void haploid_highd::set_mutation_rate ( double  m)
inline
void haploid_highd::set_random_epistasis ( double  epistasis_std)
inline
void haploid_highd::set_random_trait_epistasis ( double  epistasis_std,
int  traitnumber = 0 
)
inline
void haploid_highd::set_trait_weights ( double *  weights)
inline
int haploid_highd::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 carrying capacity is set equal to N_in if it is still unset.

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::shuffle_genotypes ( )
protected
int haploid_highd::track_locus_genealogy ( vector< int >  loci)

Designates as set of loci to have their genealogy tracked.

locus to be tracked

Here is the call graph for this function:

void haploid_highd::unique_clones ( )

Remove duplicate clones.

The library does not usually check whether two clones with the same genotype are present, but this can happen in case of recurrent mutation. This function merges duplicates.

Note: this is only needed for studying the clone structure. Evolution itself does not need to make sure that clones are unique.

void haploid_highd::update_fitness ( )

For each clone, update fitness assuming traits are already up to date.

Here is the call graph for this function:

Here is the caller graph for this function:

void haploid_highd::update_traits ( )

For each clone, recalculate its traits.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool haploid_highd::all_polymorphic
protected
double* haploid_highd::allele_frequencies
protected
bool haploid_highd::allele_frequencies_up_to_date
protected
vector<int> haploid_highd::ancestral_state
protected
int haploid_highd::carrying_capacity
double* haploid_highd::chi1
protected
double** haploid_highd::chi2
protected
bool haploid_highd::circular
double haploid_highd::crossover_rate
int* haploid_highd::crossovers
protected
gsl_rng* haploid_highd::evo_generator
protected
double haploid_highd::fitness_max
protected
stat_t haploid_highd::fitness_stat
protected
vector<poly_t> haploid_highd::fixed_mutations
protected
double* haploid_highd::gamete_allele_frequencies
protected
multi_locus_genealogy haploid_highd::genealogy
int haploid_highd::generation
protected
int* haploid_highd::genome
protected
double haploid_highd::growth_rate
gsl_rng* haploid_highd::label_generator
protected
int haploid_highd::last_clone
protected
double haploid_highd::mutation_rate
protected
int haploid_highd::number_of_clones
protected
int haploid_highd::number_of_loci
protected
vector<int> haploid_highd::number_of_mutations
protected
int haploid_highd::number_of_traits
protected
double haploid_highd::outcrossing_rate
double haploid_highd::outcrossing_rate_effective
protected
double haploid_highd::participation_ratio
protected
vector<poly_t> haploid_highd::polymorphism
protected
vector<clone_t> haploid_highd::population
int haploid_highd::population_size
protected
vector<int> haploid_highd::random_sample
protected
int haploid_highd::recombination_model
int haploid_highd::seed
protected
vector<int> haploid_highd::sex_gametes
protected
bool haploid_highd::track_genealogy
protected
hypercube_highd* haploid_highd::trait
double** haploid_highd::trait_covariance
protected
stat_t* haploid_highd::trait_stat
protected
double* haploid_highd::trait_weights
protected

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