def get_sliding_p(M, w_size = 200, w_step = 50): df = pd.DataFrame(M.T) w_st = 0 P = [] x = [] Ib=[] while True: Mw = M[:, w_st:w_st + w_size] [H, N] = myHAF.get_mutation_h_n(Mw, eps=0) haf = myHAF.HAF(Mw) if (ba_ind<(w_st + w_size))&(ba_ind>=w_st): Ib+=[1] else: Ib+=[0] h = 1.0 * H / sum(haf) n = 1.0 * N / (np.unique(haf).shape[0]) f = Mw.mean(0) p = myHAF.neutrality_divergence_likelihood_2(h, n, f, method=3) I = np.argsort(p)[::-1] top_kw = len(I) P += list(p[I[:top_kw]]) x += list(w_st + I[:top_kw]) w_st += w_step if Mw.shape[1] < w_size: break d = pd.DataFrame([x, P]).T D = d.groupby(0).mean().reset_index() return D
def get_p(Mw): [H, N] = myHAF.get_mutation_h_n(Mw, eps=0) haf = myHAF.HAF(Mw) h = 1.0 * H / sum(haf) n = 1.0 * N / (np.unique(haf).shape[0]) f = Mw.mean(0) p = myHAF.neutrality_divergence_likelihood_2(h, n, f, method=3) r = np.argsort(p)[::-1] return p,r,h,n