phi = Integration.one_pop(phi, xx, T188, nu188)
    phi = Integration.one_pop(phi, xx, T189, nu189)
    phi = Integration.one_pop(phi, xx, T190, nu190)
    phi = Integration.one_pop(phi, xx, T191, nu191)
    phi = Integration.one_pop(phi, xx, T192, nu192)
    phi = Integration.one_pop(phi, xx, T193, nu193)
    phi = Integration.one_pop(phi, xx, T194, nu194)
    phi = Integration.one_pop(phi, xx, T195, nu195)
    phi = Integration.one_pop(phi, xx, T196, nu196)
    phi = Integration.one_pop(phi, xx, T197, nu197)
    phi = Integration.one_pop(phi, xx, T198, nu198)
    # simulate sfs:
    fs = Spectrum.from_phi(phi,ns,(xx,))
    return fs

SMCPLUS_extrap_function_198 = Numerics.make_extrap_log_func(SMCPLUS_model_198steps)


#################################### CEU ##################################
# get SFS relative to theta = 1
smc_song_fs_ceu_relT = SMCPLUS_extrap_function_198(song_ceu_dadi,ns,pts)
# get the proportional sfs:
smc_song_fs_ceu_freq = smc_song_fs_ceu_relT / np.sum(smc_song_fs_ceu_relT)
# Plotting.plot_1d_comp_Poisson(obs_fs_CEU/np.sum(obs_fs_CEU),smc_song_fs_ceu_freq)
# get num snp, need a theta:
# Length is from Gutenkunst so that SFSes are comparable
Length = 4040000
# wsong mu: 1.25 × 10−8
song_mu= 1.25e-08
# ancestral size (oldest nu)
song_ceu_nuA = song_ceu_dips[-1]
예제 #2
0
    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:
    # followed by a number of time steps, with associated pop changes:
    phi = Integration.one_pop(phi, xx, 0.012177548731, 1)
    phi = Integration.one_pop(phi, xx, 0.00712323213699992, 0.444441187582237)
    phi = Integration.one_pop(phi, xx, 0.00505418013100008, 0.444441187582237)
    phi = Integration.one_pop(phi, xx, 0.00392030906399995, 0.137194521186969)
    phi = Integration.one_pop(phi, xx, 0.00320305953600002, 0.137194521186969)
예제 #3
0
#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,
                                    upper_bound=upper_bound,
                                    verbose=len(params),
                                    maxiter=15)

model = gr(poptg, ns, pts)
예제 #4
0
	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)
	# get expected SFS:
	fs = Spectrum.from_phi(phi,ns,(xx,))
	return fs


func=nso_model_trim_20
modelName="nso_model_trim_20"
params=params # change for each model 
# wrap your function in Numerics.make_extrap_log_func to make extrapolation version of your function
func_ex = Numerics.make_extrap_log_func(func)


model=func_ex(params,ns,pts_l) # this is relative to theta =1
### get proportional sfs 
model_freq = model/(sum(model))
model_freq_fold =model_freq.fold()


############### Output SFS ########################
print('Writing out SFS **************************************************')                                   

outputSFS=str(outdir)+"/"+str(modelName)+".PROPORTIONAL.FOLDED.expSFS.txt"

model_freq_fold.to_file(outputSFS)
예제 #5
0
    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)
    # 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_sso_model_trim_22_function = Numerics.make_extrap_log_func(
    sso_model_trim_22)


# Version of model with nu and T values plugged in plus one more epoch for dadi to optimize
def sso_model_trim_22_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:
    # followed by a number of time steps, with associated pop changes:
    phi = Integration.one_pop(phi, xx, 0.0871326536999987, 1)
    phi = Integration.one_pop(phi, xx, 0.0826612257000005, 1)
    phi = Integration.one_pop(phi, xx, 0.0786283415999992, 1.01729865557432)
    phi = Integration.one_pop(phi, xx, 0.0749695096499999, 1.01729865557432)
    phi = Integration.one_pop(phi, xx, 0.0716360027500006, 1.07723241130487)
    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 sfs:
    fs = Spectrum.from_phi(phi, ns, (xx, ))
    return fs


# wrap your function in Numerics.make_extrap_log_func to extrapolate over pts
msmc_extrap_function_38 = Numerics.make_extrap_log_func(msmc_model_38steps)

# usage: msmc_extrap_function_38(Parameters,ns,pts)
# where Parameters is a vector of MSMC output parameters
# converted to population sizes across time intervals, in units of 2*nuA (see below)


###### dadi model for 8 Haplotype MSMC model (28 steps) #########################
# need 28 steps for 8 haplotype model
def msmc_model_28steps(
    (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, 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), ns, pts):
    xx = Numerics.default_grid(pts)
예제 #7
0
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


twog = Numerics.make_extrap_log_func(two_growths)

params = array([1, 1, 1, 0.1])
upper_bound = [100, 100, 100, 10]
lower_bound = [0.01, 0.01, 0.01, 0.001]
poptg = dadi.Inference.optimize_log(params,
                                    data,
                                    twog,
                                    pts,
                                    lower_bound=lower_bound,
                                    upper_bound=upper_bound,
                                    verbose=len(params),
                                    maxiter=20)

model = twog(poptg, ns, pts)
예제 #8
0
#-------------------
# split with migration


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


S2MM = Numerics.make_extrap_log_func(s2mM)

params = array([1, 1, 1, 30, 30])
upper_bound = [10, 10, 10, 300, 300]
lower_bound = [0.01, 0.01, 0.01, 0.1, 0.1]
poptg = dadi.Inference.optimize_log(params,
                                    data,
                                    S2MM,
                                    pts,
                                    lower_bound=lower_bound,
                                    upper_bound=upper_bound,
                                    verbose=len(params),
                                    maxiter=15)

model = S2MM(poptg, ns, pts)
print 's2m ', sys.argv[1], sys.argv[2], sys.argv[3], ' params : ', poptg
    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


im2 = Numerics.make_extrap_log_func(IM2)

params = array([0.078, 2.136, 2.174, 2.063, 1.174, 0.514, 0.379])
upper_bound = [100, 100, 100, 100, 100, 200, 200]
lower_bound = [1e-3, 1e-3, 1e-3, 1e-3, 1e-3, 0, 0]
poptg = dadi.Inference.optimize_log(params,
                                    data,
                                    im2,
                                    pts,
                                    lower_bound=lower_bound,
                                    upper_bound=upper_bound,
                                    verbose=len(params),
                                    maxiter=20)

model = im2(poptg, ns, pts)
ll_model = dadi.Inference.ll_multinom(model, data)
	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)
	# 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_sso_model_trim_33_function = Numerics.make_extrap_log_func(sso_model_trim_33)


msmc_model_expSFS=extrap_sso_model_trim_33_function(params,ns,pts_l)


ll_msmc_model = dadi.Inference.ll_multinom(msmc_model_expSFS, fs)

# plot an image:
#import pylab
import matplotlib.pyplot as plt 
#fig=plt.figure(1)
#pylab.ion()
outputFigure=str(str(outdir)+"/"+str(pop)+"."+str(modelName)+".wDip.figure.png")
dadi.Plotting.plot_1d_comp_multinom(msmc_model_expSFS, fs)
pyplot.title(str(modelName)+" LL = "+str(ll_msmc_model))
# split with migration, with recent change in migration


def s2mRM(params, ns, pts):
    nu1, nu2, T, M12, M21, M12r, M21r = params
    Tr = 0.01
    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)
    phi = Integration.two_pops(phi, xx, Tr, nu1, nu2, m12=M12r, m21=M21r)
    fs = Spectrum.from_phi(phi, ns, (xx, xx))
    return fs


S2MRM = Numerics.make_extrap_log_func(s2mRM)

params = array([1, 1, 1, 30, 30, 30, 30])
upper_bound = [10, 10, 10, 300, 300, 300, 300]
lower_bound = [0.01, 0.01, 0.01, 0.1, 0.1, 0.1, 0.1]
poptg = dadi.Inference.optimize_log(params,
                                    data,
                                    S2MRM,
                                    pts,
                                    lower_bound=lower_bound,
                                    upper_bound=upper_bound,
                                    verbose=len(params),
                                    maxiter=15)

model = S2MRM(poptg, ns, pts)
print 's2mRM ', sys.argv[1], sys.argv[2], sys.argv[3], ' params : ', poptg