Matlab Functions for Population Genetics :

The following functions were written by me quite a long time ago now to illustrate a number of concepts in population genetics. However, I nonetheless hope they might be of some use to others.
To view any of the functions, click on the link. To save, right click and select 'Save Target As...' or 'Save Link As..." Please pardon the amateurish code. (You should see me code now. . . it's no better!)
Comments and questions should be directed to me via email (lrevell@nescent.org), as I am now at NESCent.
Many, but probably not all, of these should run in the free software package Octave.
Most of the exercises arose out of a reading group on the great book by Sean Rice :
Rice, S. H. 2004. Evolutionary Theory. Sinauer, Sunderland MA.
You should check it out!

pt0_pt1_cobweb.m This function creates an animated cobweb plot of p(t) by p(t+1) under a density independent single locus selection model for an arbitrary number of generations. Compare to Fig 1.1 in the Rice (2004) book.
frequency_dep.m This function creates an animated cobweb plot of p(t) by p(t+1) under a density dependent single locus selection model. This model exhibits wild chaotic behavior under some circumstances. Compare to Fig 1.2 in the Rice (2004) book.
fertility_selection.m This function simulates stochastic fertility selection in which different mating types have different fitness. In this case the mating type Aa x Aa has a fitness of 1 and all other mating types have a fitness of 0.025, following Rice 2004 pp. 28-30. Compare to Fig 1.6 in the Rice (2004) book.
LD_haplotypes.m This function plots the erosion of linkage disequilibrium and the change in haplotype (gamete) frequencies over time. LD_haplotypes_stochastic.m does the same thing but also simulates stochastic drift and recombination and compares that result to the deterministic model.
LD_selection_caseA.m,
LD_selection_caseB.m
These functions recreate particular cases in which the erosion of LD is inhibited by selection, in some cases resulting in quasi-gametic equilibrium. LD_selection_rand.m is useful to illustrate how readily QGE might be achieved. This function assigns genotypic fitnesses at random and QGE is a not uncommon results.
additive_x_additive.m This simple function recreates Fig 2.5 from the Rice 2004 book, plotting additive variance against allele frequencies for two loci exhibiting additive by additive epistasis, while additive_x_dominance.m plots additive variance against allele frequencies for loci exhibiting additive by dominance epistasis. Be sure to view with the 'orbit camera' in the MatLab 'camera toolbar.'
cultural.m This function illustrates the evolutionary dynamics of transmission unhindered by the rules of Mendelian inheritance- eg. cultural transmission. Compare to Fig 2.9 in the Rice 2004 book. 'Rebellion' (or the strong propensity of offspring to adopt a behavioral trait different than their parents if their parents have the same trait) will cause the frequency of the trait to cycle stably.
fast_drift.m This simple function simulates drift in a haploid population of size N by random sampling while drift_movie.m animates the same process.
drift_markov.m This function simulates drift as a Markov process whereby transitions between allele frequency states are assigned probabilities defined by the binomial sampling distribution. The population then changes states according to this transition matrix.
drift_variance.m This function plots the expected variance among populations over time under drift. It also animates the expected distribution of allele frequencies amongst populations over time. Compare to Fig 3.1 in Rice 2004.
drift_randcov.m This function plots the expected variance among populations over time under drift. It also animates the expected distribution of allele frequencies amongst populations over time. Compare to Fig 3.1 in Rice 2004. drift_variance_stoch.m plots the expected variance among populations with that observed under an arbitrary number of stochastically simulated populations.
coalescence.m This function simulates the coalescent process either once or multiple times and calculates a time to coancestry distribution for that single run or an average time to coancestry distribution across multiple runs. This result is plotted with the 'expected' time to coancestry distribution. Compare to Slatkin and Hudson (1991).
harmonic_N.m This function simulates drift and plots the resultant erosion of heterozygosity for a population of varying size over time. It then plots this observation with that predicted by an Ne equivalent to the arithmetic and harmonic means, as well as the exact predicted rate of erosion of heterozygosity. In order to use also download harmmean.m and put it in the same directory.
sexratio_N.m This function simulates drift in populations with unequal sex ratio, plotting the resultant erosion of heterozygosity with that expected under an equal sex ratio and under the sex ratio used in the simulation model.
invariant_fam.m This function simulates drift in a population reproducing with invariant family size. The result is interesting because the rate of erosion of heterozygosity (the effect of drift) takes exactly half the value it would exhibit in a population exhibiting Poisson distributed family size. This indicates that half the effect of drift is due to variation in reproductive success and the other half to random segregation of alleles during meiosis.
famsize_N.m This function simulates drift under varied distributions of family size returning both a plot of the heterozygosity through time and a histogram of the mean distribution of family sizes. It requires a parameter, c, which is effectively a scaling factor which determines the probability of individual reproducing again once it has reproduced once. If c=1, this is just the Wright-Fisher model. If c>1 the distribution is more skewed, if c<1, less.

Not my car, however, among possible vanity plates, I appreciate this one.
If you object to my use of this image, please let me know.
Research  |   Computer Programs  |   Pictures  |   NESCent Home

Last updated Aug. 30, 2009.