Coalescence with positive selection
FFPopSim can be used to track the genealogy of the population at specified loci. This feature allows to explore how the shape of genealogical trees depends on population parameters. The script genealogies_with_selection.py does exactly that (download it here). Typical output of the script is reproduced below and discussed briefly. The script uses the infinite sites mode of FFPopSim, in which L loci are kept polymorphic by introducing a new mutation whenever the previous mutation fixed or was lost. The crucial parts of the script are the following:
L = 1000 #number of segregating sites
s = 1e-2 #single site effect
N = 2000 #population size
r = 0.0 #outcrossing rate
sample_size=30 #number of individuals whose genealogy is looked at
nsamples = 3 #number of trees
burnin = 2000 #a few times the expected coalescence time
dt = 1000 #time between samples
#set the effect sizes of the mutations that are injected (the same at each site in this case)
pop.set_fitness_additive(np.ones(L)*0.5*s)
#track the genealogy at a central locus L/2 (which one doesn't matter in the asexual case)
pop.track_locus_genealogy([L/2])
for si in xrange(nsamples):
#evolve a while before sampling the next tree
pop.evolve(dt)
#draw a sample from the population, convert to a BioPython tree object and plot
tree = pop.genealogy.get_tree(L/2)
subtree = tree.create_subtree_from_keys(rd.sample(tree.leafs,sample_size)).to_Biopython_tree()
subtree.ladderize()
plt.subplot(3,1,si+1)
Phylo.draw(subtree,label_func=lambda x:"")
plt.draw()
Strong positive selection
To demonstrate how selection speeds up coalescence, we simulate a population of size N=10000 with 1000 loci, each of which contributes a selection differential of s=0.01.The most recent common ancestor is found in roughly 200 generations, despite the fact that the population size is N=10000. Furthermore, the shape of the trees is rather different. There are long terminal branches and often very skewed branching. Sometimes, several lineages coalesce almost at the same time, corresponding to approximate multiple mergers.
Neutral comparison
The following shows three trees sampled from an almost neutrally evolving population of size 200.As expected for approximately neutral coalescence, most coalescence happens early and the trees are rather balanced. The time to the most recent common ancestor is of the order of the population size. Open the script in your favorite text editor, change parameters, and rerun to explore.