Hello Ryan,
I'm really new to dadi and to python so it may be that this issue has in fact a simple answer.
I'm trying to get the likelihood for a simple IM model using a sample data of ca. 700 SNPs. My sample size is of 10 and 9 (2 pops), without outgroup information and both are projected down to 7 (data is from haploids).
When I try to fit the data to an IM model without migration, everything seems to work just fine and I get parameters optimized and both model and optimized likelihoods.
The model without migration is defined as:
def IM_no_mig(params, ns, pts):
s, nu1, nu2, T = params
xx = Numerics.default_grid(pts)
phi = PhiManip.phi_1D(xx)
phi = PhiManip.phi_1D_to_2D(xx , phi)
phi = Integration.two_pops(phi , xx , T, nu1 , nu2)
model_sfs = Spectrum.from_phi(phi , ns , (xx ,xx))
return model_sfs
However when I try to put migration in this model (I guess this would correspond to continuous migration):
def IM(params, ns, pts):
s,nu1,nu2,T,m12,m21 = params
xx = Numerics.default_grid(pts)
phi = PhiManip.phi_1D(xx)
phi = PhiManip.phi_1D_to_2D(xx, phi)
phi = Integration.two_pops(phi, xx, T, nu1, nu2, m12=m12, m21=m21)
fs = Spectrum.from_phi(phi, ns, (xx,xx))
return fs
it happens a strange error that I can not trace back...
Traceback (most recent call last):
File "./test-dadi.py", line 105, in <module>
ll_model = dadi.Inference.ll_multinom(model, fs)
File "/usr/lib64/python2.7/site-packages/dadi-1.6.3-py2.7-linux-x86_64.egg/dadi/Inference.py", line 388, in ll_multinom
ll_arr = ll_multinom_per_bin(model, data)
File "/usr/lib64/python2.7/site-packages/dadi-1.6.3-py2.7-linux-x86_64.egg/dadi/Inference.py", line 372, in ll_multinom_per_bin
return ll_per_bin(theta_opt*model, data)
File "/usr/lib64/python2.7/site-packages/dadi-1.6.3-py2.7-linux-x86_64.egg/dadi/Inference.py", line 326, in ll_per_bin
if data.folded and not model.folded:
AttributeError: 'MaskedArray' object has no attribute 'folded'
The code I'm using is the following and I've also attached the data:
import numpy
from numpy import array
import scipy
import dadi
import models
dd = dadi.Misc.make_data_dict("data.dadi")
nproj = [7, 7]
fs = dadi.Spectrum.from_data_dict(dd, ['Pop1','Pop2'], nproj, polarized=False)
ns = fs.sample_sizes
pts_l = [20,30,40]
func = models.IM
params = array([0.5, 5, 5, 5, 10, 10])
upper_bound = [1, 10, 10, 10, 20, 20]
lower_bound = [1e-3, 1e-3, 1e-3, 0, 0, 0]
func_ex = dadi.Numerics.make_extrap_log_func(func)
model = func_ex(params, ns, pts_l)
ll_model = dadi.Inference.ll_multinom(model, fs)
Using IPython, if I see the spectrum for the data it seems to be fine and folded
Spectrum([[-- 163.2079089506176 64.08923611111122 33.95335648148154
28.451504629629685 14.389930555555557 14.689699074074081
2.9186921296296306]
[163.31878858024706 26.8812114197531 11.697569444444447 5.653356481481482
4.36400462962963 4.591319444444446 4.432118055555557 --]
[58.634143518518535 17.535300925925952 9.499652777777786 7.398495370370377
6.398032407407413 2.772395833333336 -- --]
[28.726273148148138 9.94039351851853 11.789930555555568 7.4461805555555625
3.1258680555555585 -- -- --]
[13.264467592592599 9.308449074074087 8.897569444444455 3.1258680555555585
-- -- -- --]
[7.5723379629629655 8.475578703703716 2.772395833333336 -- -- -- -- --]
[4.098958333333332 4.432118055555557 -- -- -- -- -- --]
[2.9186921296296306 -- -- -- -- -- -- --]], folded=True, pop_ids=['Pop1', 'Pop2'])
but the spectrum for the model is unfolded?! and of course empty.
Spectrum([[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]
[-- -- -- -- -- -- -- --]], folded=False, pop_ids=None)
Do you know why is this happening and what do I have to do to fix this issue?
Many thanks,
Pedro