Span(location=-math.log10(0.05 / len(source.data['index'])), dimension='width', render_mode='css', line_color='darkblue') ] ) labels = np.arange(10, 100, 10) / 100 labels = np.append([0.001, 0.01, 0.05], labels) coords = -np.log10(labels) coords = coords.tolist() # plot.yaxis[0].ticker = bokeh.models.tickers.FixedTicker(ticks=coords) y_ticker = bokeh.models.tickers.FixedTicker(ticks=coords) plot.ygrid[0].ticker = y_ticker plot.set(x_range=Range1d(-1.1, 1.1), y_range=Range1d(min(source.data['y']), 10 ** 3) ) sliders = VBox( p_value_text, HBox(p_value, p_mult), HBox(left_limit, right_limit)) button_box = VBox( HBox(*buttons[:3]), HBox(*buttons[3:]) ) save_filename = bokeh.models.TextInput() save_button = bokeh.models.Button(label='Save') input_box = HBox(
def plotTracks(preds,tag,n=3,title=None,width=820,height=None, seqdepot=None,bcell=None,exp=None): """Plot epitopes as parallel tracks""" from bokeh.models import Range1d,HoverTool,FactorRange,Grid,GridPlot,ColumnDataSource from bokeh.plotting import Figure alls=1 if title == None: title=tag for m in preds: alls += len(preds[m].data.groupby('allele')) if height==None: height = 130+10*alls yrange = Range1d(start=0, end=alls+3) plot = Figure(title=title,title_text_font_size="11pt",plot_width=width, plot_height=height, y_range=yrange, y_axis_label='allele', tools="xpan, xwheel_zoom, resize, hover, reset, save", background_fill="#FAFAFA", toolbar_location="below") h=3 if bcell != None: plotBCell(plot, bcell, alls) if seqdepot != None: plotAnnotations(plot,seqdepot) if exp is not None: plotExp(plot, exp) #plotRegions(plot) #lists for hover data #we plot all rects at once x=[];y=[];allele=[];widths=[];clrs=[];peptide=[] predictor=[];position=[];score=[];leg=[] l=80 for m in preds: pred = preds[m] cmap = mpl.cm.get_cmap(colormaps[m]) df = pred.data sckey = pred.scorekey pb = pred.getPromiscuousBinders(data=df,n=n) if len(pb) == 0: continue l = pred.getLength() grps = df.groupby('allele') alleles = grps.groups.keys() if len(pb)==0: continue c=colors[m] leg.append(m) for a,g in grps: b = pred.getBinders(data=g) b = b[b.pos.isin(pb.pos)] #only promiscuous b.sort('pos',inplace=True) scores = b[sckey].values score.extend(scores) pos = b['pos'].values position.extend(pos) x.extend(pos+(l/2.0)) #offset as coords are rect centers widths.extend([l for i in scores]) clrs.extend([c for i in scores]) y.extend([h+0.5 for i in scores]) alls = [a for i in scores] allele.extend(alls) peptide.extend(list(b.peptide.values)) predictor.extend([m for i in scores]) h+=1 source = ColumnDataSource(data=dict(x=x,y=y,allele=allele,peptide=peptide, predictor=predictor,position=position,score=score)) plot.rect(x,y, width=widths, height=0.8, #x_range=Range1d(start=1, end=seqlen+l), color=clrs,line_color='gray',alpha=0.7,source=source) hover = plot.select(dict(type=HoverTool)) hover.tooltips = OrderedDict([ ("allele", "@allele"), ("position", "@position"), ("peptide", "@peptide"), ("score", "@score"), ("predictor", "@predictor"), ]) seqlen = pred.data.pos.max()+l plot.set(x_range=Range1d(start=0, end=seqlen+1)) plot.xaxis.major_label_text_font_size = "8pt" plot.xaxis.major_label_text_font_style = "bold" plot.ygrid.grid_line_color = None plot.yaxis.major_label_text_font_size = '0pt' plot.xaxis.major_label_orientation = np.pi/4 #js,html = embedPlot(plot) script, div = embedPlot(plot) return script, div