Hi Ryan,
I made some progress but still ran into this error message.
raise ValueError('Dimensionality of phi and lengths of ns and xxs '
ValueError: Dimensionality of phi and lengths of ns and xxs do not all agree.
I wonder if it's caused by being given a 3D sfs but is asked to return a 2D sfs because of the admixture event. Any insights is much appreciated!
Below are the relevant codes. Basically, the history is 1 (SB) split from 2+3 (SR+SN), then 2 & 3 split, then 1 & 2 become admixed/fused and 3 continues on its own, leaving 2 final populations. While this is going on, there's symmetrical gene flow between pairs of populations.
HC
def model_func(params, ns, pts):
# 14 parameters:
nu_SB, nu_SRSN, nu_SR, nu_SN, nu_SBSR, T1, T2, T3, m_SB_SRSN, m_SB_SR, m_SB_SN, m_SR_SN, m_SBSR_SN, f2 = params
xx = dadi.Numerics.default_grid(pts)
phi = dadi.PhiManip.phi_1D(xx)
# Phase 2: Split into two populations (SB and SR-SN); initialize 2D phi.
phi = dadi.PhiManip.phi_1D_to_2D(xx, phi)
phi = dadi.Integration.two_pops(phi, xx, T1, nu1=nu_SB, nu2=nu_SRSN, m12=m_SB_SRSN, m21=m_SB_SRSN)
# Phase 3: At time T2, split population SRSN into two populations (SR and SN)
phi = dadi.PhiManip.phi_2D_to_3D_split_2(xx, phi)
phi = dadi.Integration.three_pops(phi, xx, T2, nu1=nu_SB, nu2=nu_SR, nu3=nu_SN,
m12=m_SB_SR, m21=m_SB_SR,
m13=m_SB_SN, m31=m_SB_SN,
m23=m_SR_SN, m32=m_SR_SN)
phi = dadi.PhiManip.phi_3D_admix_2_and_3_into_1(phi, f2, 0, xx, xx, xx) #only pop2 admix with 1
# Phase 6: Remove population SR (population 2).
phi = dadi.PhiManip.remove_pop(phi, xx, 2)
# Phase 7: Integrate for time T3 with two populations (SB+SR and SN) with migration rate m2.
phi = dadi.Integration.two_pops(phi, xx, T3, nu1=nu_SBSR, nu2=nu_SN, m12=m_SBSR_SN, m21=m_SBSR_SN)
# Finally, generate the frequency spectrum for populations SB and SN.
fs = dadi.Spectrum.from_phi(phi, ns, (xx, xx))
return fs