Esempio n. 1
0
    def test_CompareUsingView(self):
        """
        Evolve some population, take samples,
        get details of those samples, make sure
        those details match up what 'views' think should
        be in the population.
        """
        samples = [fp.get_samples(rng,i,100) for i in pops]
        
        details = [fp.get_sample_details(i[1],j) for i,j in zip(samples,pops)]



        ##For each element in details,
        ##find it in the "mutation view" for that replicate
        for i in range(len(samples)):
            ##Make sure that lengths match up
            for key in details[i]:
                self.assertEqual(len(samples[i][1]),len(details[i][key]))
            for j in range(len(samples[i][1])):
                mm=[X for X in mviews[i] if X['pos'] == samples[i][1][j][0]]
                ##Make sure each position is uniuqe
                self.assertEqual(len(mm),1)
                for mmi in mm:
                    ##Make sure that the position is equal to what we expect
                    self.assertEqual(mmi['pos'],samples[i][1][j][0])
                    ##Make sure selection coefficient matches up
                    self.assertEqual(mmi['s'],details[i]['s'][j])
                    EP=mmi['n']/float(2000) #"expected" frequency
                    self.assertEqual(EP,details[i]['p'][j])
Esempio n. 2
0
for i in samples[:4]:
    print ("A sample from a population is a ",type(i))
    
print(len(samples))


# ### Getting additional information about samples

# In[10]:

#Again, use list comprehension to get the 'details' of each sample
#Given that each object in samples is a tuple, and that the second
#item in each tuple represents selected mutations, i[1] in the line
#below means that we are getting the mutation information only for
#selected variants
details = [fp.get_sample_details(i[1],j) for i,j in zip(samples,pops)]


# In[11]:

#details is now a list of pandas DataFrame objects
#Each DataFrame has the following columns:
#  a: mutation age (in generations)
#  h: dominance of the mutation
#  p: frequency of the mutation in the population
#  s: selection coefficient of the mutation
#  label: A label applied for mutations for each region.  Here, I use 0 for all regions
for i in details[:4]:
    print(i)

Esempio n. 3
0
print "S per sample =",segsites

#number of singletons per sample
nsing = [countDerived(si[0]) for si in s]
print "No. singletons per sample =",nsing

## remove the non-singleton sites from each sample
sAllSing = [filter( lambda x: isSingleton(x) == True, j[0] ) for j in s]
print "No. singletons per sample =",[len(i) for i in sAllSing]

##Remove the singletons
sNoSing = [filter( lambda x: isSingleton(x) == False, j[0] ) for j in s]
print "No. non-singletons per sample =",[len(i) for i in sNoSing]

##Get xtra info for each mutation in the sample
sh = [fwdpy.get_sample_details(i[0],j) for i,j in zip(s,pop)]

##Add a column to each DataFrame specifying the mutation position, count of derived state, and a "replicate ID"
for i in range(len(sh)):
    sh[i]['pos']=[x[0] for x in s[i][0]]
    sh[i]['freq']=[ x[1].count('1') for x in s[i][0]]
    sh[i]['id']=[i]*len(sh[i].index)

##Write all DataFrames to a file
pandas.concat(sh).to_csv("test.csv",sep="\t",index=False)

##Now, evolve them some more and end with a bottleneck + recent, partial recovery
fwdpy.evolve_pops_more_t(rng,pop,[1000]*int(1e4) + [500]*100 + [750]*10,50,50)

##Check that all is cool with the data structures...
for i in range(len(pop)):
Esempio n. 4
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)
Esempio n. 5
0
#popsizes are NumPy arrays of 32bit unsigned integers
popsizes = np.array([1000],dtype=np.uint32)
popsizes = np.tile(popsizes,10*1000)

pops = fwdpy.evolve_regions(rng,3,1000,popsizes[0:],0.001,0.0001,0.001,nregions,sregions,rregions)
s = [fwdpy.get_samples(rng,i,[10,]) for i in pops]

for i in range(len(s)):
    print s[i],"\n\n"

print [i.gen() for i in pops]

fwdpy.evolve_regions_more(rng,pops,popsizes[0:],0.001,0.0001,0.001,nregions,sregions,rregions)

s = [fwdpy.get_samples(rng,i,[10,]) for i in pops]

for i in range(len(s)):
    print s[i],"\n\n"


print [i.gen() for i in pops]
print [i.sane() for i in pops]
print [i.popsize() for i in pops]

##Not get more info for selected mutations

info = [fwdpy.get_sample_details(i[1],j) for i,j in zip(s,pops)]

print info