def family_exemplar_structs(rfid, refseq_method = None, sp_method = None, aff_type = None): suboptimals = rutils.family_suboptimals(rfid) c2 = rutils.cluster_2(spairs, ungapped_ref) arr = rutils.rna_draw(ungapped_ref.seq, rutils.pairs_stk(sp,len(ungapped_ref)), 'name' ) raise Exception() affinities, ss = rutils.affinity_matrix(spairs, aff_type = aff_type) aff_shape, ss_shape = rutils.affinity_matrix(spairs, aff_type = 'easy', ss_multiplier = .5) pca_vecs = mlab.PCA(affinities).project(affinities) pca_vecs_shape = mlab.PCA(aff_shape).project(aff_shape) inds = compute_clusters(aff_shape, ss_shape) exemplars = list(set(inds)) import compbio.utils.colors as mycolors ct = mycolors.getct(len(exemplars)) import matplotlib.pyplot as plt f = plt.gcf() plt.clf() for idx0, embeddings in enumerate([pca_vecs, pca_vecs_shape]): ax = f.add_subplot('21{0}'.format(idx0 +1)) lims =[ [min(embeddings[:,0]),max(embeddings[:,0])], [min(embeddings[:,1]),max(embeddings[:,1])] ] lims += [-.5,.5] *squeeze(diff(lims,1))[:,newaxis] ax.set_xlim(lims[0]) ax.set_ylim(lims[1]) print sum(embeddings) for idx, embedding in enumerate(embeddings): if mod(idx,1) != 0: continue sp = spairs[idx] arr = rutils.rna_draw(ungapped_ref.seq, rutils.pairs_stk(sp,len(ungapped_ref)), 'name' ) struct_emb = arr + embedding[0:2] #plt.plot(*struct_emb.T) pkw = {'color':ct[exemplars.index(inds[idx])], 'lw':8 if idx in inds else 1, 'alpha': 1 if idx in inds else .2} lc = rplots.show_rna(embedding, arr, pkw = pkw) #exemplar_structs = [spairs[e] for e in set(inds)] raise Exception() return pca_vecs, exemplar_structs
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