コード例 #1
0
ファイル: Estimate.py プロジェクト: airanmehr/bio
def LR(param):
    i=param['testingSite']
    data, inith,pos = param['Data'][:, (i,), :],param['initHaps'][:, (i,)],param['positions'][i]
    lik = Likelihood(data, inith , param['times'], [pos], pos, None)
    fit = lik.maxlik_s(N=param['N'], log10r=np.log10(param['r']), h=param['h'], bounds=(-.15, .15))
    ml = -fit.fun
    ml0 = lik.likelihood(N=param['N'], r=param['r'], h=param['h'], s=0.0)
    lr = 2 * (ml - ml0)
    return (pos, lr)
コード例 #2
0
ファイル: Estimate.py プロジェクト: airanmehr/bio
def multipleLocus(X, initHaps, N,r,times,pos):
    start_time=time()
    h0=np.zeros(initHaps.shape);
    h0[:int(h0.shape[0]*X[0,0,0]),0]=1
    lik = Likelihood(X[times!=0], initHaps, times[times!=0], pos, pos[0], None)
    fit = lik.maxlik_s(N=N, log10r=np.log10(r), h=0.5, bounds=(-.15, .15))
    ml = -fit.fun
    ml0 = lik.likelihood(N, r, 0.5, 0.0)
    if abs(ml0) == np.inf:
        ml0=np.sign(ml0)*1000
    lr = 2 * (ml - ml0)
    s=float(fit.x)*1.0
    pyexp.reset()
    # print pos,time()-start_time
    return pd.Series({'LR':lr ,'s':s, 'SLR':lr*s, 'pos':pos, 'Time':time()-start_time})
コード例 #3
0
ファイル: example.py プロジェクト: airanmehr/bio
times = [10, 20, 30, 40, 50]
r = 1e-4
N = 2000
# True selected position is 568
liks = []
print len(positions)
print positions
data[:, (0,), 0]
print("## Pass 1. Testing")
for i, pos in enumerate(positions):
    dta = data[:, (i,), :]
    if np.min(dta[-1]) < 0.01:
#         print 'Skip sites which are are lost'
        continue
    ih = init_haps[:, (i,)]
    lik = Likelihood(data[:, (i,), :], init_haps[:, (i,)], times, [pos], pos, None)
    fit = lik.maxlik_s(N=N, log10r=math.log10(r), h=0.5, bounds=(-.15, .15))
    s_hat = fit.x
    ml = -fit.fun
    ml0 = lik.likelihood(N, r, 0.5, 0.0)
    lr = 2 * (ml - ml0)
    if lr < 0:
        print(dta, )
    print("Site: %d\tLoglik ratio: %g" % (pos, lr))
    liks.append((pos, lr))

print("## Pass 2. Estimation")
maxpos = sorted(liks, key=lambda tup: -tup[1])[0][0]
print("Site with highest LR: %d" % maxpos)
print("Estimating a 5-locus model at this site...")
mpi = tuple(positions).index(maxpos)