In [1]:
from __future__ import print_function
import fwdpy as fp
import pandas as pd
from background_selection_setup import *
Get the mutations that are segregating in each population:
In [2]:
mutations = [fp.view_mutations(i) for i in pops]
Look at the raw data in the first element of each list:
In [3]:
for i in mutations:
print(i[0])
Let's make that nicer, and convert each list of dictionaries to a Pandas DataFrame object:
In [4]:
mutations2 = [pd.DataFrame(i) for i in mutations]
In [5]:
for i in mutations2:
print(i.head())
The columns are:
We can do all the usual subsetting, etc., using regular pandas tricks. For example, let's get the neutral mutations for each population:
In [6]:
nmuts = [i[i.neutral == True] for i in mutations2]
for i in nmuts:
print(i.head())
We can also take views of gametes:
In [7]:
gametes = [fp.view_gametes(i) for i in pops]
The format is really ugly. v Each gamete is a dict with two elements:
In [8]:
for i in gametes:
print(i[0])
OK, let's clean that up. We'll focus on the selected mutations for each individual, and turn everything into a pd.DataFrame.
We're only going to do this for the first simulated population.
In [9]:
smuts = [i['selected'] for i in gametes[0]]
We now have a list of lists stored in 'smuts'.
In [10]:
smutsdf = pd.DataFrame()
ind=0
##Add the non-empty individuals to the df
for i in smuts:
if len(i)>0:
smutsdf = pd.concat([smutsdf,pd.DataFrame(i,index=[ind]*len(i))])
ind += 1
In [11]:
smutsdf.head()
Out[11]:
That's much better. We can use the index to figure out which individual has which mutations, and their effect sizes, etc.
Finally, we can also take views of diploids. Let's get the first two diploids in each population:
In [12]:
dips = [fp.view_diploids(i,[0,1]) for i in pops]
Again, the format here is ugly. Each diploid view is a dictionary:
In [13]:
for key in dips[0][0]:
print(key)
The values are:
Please note that g, e, and w, may or may not be set by a particular simulation. Their use is optional.