Let's evolve 40 populations to mutation-drift equilibrium:
In [1]:
import fwdpy as fp
import numpy as np
import pandas as pd
nregions=[fp.Region(0,1,1)]
sregions=[fp.GammaS(0,1,0.1,0.1,0.1,1.0),
fp.GammaS(0,1,0.9,-0.2,9.0,0.0)
]
recregions=nregions
N=1000
nlist=np.array([N]*(10*N),dtype=np.uint32)
mutrate_neutral=50.0/float(4*N)
recrate=mutrate_neutral
mutrate_sel=mutrate_neutral*0.2
rng=fp.GSLrng(101)
pops=fp.SpopVec(40,1000)
sampler=fp.NothingSampler(len(pops))
#This function implicitly uses a "nothing sampler"
fp.evolve_regions_sampler(rng,pops,sampler,nlist,
mutrate_neutral,
0.0, #No selected mutations....
recrate,
nregions,sregions,recregions,
#Only sample every 10N generations,
#which is fine b/c we're not sampling anything
10*N)
In [2]:
#Take sample of size n=20
sampler=fp.PopSampler(len(pops),20,rng)
fp.evolve_regions_sampler(rng,pops,sampler,
nlist[:N], #Evolve for N generations
mutrate_neutral,
mutrate_sel,
recrate,
nregions,sregions,recregions,
#Sampler every 100 generations
100)
The output from this particular sampler type is a generator. Let's look at the first element of the first sample:
In [4]:
data=sampler[0]
In [5]:
print data[0]
These "genotypes" blocks can be used to caculate summary statistics. See the example on using pylibseq for that task.
In [6]:
print data[1]
Each element in d[0] is a tuple:
In [7]:
#The first element are the genotypes
data[0][0]
Out[7]:
In [9]:
#The first element in the genotypes are the neutral variants.
#The first value is the position. The second value is a string
#of genotypes for chromosomes 1 through n. 0 = ancestral/1=derived
data[0][0][0]
Out[9]:
In [10]:
#Same format for selected variants
data[0][0][1]
Out[10]:
In [12]:
#This is a dict relating to info re:
#the selected variants.
#dcount = derived freq in sample
#ftime = fixation time. 2^32-1 = has not fixed
#generation = generation when sampling occurred
#h = dominance
#origin = generation when mutation entered population
#p = population frequency
#s = effect size/selection coefficient
data[0][1]
Out[12]:
In [ ]:
See the example on fixation times for the use of this sampler