示例#1
0
def plot_grid(fig, params):
    grid =map(lambda x: x.strip().split(' '),
              open(au.data_filepath(params['fname'])).readlines())


    grid_rs = zeros((len(grid),len(grid[0])),int) + 200
    if params['command'] == 'DumpLineageGrid':
        grid =array(grid, float)
        grid_colors = zeros(shape(grid),int)
        grid_colors += grid
        cols = ['Mut-Averse','Mut-Prone']
        plotLinCounts(grid)

    elif params['command'] == 'DumpTaskGrid':
        grid_int = array(grid,int)
        grid_colors = zeros(shape(grid_int),int) -1
        while 1:
            nz =nonzero(greater(grid_int,0))
            if len(nz[0]) == 0 : break
            grid_colors[nz[0],nz[1]]+= 1
            grid_int /= 2

        grid = grid_colors #(array(grid, float)) 
        cols,data = au.parse_printed('tasks.dat')
        cols = cols[1:]

    elif params['command'] == 'PrintResourceData':
        grid_int = array(grid,int)
        grid_colors = grid_int
        cols = [str(i) for i in range(max(grid_int)+1)]

    else:
        raise Exception('Grid type not implemented')
    

    #grid = params['grid']
    x = shape(grid)[0]
    y = shape(grid)[1]
    n = x * y

    if x != y:
        print "Grid not square, skipping"
        return



    fig.clear()

    

    ct = mycolors.getct(len(cols))
    nc = len(ct)
    
    xs,ys,rs,cs = [[] for i in range(4)]

    c_lambda = lambda x: x>=0 and ct[x] or [0,0,0]
    
    arr = zeros((x,y,3))
    for i in range(nc):
        arr[nonzero(equal(grid, i))] = ct[i]


    #for i in range(x):
    #    for j in range(y):
    #        grid_colors
    #
    #for i in range(x):
    #    for j in range(y):
    #        xs.append(i)
    #        ys.append(j)
    #        rs.append(grid_rs[i,j])
    #        cs.append(c_lambda( grid_colors[i,j]))
    #ax = fig.add_subplot(111)
    #ax.scatter(xs,ys,rs,cs)

    plt.imshow(arr)
    up.color_legend(fig,ct,cols)
    plt.draw()
示例#2
0
    f.clear()
    ax = f.add_axes([0,0,1,1])



    ng = len(grids)
    
    do_fold = False
    if fold_grid and ng > 9: 
        do_fold = True

    if do_fold:
        grids2= grids[ng/2:]
        grids = grids[0:ng/2]
        ng /=2
    ct = mycolors.getct(ng)
    nx = ceil(sqrt(ng))
    ny = ceil(sqrt(ng))
    
    sx,sy = shape(grids[0])
    
    m0 = np.max(grids)
    if m0 == 0: m0 = 1

    if do_fold: m1 = np.max(grids2)
    if do_fold: 
        if m1 == 0: m1 = 1

    margin = 3
    if do_fold:
        big_grid = zeros((nx*sx +(nx +1)* margin, ny * sy + (ny +1) * margin,3))
示例#3
0
def plot_ts(fig,params,
            do_grid_resources = True):
    fname = params['fname']
    window = params.get('window',20)
    



    cols, data = au.parse_printed( fname)
    data_dict_unfiltered = {}
    widths_dict = {}

    for i in range(len(cols)):
        c = cols[i]
        data_dict_unfiltered[c] = array(map(lambda x: x[i], data),float)
        widths_dict[c] = i +1

    if 'Update' in cols:
        cols.remove('Update')    

    data_dict = {}
    for c in cols:
        data_dict[c] = data_dict_unfiltered[c]

    name = params['name']
    if name in ['tasks','fitness','all','cdata','res']:
        pass
    else:
        raise Exception('unhandled graph type: '+name)


    nplots = len(cols)
    fig.clear()
    widths = params.get('widths',1)
    last_y = zeros(window)
    ct =mycolors.getct(len(cols))

        
    
    do_fold = False
    if fold_ts and nplots > 9: 
        do_fold = True

    if do_fold:
        all_cols = [cols[0:nplots/2],cols[nplots/2:]]
    else: all_cols = [cols]
    
    
    j = 0
    colors = ct[(nplots/len(all_cols)*j):(nplots/len(all_cols)*(j+1))]
    yvals = zeros(   (len(all_cols[j])  ,window  )   )    
    for i in range(len(all_cols[j])):
        c = all_cols[j][i]            
        n = min(window, len(data_dict[c]))
        y_sm = data_dict[c][-n:]    
        yvals[i,-n:] = y_sm    
        
    seismic(fig, yvals, colors, cols)

    up.color_legend(fig, colors, cols,pos = 3)

    
    print 'Current level: ', cols[0], data_dict[cols[0]][-1]

    plt.draw()
    
    
    if   name == 'res' and do_grid_resources == True:
        grid_resources(cols)
        


    return
示例#4
0
文件: tests.py 项目: bh0085/compbio
  nx = int(ceil(sqrt(len(gbks))))
  ny = int(ceil(sqrt(len(gbks))))
  
  f = plt.figure(1)

  f.clear()
  for i in range(len(gbks)):
    xv,yv = divmod(i,nx)
    ax = f.add_subplot('{0}{1}{2}'.format(nx,ny, i), xlim = [-.2,1.2], ylim = [-.2,1.2], frameon=True)
    
    maptRNAs(gbks[i], ax)


tcols = {}
tct =  mycolors.getct(64)
lvls = 7
functype = 'blank'

def maptRNAs(gbkfile, ax = None):

  grec = SeqIO.parse(gbkfile, 'genbank')

  grec = list(grec)[0].features
  blank_speedfun = lambda x :\
      x.type == 'tRNA' and 2 \
      or x.type == 'gene' and 2 \
      or x.type == 'CDS' and 2 \
      or 0

  speedfun = lambda x :\