def show_rna_structs(xvals, yvals, structs, energies, pfracs, rname, rtype,ns,rfid,figsize,colors, seq, n, selection_type,vert_idxs): verts = rutils.struct_verts([structs['structs'][i] for i in vert_idxs] ,seq,rfid) f = myplots.fignum(3,figsize) ax = f.add_subplot(111) myplots.padded_limits(ax, xvals, yvals, .2) for vi, v in enumerate(verts): i = vert_idxs[vi] dims = [30] shadow_width = 10 pkw0 = {'linewidth':shadow_width, 'color':'white', 'alpha':1, 'zorder':1.1} rplots.show_rna([xvals[i],yvals[i]], v, dims = dims, pkw = pkw0) pkw0 = {'linewidth':shadow_width, 'color':'white', 'alpha':.8, 'zorder':vi+2} rplots.show_rna([xvals[i],yvals[i]], v, dims = dims, pkw = pkw0) pkw1 = {'linewidth':2, 'color':colors[i], 'zorder':vi+2} rplots.show_rna([xvals[i],yvals[i]], v, dims = dims, pkw = pkw1) ax.set_ylabel('mutation score') ax.set_xlabel('free energy (-kCal)') ax.annotate('''Suboptimal foldings, positioned by energy and a mutation based evolutionary score. Color indicates a second score from paired BL.''' , [0,1],xycoords ='axes fraction', xytext = [10,-10], textcoords='offset pixels', va = 'top') f.savefig(figfile.format('{3}_frac_silent_{0}_{1}{2}'.\ format(rname,selection_type,n,rtype))) return vert_idxs
def show_rna_structs(xvals, yvals, structs, energies, pfracs, rname, rtype, ns, rfid, figsize, colors, seq, n, selection_type, vert_idxs): verts = rutils.struct_verts([structs['structs'][i] for i in vert_idxs], seq, rfid) f = myplots.fignum(3, figsize) ax = f.add_subplot(111) myplots.padded_limits(ax, xvals, yvals, .2) for vi, v in enumerate(verts): i = vert_idxs[vi] dims = [30] shadow_width = 10 pkw0 = { 'linewidth': shadow_width, 'color': 'white', 'alpha': 1, 'zorder': 1.1 } rplots.show_rna([xvals[i], yvals[i]], v, dims=dims, pkw=pkw0) pkw0 = { 'linewidth': shadow_width, 'color': 'white', 'alpha': .8, 'zorder': vi + 2 } rplots.show_rna([xvals[i], yvals[i]], v, dims=dims, pkw=pkw0) pkw1 = {'linewidth': 2, 'color': colors[i], 'zorder': vi + 2} rplots.show_rna([xvals[i], yvals[i]], v, dims=dims, pkw=pkw1) ax.set_ylabel('mutation score') ax.set_xlabel('free energy (-kCal)') ax.annotate('''Suboptimal foldings, positioned by energy and a mutation based evolutionary score. Color indicates a second score from paired BL.''', [0, 1], xycoords='axes fraction', xytext=[10, -10], textcoords='offset pixels', va='top') f.savefig(figfile.format('{3}_frac_silent_{0}_{1}{2}'.\ format(rname,selection_type,n,rtype))) return vert_idxs
def show_conservation(fidx = 0, reset = False): fnum = flist[fidx] rfid = 'RF{0:05}'.format(fnum) print rfid if fnum ==50: ftype = 'riboswitch' else: ftype = 'all' out = mem.getOrSet(setFamData, **mem.rc({}, reset =reset, on_fail = 'compute', hardcopy = False, register = 'fdat'+rfid, ftype = ftype, rfid = rfid)) mvals, tvals, structs = mem.getOrSet(setTree, **mem.rc({},reset = reset, on_fail = 'compute', hardcopy = True, register = 'st'+rfid, rfid = rfid, ftype = ftype)) idxs, tidx = sutils.show_paired_v_energy(rfid,rfid,mvals,tvals,structs,ftype) all_pairs = structs['structs'] all_energies = structs['energies'] pints,eints, mints, tints = [structs['structs'][i] for i in idxs],\ [ structs['energies'][i] for i in idxs],\ [ mvals[tidx][i] for i in idxs],\ [ tvals[tidx][i] for i in idxs] seq = structs['seq'] if do_make_subopts: subopts = rutils.suboptimals(seq, n = 400) verts = rutils.struct_verts(subopts, seq, rfid) f = myplots.fignum(4,figsize) rplots.grid_rnas(verts, dims = [40]) f.savefig(figfile.format('{0}_grid_rnas'.\ format(rfid))) aff = rutils.struct_affinity_matrix(all_pairs, len(seq)) pca = rutils.project_structs(all_pairs, ptype ='pca', affinities = aff, n_comp = 3) for metric in ['n_comp']:# ['frac_silent','frac_paired','n_comp']: scolors = [] for i in range(len(tvals[tidx])): m_silent, pidxs, frac_good = sutils.metric( mvals[tidx][i],tvals[tidx][i], mtype = metric) scolors.append(mean(m_silent)) scolors = myplots.rescale(scolors, [0.,1.])[:,newaxis] * array([1.,0.,0.]) f = myplots.fignum(4,figsize) ax = f.add_subplot(111) xvals, yvals = pca[:,:2].T myplots.padded_limits(ax, xvals, yvals) ax.scatter(xvals,yvals,300,linewidth = 1, edgecolor = 'black', color = scolors) ax.scatter(pca[idxs,0],pca[idxs,1], 2100 ,alpha = 1, color = 'black') ax.scatter(pca[idxs,0],pca[idxs,1], 2000 ,alpha = 1, color = 'white') ax.scatter(pca[idxs,0],pca[idxs,1], 400 ,alpha = 1, color = scolors[idxs], ) ax.annotate('''Conservation metric: {0} Projected onto C=2 Principal Components'''.format(metric), [0,1],xycoords = 'axes fraction', va = 'top', xytext = [10,-10],textcoords='offset points') f.savefig(figfile.format('{0}_pca_{1}'.\ format(rfid, metric)))