def IM2(params, ns, pts): """ ns = (n1,n2) params = (nu01,nu02,nu1,nu2,T,m12,m21) Isolation-with-migration model with exponential pop growth. Populations split into sizes nu01 and nu02. nu1: Final size of pop 1. nu2: Final size of pop 2. T: Time in the past of split (in units of 2*Na generations) m12: Migration from pop 2 to pop 1 (2*Na*m12) m21: Migration from pop 1 to pop 2 n1,n2: Sample sizes of resulting Spectrum pts: Number of grid points to use in integration. """ nu01, nu02, nu1, nu2, T, m12, m21 = params xx = Numerics.default_grid(pts) phi = PhiManip.phi_1D(xx) phi = PhiManip.phi_1D_to_2D(xx, phi) nu1_func = lambda t: nu01 * (nu1 / nu01)**(t / T) nu2_func = lambda t: nu02 * (nu2 / nu02)**(t / T) phi = Integration.two_pops(phi, xx, T, nu1_func, nu2_func, m12=m12, m21=m21) fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def s2mM(params, ns, pts): 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
def twoEpochFixedT(params, ns, pts): nu = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop( phi, xx, 0.001, nu) # contraction for set duration of ~10 generations fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def bottleneck(params, ns, pts): nuB,nuF,TB,TF = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, TB, nuB) # bottleneck phi = Integration.one_pop(phi, xx, TF, nuF) # recovery fs = Spectrum.from_phi(phi, ns, (xx,)) return fs
def fourEpoch(params, ns, pts): nuBOT, nuREC, nuCUR = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.013, nuBOT) # bottleneck 1 phi = Integration.one_pop(phi, xx, 0.024, nuREC) # recovery 1 phi = Integration.one_pop(phi, xx, 0.0013, nuCUR) # contraction fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def fourEpoch(params, ns, pts): nu2, t2 = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.25, 2) phi = Integration.one_pop(phi, xx, t2, nu2) phi = Integration.one_pop(phi, xx, 0.036, 8) fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def fourEpoch(params, ns, pts): nuREC, nuCUR, tREC, tCUR = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.015, 0.23) phi = Integration.one_pop(phi, xx, tREC, nuREC) phi = Integration.one_pop(phi, xx, tCUR, nuCUR) fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def bottleneck_fixedDur(params, ns, pts): TB, TF = params # removed TB because that is fixed at fixed DUR xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop( phi, xx, TB, 0.01) # replace TB with fixed duration fors bottleneck phi = Integration.one_pop(phi, xx, TF, 0.1) # recovery fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def fourEpoch(params, ns, pts): t3, nu3 = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.00675, 0.05) phi = Integration.one_pop(phi, xx, 0.045, 26) phi = Integration.one_pop(phi, xx, t3, nu3) fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def split_3epoch_nomig(params, ns, pts): nu1,t1,nuIR,nuMN = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, t1, nu1) phi = PhiManip.phi_1D_to_2D(xx, phi) # split into two pops phi = Integration.two_pops(phi, xx, 0.0008, nuIR, nuMN, m12=0, m21=0) # two pops at diff sizes with symmetric migration fs = Spectrum.from_phi(phi, ns, (xx,xx)) return fs
def double_bottleneck(params, ns, pts): nuB1, nuF1, nuB2, nuF2, TB1, TF1, TB2, TF2 = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.005, nuB1) # bottleneck 1 phi = Integration.one_pop(phi, xx, TF1, nuF1) # recovery 1 phi = Integration.one_pop(phi, xx, 0.005, nuB2) # bottleneck 2 phi = Integration.one_pop(phi, xx, TF2, nuF2) # recovery 2 fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def fiveEpoch(params, ns, pts): nu3,t4,nu4 = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx,theta0 = theta1) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.26, 1.87, theta0 = theta1) phi = Integration.one_pop(phi, xx, 0.0055, 0.04, theta0 = theta1) phi = Integration.one_pop(phi, xx, 0.037,nu3, theta0 = theta1) phi = Integration.one_pop(phi, xx, t4, nu4, theta0 = theta1) fs = Spectrum.from_phi(phi, ns, (xx,)) return fs
def fourEpoch(params, ns, pts): nuBOT, nuREC, nuCUR = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.00002, nuBOT) # NA colonization bottleneck phi = Integration.one_pop(phi, xx, 0.03, nuREC) # recovery phi = Integration.one_pop(phi, xx, 0.0006, nuCUR) # IR founding bottleneck fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def split_Wmig(params, ns, pts): nu1, nu2, TDiv, m = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = PhiManip.phi_1D_to_2D(xx, phi) # split into two pops phi = Integration.two_pops( phi, xx, TDiv, nu1, nu2, m12=m, m21=m) # two pops at diff sizes with symmetric migration # allow for another size change; fix time at 35 gen fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def sandbox(params, ns, pts): nuBOT, nuREC = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = Integration.one_pop(phi, xx, 0.0005, nuBOT) # contraction 1 phi = Integration.one_pop(phi, xx, 0.02, nuREC) # recovery phi = Integration.one_pop( phi, xx, 0.0005, 0.005) # contraction 2 -fix at 20 inds for 4 gen # no recovery in between fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
def pop_split(params, ns, pts): N1, N2, 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, N1, N2, m12=0, m21=0) fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def bottleneck(params, ns, pts): nu1, nuB, nuF, Tb, Tf = 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, Tb, nu1, nuB, m12=0, m21=0) phi = Integration.two_pops(phi, xx, Tf, nu1, nuF, m12=0, m21=0) fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def split_Wmig_wBot(params, ns, pts): nu1, nu2, TDiv, m = params xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = PhiManip.phi_1D_to_2D(xx, phi) # split into two pops phi = Integration.two_pops( phi, xx, TDiv, nu1, nu2, m12=m, m21=m) # two pops at diff sizes with symmetric migration # allow for another size change; fix time at 35 gen phi = Integration.two_pops( phi, xx, 0.004, 0.05, 0.05, m12=0, m21=0 ) # fixing time at 35/(2*4000) to represent 35 gen ago and am fixing migraiton to be 0 during the bottleneck fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def pop_splitExp(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) nu1_func = lambda t: s * (nu1 / s)**(t / T) nu2_func = lambda t: (1 - s) * (nu2 / (1 - s))**(t / T) phi = Integration.two_pops(phi, xx, T, nu1_func, nu2_func, m12=0, m21=0) fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def IM(params, ns, pts): """ Split into two populations, with different migration rates. nu1: Size of population 1 after split. nu2: Size of population 2 after split. T: Time in the past of split (in units of 2*Na generations) m12: Migration from pop 2 to pop 1 (2*Na*m12) m21: Migration from pop 1 to pop 2 """ nu1, nu2, m12, m21, 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, m12=m12, m21=m21) fs = Spectrum.from_phi(phi, ns, (xx,xx)) return fs
def sso_model_trim_27_plusContraction_forOptimization(params,ns,pts): nu,T=params xx = Numerics.default_grid(pts) # intialize phi with ancestral pop: (nu0 = 1) phi = PhiManip.phi_1D(xx,nu=1) # stays at nu0=1 for T0 duration of time: # followed by a number of time steps, with associated pop changes: phi = Integration.one_pop(phi, xx, 0.0881712197999992, 1) phi = Integration.one_pop(phi, xx, 0.0820773125999968, 0.836551538729166) phi = Integration.one_pop(phi, xx, 0.0767768829000064, 0.836551538729166) phi = Integration.one_pop(phi, xx, 0.072122872869994, 0.761765214135537) phi = Integration.one_pop(phi, xx, 0.0679989058100032, 0.761765214135537) phi = Integration.one_pop(phi, xx, 0.0643224600599991, 0.738213027247672) phi = Integration.one_pop(phi, xx, 0.0610215936600004, 0.738213027247672) phi = Integration.one_pop(phi, xx, 0.0580444660799995, 0.750983120146509) phi = Integration.one_pop(phi, xx, 0.05534346867, 0.750983120146509) phi = Integration.one_pop(phi, xx, 0.0528826304500005, 0.795226999398677) phi = Integration.one_pop(phi, xx, 0.0506312702899994, 0.795226999398677) phi = Integration.one_pop(phi, xx, 0.0485650548800005, 0.869604885707006) phi = Integration.one_pop(phi, xx, 0.04665859294, 0.869604885707006) phi = Integration.one_pop(phi, xx, 0.0448991888299998, 0.968579772770968) phi = Integration.one_pop(phi, xx, 0.0432646251800001, 0.968579772770968) phi = Integration.one_pop(phi, xx, 0.0417474961999999, 1.07023813979649) phi = Integration.one_pop(phi, xx, 0.0403308743700001, 1.07023813979649) phi = Integration.one_pop(phi, xx, 0.03900946984, 1.12274330685933) phi = Integration.one_pop(phi, xx, 0.0377705869699996, 1.12514450221579) phi = Integration.one_pop(phi, xx, 0.0366078779399999, 1.09213414017289) phi = Integration.one_pop(phi, xx, 0.0355149949300004, 1.01928801965413) phi = Integration.one_pop(phi, xx, 0.0344855901200002, 0.91011303614748) phi = Integration.one_pop(phi, xx, 0.0335133156900004, 0.774150824662306) phi = Integration.one_pop(phi, xx, 0.0325958441059994, 0.609784494435127) phi = Integration.one_pop(phi, xx, 0.0317262985630002, 0.386870175412936) phi = Integration.one_pop(phi, xx, 0.030902139933, 0.141422067280315) phi = Integration.one_pop(phi, xx, 0.030119771118, 0.36675344664418) ### add contraction: phi = Integration.one_pop(phi, xx,T, nu) # get expected SFS: fs = Spectrum.from_phi(phi,ns,(xx,)) return fs
def SC(params, ns, pts): """ Split with no gene flow, followed by period of asymmetrical gene flow. nu1: Size of population 1 after split. nu2: Size of population 2 after split. m12: Migration from pop 2 to pop 1 (2*Na*m12). m21: Migration from pop 1 to pop 2. T1: The scaled time between the split and the secondary contact (in units of 2*Na generations). T2: The scaled time between the secondary contact and present. """ nu1, nu2, m12, m21, T1, T2 = 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, T1, nu1, nu2, m12=0, m21=0) phi = Integration.two_pops(phi, xx, T2, nu1, nu2, m12=m12, m21=m21) fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs
def psmc_100steps(params, ns, pts_l): nu99, nu98, nu97, nu96, nu95, nu94, nu93, nu92, nu91, nu90, nu89, nu88, nu87, nu86, nu85, nu84, nu83, nu82, nu81, nu80, nu79, nu78, nu77, nu76, nu75, nu74, nu73, nu72, nu71, nu70, nu69, nu68, nu67, nu66, nu65, nu64, nu63, nu62, nu61, nu60, nu59, nu58, nu57, nu56, nu55, nu54, nu53, nu52, nu51, nu50, nu49, nu48, nu47, nu46, nu45, nu44, nu43, nu42, nu41, nu40, nu39, nu38, nu37, nu36, nu35, nu34, nu33, nu32, nu31, nu30, nu29, nu28, nu27, nu26, nu25, nu24, nu23, nu22, nu21, nu20, nu19, nu18, nu17, nu16, nu15, nu14, nu13, nu12, nu11, nu10, nu9, nu8, nu7, nu6, nu5, nu4, nu3, nu2, nu1, nuA, T99, T98, T97, T96, T95, T94, T93, T92, T91, T90, T89, T88, T87, T86, T85, T84, T83, T82, T81, T80, T79, T78, T77, T76, T75, T74, T73, T72, T71, T70, T69, T68, T67, T66, T65, T64, T63, T62, T61, T60, T59, T58, T57, T56, T55, T54, T53, T52, T51, T50, T49, T48, T47, T46, T45, T44, T43, T42, T41, T40, T39, T38, T37, T36, T35, T34, T33, T32, T31, T30, T29, T28, T27, T26, T25, T24, T23, T22, T21, T20, T19, T18, T17, T16, T15, T14, T13, T12, T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0 = params xx = Numerics.default_grid(pts_l) # initial phi with ancestral pop: (nuA = 1) phi = PhiManip.phi_1D(xx, nu=nuA) # stays at nuA for T0 duration of time: phi = Integration.one_pop(phi, xx, T0, nuA) # followed by a number of time steps, with associated pop changes: phi = Integration.one_pop(phi, xx, T1, nu1) phi = Integration.one_pop(phi, xx, T2, nu2) phi = Integration.one_pop(phi, xx, T3, nu3) phi = Integration.one_pop(phi, xx, T4, nu4) phi = Integration.one_pop(phi, xx, T5, nu5) phi = Integration.one_pop(phi, xx, T6, nu6) phi = Integration.one_pop(phi, xx, T7, nu7) phi = Integration.one_pop(phi, xx, T8, nu8) phi = Integration.one_pop(phi, xx, T9, nu9) phi = Integration.one_pop(phi, xx, T10, nu10) phi = Integration.one_pop(phi, xx, T11, nu11) phi = Integration.one_pop(phi, xx, T12, nu12) phi = Integration.one_pop(phi, xx, T13, nu13) phi = Integration.one_pop(phi, xx, T14, nu14) phi = Integration.one_pop(phi, xx, T15, nu15) phi = Integration.one_pop(phi, xx, T16, nu16) phi = Integration.one_pop(phi, xx, T17, nu17) phi = Integration.one_pop(phi, xx, T18, nu18) phi = Integration.one_pop(phi, xx, T19, nu19) phi = Integration.one_pop(phi, xx, T20, nu20) phi = Integration.one_pop(phi, xx, T21, nu21) phi = Integration.one_pop(phi, xx, T22, nu22) phi = Integration.one_pop(phi, xx, T23, nu23) phi = Integration.one_pop(phi, xx, T24, nu24) phi = Integration.one_pop(phi, xx, T25, nu25) phi = Integration.one_pop(phi, xx, T26, nu26) phi = Integration.one_pop(phi, xx, T27, nu27) phi = Integration.one_pop(phi, xx, T28, nu28) phi = Integration.one_pop(phi, xx, T29, nu29) phi = Integration.one_pop(phi, xx, T30, nu30) phi = Integration.one_pop(phi, xx, T31, nu31) phi = Integration.one_pop(phi, xx, T32, nu32) phi = Integration.one_pop(phi, xx, T33, nu33) phi = Integration.one_pop(phi, xx, T34, nu34) phi = Integration.one_pop(phi, xx, T35, nu35) phi = Integration.one_pop(phi, xx, T36, nu36) phi = Integration.one_pop(phi, xx, T37, nu37) phi = Integration.one_pop(phi, xx, T38, nu38) phi = Integration.one_pop(phi, xx, T39, nu39) phi = Integration.one_pop(phi, xx, T40, nu40) phi = Integration.one_pop(phi, xx, T41, nu41) phi = Integration.one_pop(phi, xx, T42, nu42) phi = Integration.one_pop(phi, xx, T43, nu43) phi = Integration.one_pop(phi, xx, T44, nu44) phi = Integration.one_pop(phi, xx, T45, nu45) phi = Integration.one_pop(phi, xx, T46, nu46) phi = Integration.one_pop(phi, xx, T47, nu47) phi = Integration.one_pop(phi, xx, T48, nu48) phi = Integration.one_pop(phi, xx, T49, nu49) phi = Integration.one_pop(phi, xx, T50, nu50) phi = Integration.one_pop(phi, xx, T51, nu51) phi = Integration.one_pop(phi, xx, T52, nu52) phi = Integration.one_pop(phi, xx, T53, nu53) phi = Integration.one_pop(phi, xx, T54, nu54) phi = Integration.one_pop(phi, xx, T55, nu55) phi = Integration.one_pop(phi, xx, T56, nu56) phi = Integration.one_pop(phi, xx, T57, nu57) phi = Integration.one_pop(phi, xx, T58, nu58) phi = Integration.one_pop(phi, xx, T59, nu59) phi = Integration.one_pop(phi, xx, T60, nu60) phi = Integration.one_pop(phi, xx, T61, nu61) phi = Integration.one_pop(phi, xx, T62, nu62) phi = Integration.one_pop(phi, xx, T63, nu63) phi = Integration.one_pop(phi, xx, T64, nu64) phi = Integration.one_pop(phi, xx, T65, nu65) phi = Integration.one_pop(phi, xx, T66, nu66) phi = Integration.one_pop(phi, xx, T67, nu67) phi = Integration.one_pop(phi, xx, T68, nu68) phi = Integration.one_pop(phi, xx, T69, nu69) phi = Integration.one_pop(phi, xx, T70, nu70) phi = Integration.one_pop(phi, xx, T71, nu71) phi = Integration.one_pop(phi, xx, T72, nu72) phi = Integration.one_pop(phi, xx, T73, nu73) phi = Integration.one_pop(phi, xx, T74, nu74) phi = Integration.one_pop(phi, xx, T75, nu75) phi = Integration.one_pop(phi, xx, T76, nu76) phi = Integration.one_pop(phi, xx, T77, nu77) phi = Integration.one_pop(phi, xx, T78, nu78) phi = Integration.one_pop(phi, xx, T79, nu79) phi = Integration.one_pop(phi, xx, T80, nu80) phi = Integration.one_pop(phi, xx, T81, nu81) phi = Integration.one_pop(phi, xx, T82, nu82) phi = Integration.one_pop(phi, xx, T83, nu83) phi = Integration.one_pop(phi, xx, T84, nu84) phi = Integration.one_pop(phi, xx, T85, nu85) phi = Integration.one_pop(phi, xx, T86, nu86) phi = Integration.one_pop(phi, xx, T87, nu87) phi = Integration.one_pop(phi, xx, T88, nu88) phi = Integration.one_pop(phi, xx, T89, nu89) phi = Integration.one_pop(phi, xx, T90, nu90) phi = Integration.one_pop(phi, xx, T91, nu91) phi = Integration.one_pop(phi, xx, T92, nu92) phi = Integration.one_pop(phi, xx, T93, nu93) phi = Integration.one_pop(phi, xx, T94, nu94) phi = Integration.one_pop(phi, xx, T95, nu95) phi = Integration.one_pop(phi, xx, T96, nu96) phi = Integration.one_pop(phi, xx, T97, nu97) phi = Integration.one_pop(phi, xx, T98, nu98) phi = Integration.one_pop(phi, xx, T99, nu99) # get sfs: fs = Spectrum.from_phi(phi, ns, (xx, )) return fs
] def pooneh2DModel_ABMod((TDiv, nu1, nu2, m12, m21), ns, pts): xx = Numerics.default_grid(pts) # sets up grid phi = PhiManip.phi_1D(xx) # sets up initial phi for population phi = PhiManip.phi_1D_to_2D(xx, phi) # split into two pops phi = Integration.two_pops( phi, xx, TDiv, nu1, nu2, m12=m12, m21=m21) # two pops at diff sizes with symmetric migration # allow for another size change; fix time at 35 gen # fix these at my bneck sizes (not pooneh's) phi = Integration.two_pops( phi, xx, 0.004, 0.05, 0.05, m12=0, m21=0 ) # fixing time at 35/(2*4000) to represent 35 gen ago and am fixing migraiton to be 0 during the bottleneck fs = Spectrum.from_phi(phi, ns, (xx, xx)) return fs func = pooneh2DModel_ABMod modelName = "pooneh2DModel_ABMod" # wrap your function in Numerics.make_extrap_log_func to make extrapolation version of your function func_ex = Numerics.make_extrap_log_func(func) modelPooneh = func_ex(paramsPooneh, ns, pts_l) # this is relative to theta =1 ll_modelPooneh = dadi.Inference.ll_multinom(modelPooneh, fs) ll_modelPooneh modelAnnabel = func_ex(paramsAnnabel, ns, pts_l) # this is relative to theta =1 ll_modelAnnabel = dadi.Inference.ll_multinom(modelAnnabel, fs)
phi = Integration.one_pop(phi, xx, TAf, nu=nuAf) phi = PhiManip.phi_1D_to_2D(xx, phi) phi = Integration.two_pops(phi, xx, TB, nu1=nuAf, nu2=nuB, m12=mAfB, m21=mAfB) phi = PhiManip.phi_2D_to_3D_split_2(xx, phi) nuEu_func = lambda t: nuEu0*(nuEu/nuEu0)**(t/TEuAs) nuAs_func = lambda t: nuAs0*(nuAs/nuAs0)**(t/TEuAs) phi = Integration.three_pops(phi, xx, TEuAs, nu1=nuAf, nu2=nuEu_func, nu3=nuAs_func, m12=mAfEu, m13=mAfAs, m21=mAfEu, m23=mEuAs, m31=mAfAs, m32=mEuAs) fs = Spectrum.from_phi(phi, (n1,n2,n3), (xx,xx,xx)) return fs def OutOfAfrica_mscore((nuAf, nuB, nuEu0, nuEu, nuAs0, nuAs, mAfB, mAfEu, mAfAs, mEuAs, TAf, TB, TEuAs)): alphaEu = numpy.log(nuEu/nuEu0)/TEuAs alphaAs = numpy.log(nuAs/nuAs0)/TEuAs command = "-n 1 %(nuAf)f -n 2 %(nuEu)f -n 3 %(nuAs)f "\ "-eg 0 2 %(alphaEu)f -eg 0 3 %(alphaAs)f "\ "-ma x %(mAfEu)f %(mAfAs)f %(mAfEu)f x %(mEuAs)f %(mAfAs)f %(mEuAs)f x "\ "-ej %(TEuAs)f 3 2 -en %(TEuAs)f 2 %(nuB)f "\ "-ema %(TEuAs)f 3 x %(mAfB)f x %(mAfB)f x x x x x "\ "-ej %(TB)f 2 1 "\ "-en %(TAf)f 1 1"
from dadi import Misc, Spectrum, Numerics, PhiManip, Integration, Demographics1D, Demographics2D import sys infile = sys.argv[1] pop_ids = sys.argv[2] projections = [int(sys.argv[3])] #infile="5kA_dadi.data" #pop_ids=["O1"] #projections=[32] import os # replace this with your appropriate dir name # os.chdir("/Users/c-monstr/Documents/allRAD_august2015/digitifera/dadi") dd = Misc.make_data_dict(infile) data = Spectrum.from_data_dict(dd, pop_ids, projections, polarized=True) ns = data.sample_sizes pts = [65, 80, 95] np.set_printoptions(precision=3) #------------------- gr = Numerics.make_extrap_log_func(Demographics1D.growth) params = array([3, 1]) upper_bound = [100, 100] lower_bound = [0.01, 0.01] poptg = dadi.Inference.optimize_log(params, data, gr, pts, lower_bound=lower_bound,
#!/usr/bin/env python import dadi import pylab import matplotlib.pyplot as plt import numpy as np from numpy import array from dadi import Misc, Spectrum, Numerics, PhiManip, Integration, Demographics1D, Demographics2D import sys infile = sys.argv[1] popid = [sys.argv[2]] proj = range(int(sys.argv[3]), int(sys.argv[4])) dd = Misc.make_data_dict(infile) for p in range(len(proj)): data = Spectrum.from_data_dict(dd, pop_ids=popid, projections=[proj[p]], polarized=False) print proj[p], data.S()
import matplotlib.pyplot as plt import numpy as np from numpy import array from dadi import Misc, Spectrum, Numerics, PhiManip, Integration, Demographics1D, Demographics2D import sys infile = sys.argv[1] pop_ids = sys.argv[2] projections = [int(sys.argv[3])] import os # replace this with your appropriate dir name # os.chdir("/Users/c-monstr/Documents/allRAD_august2015/digitifera/dadi") dd = Misc.make_data_dict(infile) data = Spectrum.from_data_dict(dd, pop_ids, projections, polarized=True) ns = data.sample_sizes pts = [65, 80, 95] np.set_printoptions(precision=3) #------------------- def two_growths((nu1, nu2, T1, T2), (n1, ), pts): xx = Numerics.default_grid(pts) phi = PhiManip.phi_1D(xx) nu_func1 = lambda t: np.exp(np.log(nu1) * t / T1) phi = Integration.one_pop(phi, xx, T1, nu_func1) nu_func2 = lambda t: nu1 * np.exp(np.log(nu2 / nu1) * t / T2) phi = Integration.one_pop(phi, xx, T2, nu_func2) sfs = Spectrum.from_phi(phi, (n1, ), (xx, )) return sfs
phi = Integration.one_pop(phi, xx, T25, nu25) phi = Integration.one_pop(phi, xx, T26, nu26) phi = Integration.one_pop(phi, xx, T27, nu27) phi = Integration.one_pop(phi, xx, T28, nu28) phi = Integration.one_pop(phi, xx, T29, nu29) phi = Integration.one_pop(phi, xx, T30, nu30) phi = Integration.one_pop(phi, xx, T31, nu31) phi = Integration.one_pop(phi, xx, T32, nu32) phi = Integration.one_pop(phi, xx, T33, nu33) phi = Integration.one_pop(phi, xx, T34, nu34) phi = Integration.one_pop(phi, xx, T35, nu35) phi = Integration.one_pop(phi, xx, T36, nu36) phi = Integration.one_pop(phi, xx, T37, nu37) phi = Integration.one_pop(phi, xx, T38, nu38) # get expected SFS: fs = Spectrum.from_phi(phi, ns, (xx, )) return fs # wrap your function in Numerics.make_extrap_log_func to make extrapolation version of your function extrap_nso_model_trim_39_function = Numerics.make_extrap_log_func( nso_model_trim_39) # Version of model with nu and T values plugged in plus one more epoch for dadi to optimize def nso_model_trim_39_plusContraction_forOptimization( (contractionGen_RescBy2Nanc, contractionSize_RescByNanc), ns, pts): xx = Numerics.default_grid(pts) # intialize phi with ancestral pop: (nu0 = 1) phi = PhiManip.phi_1D(xx, nu=1) # stays at nu0=1 for T0 duration of time:
TMoCa: split time for Moroccan and Canary island populations TF: simulation ending time """ xx = Numerics.default_grid(pts) phi = PhiManip.phi_1D(xx) phi = Integration.one_pop(phi, xx, TIbMo, nu=nuIb0) phi = PhiManip.phi_1D_to_2D(xx, phi) phi = Integration.two_pops(phi, xx, TMoCa, nu1=nuIb, nu2=nuMo0) phi = PhiManip.phi_2D_to_3D_split_2(xx, phi) phi = Integration.three_pops(phi, xx, TF, nu1=nuIb, nu2=nuMo, nu3=nuCa0) fs = Spectrum.from_phi(phi, ns, (xx,xx,xx)) return fs def simple_canary_migration((nuIb0, nuIb, nuMo0, nuMo, nuCa0, TIbMo, TMoCa, mIbCa, TF), ns, pts): """ nuIb0: starting Iberian population size nuIb: ending Iberian population size nuMo0: starting Moroccan population size nuMo: ending Morrocan population size nuCa0: starting Canary island population size TIbMo: split time for Iberian and Moroccan populations TMoCa: split time for Moroccan and Canary island populations mIbCa: migration rate from Ib to Ca TF: simulation ending time