Exemplo n.º 1
0
def show_subopts(structs, polys, energies):
    srted = argsort(energies)
    e = array(energies)
    cols = [1.,0.,0.] * ((e - min(e)) / (max(e) - min(e)))[:,newaxis]
    plf2 = myplots.fignum(7,(10,10))

    rplots.grid_rnas(polys[srted], 
                     colors =cols[srted],
                     size = (8,8), dims = [180,50])    
Exemplo n.º 2
0
def cluster_2_show(clusters, polys): 
    sortorder = argsort(clusters)
    ct_colors = mycolors.getct(len(set(clusters)))
    ct_dict = dict([(cluster, ct_colors[i]) for i, cluster in enumerate(set(clusters))])
    
    plf2 = myplots.fignum(8,(10,10))
    
    rplots.grid_rnas(polys[sortorder], 
                     colors  = [ct_dict[i] for i in clusters[sortorder]],
                     size = (5,5), dims = [180,50])    
Exemplo n.º 3
0
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)))