The simulation code simtree.py
will be available in our public GitHub. Here, a few examples of the output are shown. The key code is given in the snippet in Figure 1. Figure 2 gives examples for two populations with different
# generates Mittag-Leffler time interval based on mylambda and alpha
# for each evolutionary force: Theta_1, Theta_2, M_21, M_12
# for the future, I assume this also will work for growth and population divergence
# with the correct lambda
def randommlftime(mylambda, alpha):
pia = 3.1415926 * alpha
r1 = np.random.uniform(0,1)
r2 = np.random.uniform(0,1)
denoma = 1.0 / alpha
denomlambda = 1.0 / mylambda
return -denomlambda**denoma *
(np.sin(pia)/(np.tan(pia*(1.0-r1)))-np.cos(pia))**denoma *
np.log(r2)
# creates the time for a migration or coalescent event,
# evaluating the time intervals for each force and picks the smallest
# looping through Y , the alphas vector here needs and entry for every force
# see the function fill_Yalphas()
def randomtime(Y,alphas,t0):
smallu = 1e100
for yi,ai in zip(Y,alphas):
u = randommlftime(yi,ai)
if u < smallu:
smallu = u
return t0 + smallu
usage: simtree.py [-h] [-l LOCI] [-s SITES] [-i INDIVIDUALS] [-t THETA] [-m MIG]
[-a ALPHA] [-f FILE] [-p]
Simulate a tree
options:
-h, --help show this help message and exit
-l LOCI, --loci LOCI number of loci
-s SITES, --sites SITES
number of sites
-i INDIVIDUALS, --individuals INDIVIDUALS
Number of samples for each population
-t THETA, --theta THETA
thetas for each population
-m MIG, --mig MIG immigration rate matrix the diagonal values are ignored
so for two population specify: 0,100,100,0; for 3
populations stepping stone: 0,100, 0,0,0,100,0,0,0, this
is from 3->2->1; there need to be n*n values!
-a ALPHA, --alpha ALPHA
alpha for each population
-f FILE, --file FILE treefile to be used with migdata, default is NONE which
is a placeholder for sys.stdout
-p, --plot Plots density histogram of TMRCA
Example: 3 populations with stepping stone migration one-way from 3->2->1 all with alpha=0.9
python simtree.py -i 5,5,5 -l 2 -t 0.01,0.01,0.01 -m 0,1,0,0,0,1,0,0,0 -a 0.9,0.9,0.9 -f test.tre