Exemple #1
0

# In[6]:

#Initalize a random number generator with seed value of 101
rng = fp.GSLrng(101)


# In[7]:

#Simulate 40 replicate populations.  This uses C++11 threads behind the scenes:
pops = fp.evolve_regions(rng,       #The random number generator 
                         40,         #The number of pops to simulate = number of threads to use.
                         N,         #Initial population size for each of the 40 demes
                         nlist[0:], #List of population sizes over time.
                         0.005,     #Neutral mutation rate (per gamete, per generation)
                         0.01,      #Deleterious mutation rate (per gamete, per generation)
                         0.005,     #Recombination rate (per diploid, per generation)
                         nregions,  #Defined above
                         sregions,  #Defined above
                         recregions)#Defined above


# In[8]:

#Now, pops is a Python list with len(pops) = 40
#Each element's type is fwdpy.singlepop
print(len(pops))
print(type(pops[0]))
                

Exemple #2
0
#The first part is the same as the example for fwdpy.evolve_regions
import fwdpy
import numpy as np
nregions = [fwdpy.Region(0,1,1),fwdpy.Region(2,3,1)]
sregions = [fwdpy.ExpS(1,2,1,-0.001,0.0),fwdpy.ExpS(1,2,0.01,0.001)]
rregions = [fwdpy.Region(0,3,1)]
rng = fwdpy.GSLrng(100)
popsizes = np.array([1000],dtype=np.uint32)
# Evolve for 5N generations initially
popsizes=np.tile(popsizes,10000)
pops = fwdpy.evolve_regions(rng,1,1000,popsizes[0:],0.001,0.01,0.001,nregions,sregions,rregions)
#Now, "bud" off a daughter population of same size, and evolve both for another 100 generations
mpops = fwdpy.evolve_regions_split(rng,pops,popsizes[0:100],popsizes[0:100],0.001,0.0001,0.001,nregions,sregions,rregions)
samples = [fwdpy.get_samples(rng,i,[10,10]) for i in mpops]

details = [ fwdpy.get_sample_details(rng,i[1],j)
Exemple #3
0

# In[27]:

#set up our sim
rng = fp.GSLrng(101)
nregions = [fp.Region(0,1,1),fp.Region(2,3,1)]
sregions = [fp.ExpS(1,2,1,-0.1),fp.ExpS(1,2,0.1,0.001)]
rregions = [fp.Region(0,3,1)]
popsizes = np.array([1000]*10000,dtype=np.uint32)


# In[28]:

#Run the sim
pops = fp.evolve_regions(rng,4,1000,popsizes[0:],0.001,0.0001,0.001,nregions,sregions,rregions)


# In[29]:

#Take samples from the simulation
samples = [fp.get_samples(rng,i,20) for i in pops]


# ## Calculating sliding windows
# 
# We are going to want non-overlapping widwos of size 0.1.
# 
# One thing to keep track of is the total size of our region, which is the half-open interval $[0,3)$
# 
# ### Manual method
theta=100.0
rho=100.0

mutrate_neutral = theta/float(4*N)
mutrate_sel = 0.0
recrate = rho/float(4*N)

rng = fp.GSLrng(101)

#Evolve 20 populations to mutation-drift equilibrium
pops = fp.evolve_regions(rng,20,
                         nlist[0],
                         nlist,
                         mutrate_neutral,
                         mutrate_sel,
                         recrate,
                         nregions,
                         sregions,
                         recregions)

#Change a mutation's selection coefficient
for i in pops:
    x=csp.change_selection_coeff(i,0.5,10,0.1,0.25)
    #print out count and position of variant actually changed
    print (x)

#Get the list of mutations in each population
views = [pd.DataFrame(i) for i in fp.view_mutations(pops)]

for i in views:
Exemple #5
0
import fwdpy as fp
import numpy as np
rng = fp.GSLrng(101)
N=1000
nlist=np.array([N]*10*N,dtype=np.uint32)
p=fp.evolve_regions(rng,
                    64,N,
                    nlist,
                    0.25,
                    0.0,
                    0.25,
                    [fp.Region(0,1,1)],
                    [],
                    [fp.Region(0,1,1)])
#p.append(p2)
#print len(p)
#v = fp.view_diploids_pd(p,range(0,N,1))
#v=[fp.view_diploids(i,range(0,N,1)) for i in p]
#b = fp.view_diploids_pd(p,range(0,N,1))
#print b
#for i in v:
#    print i
#g = [i.gen() for i in p]
#print g

#d = fp.view_diploids(p,[0,1])

#print d
     
 def test_nonFiniteNonNeutralMutationRate(self):
     with self.assertRaises(RuntimeError):
         pops = fwdpy.evolve_regions(rng,1,1000,popsizes[0:],0.001,np.nan,0.001,nregions,sregions,rregions)
 def test_nonFiniteRecRate(self):
     with self.assertRaises(RuntimeError):
         pops = fwdpy.evolve_regions(rng,1,1000,popsizes[0:],0.001,0.001,np.inf,nregions,sregions,rregions)
Exemple #8
0
import unittest
import fwdpy
import numpy as np

nregions = [fwdpy.Region(0, 1, 1), fwdpy.Region(2, 3, 1)]
sregions = [fwdpy.ExpS(1, 2, 1, -0.1), fwdpy.ExpS(1, 2, 0.01, 0.001)]
rregions = [fwdpy.Region(0, 3, 1)]
rng = fwdpy.GSLrng(100)
N = 1000
NGENS = 100
popsizes = np.array([N], dtype=np.uint32)
popsizes = np.tile(popsizes, NGENS)
pops = fwdpy.evolve_regions(rng, 1, N, popsizes[0:], 0.001, 0.0001, 0.001,
                            nregions, sregions, rregions)

#The sum of the gamete counts must be 2*(deme size):
#mpops = fwdpy.evolve_regions_split(rng,pops,popsizes[0:],popsizes[0:],0.001,0.0001,0.001,nregions,sregions,rregions,[0]*2)


class test_singlepop_views(unittest.TestCase):
    def testNumGametes(self):
        gams = fwdpy.view_gametes(pops[0])
        nsingle = 0
        for i in gams:
            nsingle += i['n']
        self.assertEqual(nsingle, 2000)

    def testDipsize(self):
        dips_single = fwdpy.view_diploids(pops[0], [0, 1, 2])
        self.assertEqual(len(dips_single), 3)
 def test_negativeNeutralMutationRate(self):
     with self.assertRaises(RuntimeError):
         pops = fwdpy.evolve_regions(rng,1,1000,popsizes[0:],-0.001,0.0001,0.001,nregions,sregions,rregions)
 def test_nonFiniteRecRate(self):
     with self.assertRaises(RuntimeError):
         pops = fwdpy.evolve_regions(rng, 1, 1000, popsizes[0:], 0.001,
                                     0.001, np.inf, nregions, sregions,
                                     rregions)
 def test_nonFiniteNonNeutralMutationRate(self):
     with self.assertRaises(RuntimeError):
         pops = fwdpy.evolve_regions(rng, 1, 1000, popsizes[0:], 0.001,
                                     np.nan, 0.001, nregions, sregions,
                                     rregions)
 def test_negativeNeutralMutationRate(self):
     with self.assertRaises(RuntimeError):
         pops = fwdpy.evolve_regions(rng, 1, 1000, popsizes[0:], -0.001,
                                     0.0001, 0.001, nregions, sregions,
                                     rregions)
Exemple #13
0
      "/", dt.day, "/", dt.year)
print("The dependency versions are", fp.pkg_dependencies())

# In[27]:

#set up our sim
rng = fp.GSLrng(101)
nregions = [fp.Region(0, 1, 1), fp.Region(2, 3, 1)]
sregions = [fp.ExpS(1, 2, 1, -0.1), fp.ExpS(1, 2, 0.1, 0.001)]
rregions = [fp.Region(0, 3, 1)]
popsizes = np.array([1000] * 10000, dtype=np.uint32)

# In[28]:

#Run the sim
pops = fp.evolve_regions(rng, 4, 1000, popsizes[0:], 0.001, 0.0001, 0.001,
                         nregions, sregions, rregions)

# In[29]:

#Take samples from the simulation
samples = [fp.get_samples(rng, i, 20) for i in pops]

# ## Calculating sliding windows
#
# We are going to want non-overlapping widwos of size 0.1.
#
# One thing to keep track of is the total size of our region, which is the half-open interval $[0,3)$
#
# ### Manual method
#
# Let's just do it using pure Python:
Exemple #14
0
import fwdpy as fp
import numpy as np

rng = fp.GSLrng(101)
N = 1000
nlist = np.array([N] * 10 * N, dtype=np.uint32)
p = fp.evolve_regions(rng, 64, N, nlist, 0.25, 0.0, 0.25, [fp.Region(0, 1, 1)], [], [fp.Region(0, 1, 1)])
# p.append(p2)
# print len(p)
# v = fp.view_diploids_pd(p,range(0,N,1))
# v=[fp.view_diploids(i,range(0,N,1)) for i in p]
# b = fp.view_diploids_pd(p,range(0,N,1))
# print b
# for i in v:
#    print i
# g = [i.gen() for i in p]
# print g

# d = fp.view_diploids(p,[0,1])

# print d