libsequence  1.9.5
Sequence::coalsim Namespace Reference

Routines for coalescent simulation. More...

Classes

struct  chromosome
 A chromosome is a container of segments. More...
 
struct  marginal
 The genealogy of a portion of a chromosome on which no recombination has occurred. More...
 
class  newick_stream_marginal_tree
 Class that provides a typecast-on-output of a marginal tree to a newick tree Example use: More...
 
class  newick_stream_marginal_tree_impl
 
struct  node
 A point on a marginal tree at which a coalescent event occurs. More...
 
struct  segment
 A portion of a recombining chromosome. More...
 

Typedefs

typedef std::vector< std::string >::size_type MAX_SEG_T
 
typedef std::pair< std::vector< double >, std::vector< std::string > > gamete_storage_type
 an object to store simulated gametes An object of this type will tend to exist in the calling environment of your program. If you are simulating a sample of n chromosomes, you would initialize the object as follows: More...
 
typedef std::list< marginalarg
 Ancestral Recombination Graph. More...
 

Functions

template<typename uniform_generator >
std::pair< int, int > pick2_in_deme (uniform_generator &uni, const std::vector< Sequence::coalsim::chromosome > &sample, const int &ttl_nsam, const int &deme_nsam, const int &deme)
 
template<typename uniform_generator >
std::pair< int, int > pick2_in_deme (const uniform_generator &uni, const std::vector< Sequence::coalsim::chromosome > &sample, const int &ttl_nsam, const int &deme_nsam, const int &deme)
 
template<typename uniform_generator >
std::pair< int, int > pick2 (uniform_generator &uni, const int &nsam)
 
template<typename uniform_generator >
std::pair< int, int > pick2 (const uniform_generator &uni, const int &nsam)
 
bool isseg (chromosome::const_iterator seg, const unsigned &nsegs, const int &pos, unsigned *offset)
 ask if a chromosome beginning at seg and containing nsegs contains a segment containing the position pos More...
 
int coalesce (const double &time, const int &ttl_nsam, const int &current_nsam, const int &c1, const int &c2, const int &nsites, int *nlinks, std::vector< chromosome > *sample, arg *sample_history)
 Common ancestor routine for coalescent simulation. Merges chromosome segments and updates marginal trees. More...
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator >
arg bottleneck (uniform_generator &uni, uniform01_generator &uni01, exponential_generator &expo, const std::vector< chromosome > &initialized_sample, const marginal &initialized_marginal, const double &tr, const double &d, const double &f, const double &rho=0., const bool &exponential_recovery=false, const double &recovered_size=1.)
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator >
arg bottleneck (const uniform_generator &uni, const uniform01_generator &uni01, const exponential_generator &expo, const std::vector< chromosome > &initialized_sample, const marginal &initialized_marginal, const double &tr, const double &d, const double &f, const double &rho=0., const bool &exponential_recovery=false, const double &recovered_size=1.)
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator >
arg exponential_change (uniform_generator &uni, uniform01_generator &uni01, exponential_generator &expo, const std::vector< chromosome > &initialized_sample, const marginal &initialized_marginal, const double &G, const double &t_begin, const double &t_end, const double &rho=0., const double &size_at_end=-1)
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator >
arg exponential_change (const uniform_generator &uni, const uniform01_generator &uni01, const exponential_generator &expo, const std::vector< chromosome > &initialized_sample, const marginal &initialized_marginal, const double &G, const double &t_begin, const double &t_end, const double &rho=0., const double &size_at_end=-1)
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator >
arg snm (uniform_generator &uni, uniform01_generator &uni01, exponential_generator &expo, const std::vector< chromosome > &initialized_sample, const marginal &initialized_marginal, const double &rho)
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator >
arg snm (const uniform_generator &uni, const uniform01_generator &uni01, const exponential_generator &expo, const std::vector< chromosome > &initialized_sample, const marginal &initialized_marginal, const double &rho)
 
int sample_length (const std::vector< std::pair< int, int > > &fragments)
 When simulating partially linked regions, return the total length of sample material that we are simulating. More...
 
int total_length (const std::vector< std::pair< int, int > > &fragments)
 When simulating partially linked regions, return the total length of the region. More...
 
void calculate_scales (const std::vector< std::pair< int, int > > &fragments, std::vector< std::pair< double, double > > *sample_scale, std::vector< std::pair< double, double > > *mutation_scale)
 This is a helper function that rescales physical distance in base pairs to continuous distance on the interval 0,1. More...
 
void rescale_mutation_positions (Sequence::SimData *d, const std::vector< std::pair< double, double > > &sample_scale, const std::vector< std::pair< double, double > > &mutation_scale)
 Rescales the positions of the mutations in d from the scale given in sample_scale to that given in mutation_scale. More...
 
void rescale_arg (arg *sample_history, const std::vector< std::pair< int, int > > &fragments)
 Rescales the beginnings of marginal trees in an ancestral recombination graph from a genetic scale to a physical scale.
 
double integrate_genetic_map (const std::vector< chromosome > &sample, const int &current_nsam, const std::vector< double > &genetic_map, std::vector< double > *reclens)
 When simulating non-uniform recombination rates, the probability of recombination at each point in the simulation needs to be obtained by integrating over the genetic map and the current sample configuration. This function does that. More...
 
std::vector< chromosomeinit_sample (const std::vector< int > &pop_config, const int &nsites)
 A simple function to initialize a sample of chromosomes. More...
 
marginal init_marginal (const int &nsam)
 Simple function to initialize a marginal tree. More...
 
template<typename uniform_generator >
void add_S_inf_sites (uniform_generator &uni, marginal::const_iterator history, const double &tt, const int &beg, const int &end, const int &nsam, const int &nsites, const int &S, const int &first_snp_index, gamete_storage_type *gametes)
 
template<typename uniform_generator >
void add_S_inf_sites (const uniform_generator &uni, marginal::const_iterator history, const double &tt, const int &beg, const int &end, const int &nsam, const int &nsites, const int &S, const int &first_snp_index, gamete_storage_type *gametes)
 
template<typename poisson_generator , typename uniform_generator >
int infinite_sites (poisson_generator &poiss, uniform_generator &uni, gamete_storage_type *gametes, const int &nsites, const arg &history, const double &theta)
 
template<typename poisson_generator , typename uniform_generator >
int infinite_sites (const poisson_generator &poiss, const uniform_generator &uni, gamete_storage_type *gametes, const int &nsites, const arg &history, const double &theta)
 
template<typename uniform_generator >
int infinite_sites (uniform_generator &uni, gamete_storage_type *gametes, const int &nsites, const arg &history, const double *total_times, const unsigned *segsites)
 
template<typename uniform_generator >
int infinite_sites (const uniform_generator &uni, gamete_storage_type *gametes, const int &nsites, const arg &history, const double *total_times, const unsigned *segsites)
 
template<typename poisson_generator , typename uniform_generator >
SimData infinite_sites_sim_data (poisson_generator &poiss, uniform_generator &uni, const int &nsites, const arg &history, const double &theta) __attribute((deprecated))
 
template<typename poisson_generator , typename uniform_generator >
SimData infinite_sites_sim_data (const poisson_generator &poiss, const uniform_generator &uni, const int &nsites, const arg &history, const double &theta) __attribute__((deprecated))
 
template<typename uniform_generator >
SimData infinite_sites_sim_data (uniform_generator &uni, const int &nsites, const arg &history, const double *total_times, const unsigned *segsites) __attribute__((deprecated))
 
template<typename uniform_generator >
SimData infinite_sites_sim_data (const uniform_generator &uni, const int &nsites, const arg &history, const double *total_times, const unsigned *segsites) __attribute__((deprecated))
 
void output_gametes (FILE *fp, const unsigned &segsites, const unsigned &nsam, const gamete_storage_type &gametes)
 Write an object of type gamete_storage type to a C-style file stream This function is used when you need to output simulated gametes using a method faster than the operator<< for class SimData. More...
 
template<typename uniform_generator , typename uniform01_generator , typename exponential_generator , typename poisson_generator >
Sequence::SimData neutral_sample (uniform_generator &uni, uniform01_generator &uni01, exponential_generator &expo, poisson_generator &poiss, const double &theta, const double &rho, const int &nsites, const int &nsam, std::vector< chromosome > *sample, arg *sample_history, unsigned *max_chromosomes=NULL, const unsigned &max_chromosomes_inc=0)
 A simple function to generate samples under a neutral equilibrium model. More...
 
int crossover (const int &current_nsam, const int &chromo, const int &pos, std::vector< chromosome > *sample, arg *sample_history)
 Recombination function. More...
 
std::pair< int, int > pick_uniform_spot (const double &random_01, const int &nlinks, std::vector< chromosome >::const_iterator sample_begin, const unsigned &current_nsam)
 Pick a crossover point for the model where recombination rates are constant across a recion. Picks a positions uniformly amongst all chromosomes at which a recombination event will occur. More...
 
template<typename uniform01_generator >
std::pair< int, int > pick_spot (uniform01_generator &uni01, const double &total_reclen, const std::vector< double > &reclens, std::vector< chromosome >::const_iterator sample_begin, const unsigned &current_nsam, const double *rec_map)
 
template<typename uniform01_generator >
std::pair< int, int > pick_spot (const uniform01_generator &uni01, const double &total_reclen, const std::vector< double > &reclens, std::vector< chromosome >::const_iterator sample_begin, const unsigned &current_nsam, const double *rec_map)
 
std::ostream & operator<< (std::ostream &s, const chromosome &c)
 output operator for chromosome types in coalescent simulation Outputs the segments contained by the chromosome
 
std::ostream & operator<< (std::ostream &s, const marginal &m)
 Write a marginal tree to an ostream.
 
std::ostream & operator<< (std::ostream &o, const newick_stream_marginal_tree &n)
 
std::istream & operator>> (std::istream &i, newick_stream_marginal_tree &n)
 
template<typename uni01_generator >
void ConditionalTraj (uni01_generator &uni01, std::vector< double > *traj, const unsigned &N, const double &s, const double &dt, const double &initial_frequency, const double &final_frequency=1.)
 
template<typename uni01_generator >
void ConditionalTraj (const uni01_generator &uni01, std::vector< double > *traj, const unsigned &N, const double &s, const double &dt, const double &initial_frequency, const double &final_frequency=1.)
 
template<typename uni01_generator >
void ConditionalTrajNeutral (uni01_generator &uni01, std::vector< double > *traj, const double &dt, const double &initial_freq=1., const double &final_freq=0.)
 
template<typename uni01_generator >
void ConditionalTrajNeutral (const uni01_generator &uni01, std::vector< double > *traj, const double &dt, const double &initial_freq=1., const double &final_freq=0.)
 
double total_time (const marginal::const_iterator beg, const int &nsam)
 Calculate total time on a marginal tree. More...
 
int pick_branch (marginal::const_iterator beg, const int &nsam, const double &rtime)
 pick a random branch of a marginal tree More...
 
std::vector< int > get_all_descendants (marginal::const_iterator beg, const int &nsam, const int &branch)
 Find all the descendants of a branch on a marginal tree. More...
 
bool is_descendant (marginal::const_iterator beg, const int &ind, const int &branch)
 Ask if a tip of a tree is a descendant of a particular branch. More...
 
double total_time_on_arg (const Sequence::coalsim::arg &sample_history, const int &total_number_of_sites)
 Returns the total time on an ancestral recombination graph. More...
 
void minimize_arg (arg *sample_history)
 

Variables

MAX_SEG_T MAX_SEGSITES
 controls allocation of simulated gametes You must define this in namespace Sequence in your program. A value of 200 works well.
 
MAX_SEG_T MAX_SEGS_INC
 controls (re)allocation of simulated gametes You must define this in namespace Sequence in your program. A value of 100 works well
 

Detailed Description

Routines for coalescent simulation.

Function Documentation

◆ ConditionalTraj() [1/2]

template<typename uni01_generator >
void Sequence::coalsim::ConditionalTraj ( uni01_generator &  uni01,
std::vector< double > *  traj,
const unsigned &  N,
const double &  s,
const double &  dt,
const double &  initial_frequency,
const double &  final_frequency = 1. 
)

Generate a trajectory for an additive beneficial mutation with selection coefficient "s", follwing the method of Coop and Griffiths [Coop:2004dk]

Parameters
uni01Generates doubles on the interval [0,1)
trajThis will contain the trjactory. It is cleared by the function.
NThe population size (keep it small, <= 10^4 or so)
sThe selection coefficient
dtDetermines the time scale
initial_frequencyThe starting frequency of the beneficial mutation
final_frequencyThe final_frequency of the beneficial mutation
Note
Upon return, traj contains frequency values starting at final_frequency and ending at initial_frequency

◆ ConditionalTraj() [2/2]

template<typename uni01_generator >
void Sequence::coalsim::ConditionalTraj ( const uni01_generator &  uni01,
std::vector< double > *  traj,
const unsigned &  N,
const double &  s,
const double &  dt,
const double &  initial_frequency,
const double &  final_frequency = 1. 
)

Generate a trajectory for an additive beneficial mutation with selection coefficient "s", follwing the method of Coop and Griffiths [Coop:2004dk]

Parameters
uni01Generates doubles on the interval [0,1)
trajThis will contain the trjactory. It is cleared by the function.
NThe population size (keep it small, <= 10^4 or so)
sThe selection coefficient
dtDetermines the time scale
initial_frequencyThe starting frequency of the beneficial mutation
final_frequencyThe final_frequency of the beneficial mutation
Note
Upon return, traj contains frequency values starting at final_frequency and ending at initial_frequency

◆ ConditionalTrajNeutral() [1/2]

template<typename uni01_generator >
void Sequence::coalsim::ConditionalTrajNeutral ( uni01_generator &  uni01,
std::vector< double > *  traj,
const double &  dt,
const double &  initial_freq = 1.,
const double &  final_freq = 0. 
)

Generate a trajectory for a neutral mutation via the method of Przeworski et al. (2005) [Przeworski:2005ef]

Parameters
uni01Generates doubles on the interval [0,1)
trajThis will contain the trjactory. It is cleared by the function.
dtDetermines the time scale
initial_frequencyThe starting frequency of the beneficial mutation
final_frequencyThe final_frequency of the beneficial mutation
Note
Upon return, traj contains frequency values starting at final_frequency and ending at initial_frequency

◆ ConditionalTrajNeutral() [2/2]

template<typename uni01_generator >
void Sequence::coalsim::ConditionalTrajNeutral ( const uni01_generator &  uni01,
std::vector< double > *  traj,
const double &  dt,
const double &  initial_freq = 1.,
const double &  final_freq = 0. 
)

Generate a trajectory for a neutral mutation via the method of Przeworski et al. (2005) [Przeworski:2005ef],

Parameters
uni01Generates doubles on the interval [0,1)
trajThis will contain the trjactory. It is cleared by the function.
dtDetermines the time scale
initial_frequencyThe starting frequency of the beneficial mutation
final_frequencyThe final_frequency of the beneficial mutation
Note
Upon return, traj contains frequency values starting at final_frequency and ending at initial_frequency

◆ minimize_arg()

void Sequence::coalsim::minimize_arg ( Sequence::coalsim::arg sample_history)

Takes an arg (Ancestral Recombination Graph) and removes redundant marginal trees. Specifically, for two adjacent trees i and j (j->beg > i->beg), j is removed from the arg if the topology and branch lengths of i and j are identical.

Parameters
sample_historythe arg to minimize

Definition at line 169 of file CoalescentTreeOperations.cc.

◆ operator<<()

std::ostream & Sequence::coalsim::operator<< ( std::ostream &  o,
const newick_stream_marginal_tree n 
)
Returns
n.print(o);

Definition at line 461 of file CoalescentSimTypes.cc.

◆ operator>>()

std::istream & Sequence::coalsim::operator>> ( std::istream &  i,
newick_stream_marginal_tree n 
)
Returns
n.read(o);

Definition at line 469 of file CoalescentSimTypes.cc.

◆ output_gametes()

void Sequence::coalsim::output_gametes ( FILE *  fp,
const unsigned &  segsites,
const unsigned &  nsam,
const gamete_storage_type gametes 
)

Write an object of type gamete_storage type to a C-style file stream This function is used when you need to output simulated gametes using a method faster than the operator<< for class SimData.

Parameters
fppointer to an open C-style output stream
segsitesthe number of segregating sites in gametes
nsamthe number of individuals in gametes
gametesthe simulated sample. Must be allocated to hold at least segsites positions, and nsam strings of length segsites

Definition at line 29 of file CoalescentMutation.cc.