def draw(): X = simulate.runOne(SHOW=False,we=1.0,wl=0., wr=0., foot_print=4,s=5, l=5) F = plt.figure( ) ax1 = F.add_subplot(2,2,1) ax2 = F.add_subplot(2,2,2) ax3 = F.add_subplot(2,2,3) ax4 = F.add_subplot(2,2,4) ax_c= F.add_axes([0.35,0.52,0.35,0.02]) ax_c.set_xticks([]) ax_c.set_yticks([]) cmap = mpl.cm.jet norm = mpl.colors.Normalize(vmin=-1000, vmax=0) # ColorbarBase derives from ScalarMappable and puts a colorbar # in a specified axes, so it has everything needed for a # standalone colorbar. There are many more kwargs, but the # following gives a basic continuous colorbar with ticks # and labels. cb1 = mpl.colorbar.ColorbarBase(ax_c, cmap=cmap, norm=norm, orientation='horizontal') ax_c.set_xticklabels([r"$-10^{30}$"]+ [" "," "," "," ",r"$-10^{15}$"," "," "," "," " ]+ [r'$-10^3$'] , rotation=15 ) ax_c.set_title("log-likelihood") res = 3 mu_by_lambda(ax1, X,res) mu_by_pi(ax2,X,res) sigma_by_lambda(ax3,X,res) fp_by_sigma(ax4,X,res) plt.tight_layout() plt.show()
def run(FILE): FHW = open(FILE, "w") X = load.grab_specific_region("chr1",6229860,6303055, SHOW=False, bins=1000 ) print min(X[:,0]), max(X[:,0]) FHW.write("#chr1,6229860,6303055\n") FHW.write("~forward\n") for i in range(X.shape[0]): FHW.write(str(X[i,0]) + "," + str(X[i,1]) + "\n") FHW.write("~reverse\n") for i in range(X.shape[0]): FHW.write(str(X[i,0]) + "," + str(X[i,2]) + "\n") X = simulate.runOne(mu=0, s=0.1, l=3, lr=100, ll=-50, we=0.5,wl=0.25, wr=0.25, pie=0.5, pil=0.1, pir=0.9, N=1000, SHOW=False, bins=1000, noise=True ) X[:,0]+=6303055 X[:,0]*=100. st, sp = X[0,0], X[-1,0] print st, sp FHW.write("#chrN,"+str(st) + "," + str(sp) + "\n") FHW.write("~forward\n") for i in range(X.shape[0]): FHW.write(str(X[i,0]) + "," + str(X[i,1]) + "\n") FHW.write("~reverse\n") for i in range(X.shape[0]): FHW.write(str(X[i,0]) + "," + str(X[i,2]) + "\n") FHW.close()
def draw_posterior(ax,ax_cbar): X1 = sim.runOne(mu=-40, s=1, l=10, lr=40, ll=-200, we=0.5,wl=0.25, wr=0.25, pie=0.5, pil=0.1, pir=0.9, N=3000, SHOW=False , bins=200, noise=False, foot_print = 1 ) X2 = sim.runOne(mu=40, s=1, l=10, lr=200, ll=-40, we=0.5,wl=0.25, wr=0.25, pie=0.5, pil=0.1, pir=0.9, N=3000, SHOW=False , bins=200, noise=False, foot_print = 1 ) rvs = [model.component_bidir( -40, 1, 0.1, 0.5,0.5 , None,foot_print=1 )] rvs +=[model.component_elongation( -40, 200, 0.25,1.0 ,None , None, None, None)] rvs +=[model.component_elongation( -200, -40, 0.25,0 , None , None, None, None )] rvs += [model.component_bidir( 40, 1, 0.1, 0.5,0.5 , None,foot_print=1 )] rvs +=[model.component_elongation( 40, 200, 0.25,1.0 ,None , None, None, None)] rvs +=[model.component_elongation( -200, 40, 0.25,0 , None , None, None, None )] norm = mpl.colors.Normalize(vmin=0, vmax= 1) cmap = plt.get_cmap('PuOr' ) m = cm.ScalarMappable(norm=norm, cmap=cmap) cb1 = mpl.colorbar.ColorbarBase(ax_cbar, cmap=cmap, norm=norm, orientation='vertical') cb1.set_label(r'$p(k=paused|\hat{\theta})$') ax_cbar.yaxis.tick_right() ax_cbar.set_yticklabels(["0", "", "", "","", "0.5", "","", "", "", "1"] ) ax2 = ax_cbar.twinx() ax2.set_yticks([]) ax2.yaxis.set_label_position("left") KS = (0,3) MIN, MAX = 0,0 for i,X in enumerate((X1, X2)) : w = (X[-1,0] - X[0,0]) / X.shape[0] xs = np.linspace(X[0,0],X[-1,0], X.shape[0] ) MAX = max(MAX, max(X[:,1])) MIN = min(MIN, min(-X[:,2])) colorsf = [ m.to_rgba(posterior(x,rvs, Type=KS[i] )) for x in xs ] ax.bar(X[:,0], X[:,1], width=w, color=colorsf, edgecolor=colorsf,alpha=0.3) ax.bar(X[:,0], -X[:,2], width=w, color=colorsf, edgecolor=colorsf,alpha=0.3) ax.set_ylim(MIN, MAX) ax.set_yticklabels([""]+[str(abs(int(i ) )) for i in ax.get_yticks()[1:] ] ) ax.set_ylabel("Read Coverage") ax.set_xlabel("Relative Genomic Position") ax.grid()
def run(mu=0, si=1, l=0.1, pi=0.5 , we=0.5,wl=0.25, wr=0.25, N=2,NS=(100,1000), OUT=""): FHW = open(OUT, "w") FHW.write("~" + str(mu) + "," + str(si) + "," + str(l) + "," + str(we) + "," + str(pi) + "," + str(wl) + "," + str(wr) + "\n" ) for n in NS: FHW.write("#" + str(int(n)) + "\n") for b in range(N): print n,b FHW.write("*" + str(b) + "\n") X = sim.runOne(mu=mu, s=si, l=1.0/l, lr=100, ll=-100, we=we,wl=wl, wr=wr, pie=pi, pil=0.1, pir=0.9, N=int(n), SHOW=False , bins=200, noise=False, foot_print = 0 ) clf = model.EMGU(noise=True, K=1,noise_max=0.,moveUniformSupport=0,max_it=200, cores=1, seed=False,foot_print=0) t = clf.fit(X) for rv in clf.rvs: FHW.write("conv: " + str(t) + "\n") FHW.write(rv.__str__() + "\n") FHW.flush()
def draw_sim_one(ax, mu,si, l, w, pi): X = sim.runOne(mu=mu, s=2, l=1.0/l, lr=100, ll=-100, we=0.5,wl=0.25, wr=0.25, pie=0.5, pil=0.1, pir=0.9, N=300, SHOW=False , bins=200, noise=False, foot_print = 1 ) noise = np.random.uniform(-135,145, 50) noise2 = np.random.uniform(-135,145, 50) counts,edges = np.histogram(noise, bins=200, normed=1) counts2,edges2 = np.histogram(noise2, bins=200, normed=1) counts*=0.05 counts2*=0.05 rvs = [model.component_bidir( 0, 2, l, 0.5,0.5 , None,foot_print=1 )] rvs +=[model.component_elongation( 0, 100, 0.25,1.0 ,None , None, None, None)] rvs +=[model.component_elongation( -100, 0, 0.25,0.0 , None , None, None, None )] X[:,1:]/=np.sum(X[:,1:]) w = (X[-1,0] - X[0,0]) / X.shape[0] ax.bar(X[:,0], X[:,1], width=w, color="blue", edgecolor="blue",alpha=0.3) ax.bar(X[:,0], -X[:,2], width=w, color="red", edgecolor="red",alpha=0.3) ax.bar(edges[1:], counts,width=w, color="blue", edgecolor="blue",alpha=0.3) ax.bar(edges2[1:], -counts2, width=w, color="red", edgecolor="red",alpha=0.3) xs = np.linspace(X[0,0], X[-1,0], 1000) ysf = [sum([rv.pdf(x,1) for rv in rvs ]) for x in xs] ysr = [sum([-rv.pdf(x,-1) for rv in rvs ]) for x in xs] ax.plot(xs,ysf,linewidth=2.5,linestyle="-", color="black") ax.plot(xs,ysr,linewidth=2.5,linestyle="-", color="black", label="Model") ax.set_yticks(np.linspace(min(ysr)-0.01, max(ysf)+0.01, 12)) ax.set_yticklabels([""]+ [str(abs(x))[:5] for x in np.linspace(min(ysr)+0.01, max(ysf)-0.01, 10)] + [""] ) ax.set_ylim(min(ysr)-0.01, max(ysf)+0.01) ax.grid() ax.set_ylabel("Density") ax.set_xticklabels([str(int(10*x)) for x in ax.get_xticks() ]) ax.set_xlabel("Relative Genomic Coordinate") ax.legend() pass
ax.grid() plt.show() if __name__ == "__main__": #================================== #testing MAP-EM procedure X = simulate.runOne(mu=0, s=1, l=10, lr=100, ll=-50, we=0.5, wl=0.25, wr=0.25, pie=0.5, pil=0.1, pir=0.9, N=1000, SHOW=False, bins=300, noise=False, foot_print=10) # chr1:20,984,647-20,991,448 #chr1:836,835-843,549 # X = load.grab_specific_region("chr1",836835, 843549, # pos_file="/Users/joazofeifa//Lab/gro_seq_files/HCT116/bed_graph_files/DMSO2_3.pos.BedGraph", # neg_file="/Users/joazofeifa//Lab/gro_seq_files/HCT116/bed_graph_files/DMSO2_3.neg.BedGraph", # SHOW =False, bins=300) # X[:,0]-=X[0,0] # X[:,0]/=100.