def get(self): args = self.request.arguments defaultargs = get_args(args) form = ControlsForm() path = defaultargs['path'] current_name = defaultargs['name'] if not os.path.exists(path): msg = help_msg() self.render('sequence.html', form=form, status=0, name='', msg=msg, path=path) return names = web.get_file_lists(path) if current_name == '': current_name = names[0] form.path.data = path form.name.choices = [(i,i) for i in names] form.name.data = current_name form.cutoff.data = defaultargs['cutoff'] form.n.data = defaultargs['n'] form.cutoff_method.data = defaultargs['cutoff_method'] form.kind.data = defaultargs['kind'] form.view.data = defaultargs['view'] preds = web.get_predictors(path, current_name) #alleles = web.get_alleles(preds) data = web.get_binder_tables(preds, **defaultargs) tables = web.dataframes_to_html(data, classes='tinytable sortable') tables = web.tabbed_html(tables) #info = web.dict_to_html(web.get_results_info(preds[0])) info='' kind = defaultargs['kind'] if kind == 'grid': seqhtml = web.sequence_to_html_grid(preds, classes="gridtable") div = '<div class="scrolled">%s</div>' %seqhtml script = '' elif kind == 'text': seqhtml = web.create_sequence_html(preds, classes="seqtable") div = '<div class="scrolled">%s</div>' %seqhtml script = '' else: plots = web.create_figures(preds, **defaultargs) if len(plots) > 0: grid = gridplot(plots, ncols=1, merge_tools=True, sizing_mode='scale_width', toolbar_options=dict(logo=None)) script, div = components(grid) else: script = ''; div = '' links = [] for k in data.keys(): defaultargs['pred'] = k links.append(self.get_url(defaultargs, link=k)) self.render('sequence.html', script=script, div=div, form=form, tables=tables, msg='', info=info, name=current_name, status=1, links=links, path=path)
def get(self): args = self.request.arguments form = SummaryForm() defaultargs = {'savepath': '', 'deletecached': 1} for k in defaultargs: if k in args: defaultargs[k] = args[k][0].decode("utf-8") savepath = defaultargs['savepath'].strip() deletecached = defaultargs['deletecached'] #if usecached == 1: # print ('using cached results') if not os.path.exists(savepath): msg = help_msg() self.render('global.html', form=form, msg=msg, savepath=savepath, status=0) data = web.get_summary_tables(savepath, **defaultargs) df = pd.concat(data).reset_index() plot = plotting.bokeh_summary_plot(df) plots = [plot] if len(plots) > 0: grid = gridplot(plots, ncols=1, merge_tools=True, sizing_mode='scale_width', toolbar_options=dict(logo=None)) script, div = components(grid) else: script = '' div = '' for k in data: data[k] = web.column_to_url( data[k], 'name', '/sequence?savepath=%s&name=' % savepath) #convert dfs to html tables = web.dataframes_to_html(data, classes='tinytable sortable') #put tables in tabbed divs tables = web.tabbed_html(tables) form.savepath.data = savepath self.render('global.html', form=form, tables=tables, msg='', script=script, div=div, status=1, savepath=savepath)
def get(self): args = self.request.arguments form = ControlsForm() defaultargs = {'path':'','cutoff':5,'cutoff_method':'rank', 'view':'promiscuous','n':2,'cached':1} for k in defaultargs: if k in args: defaultargs[k] = args[k][0] path = defaultargs['path'].strip() view = defaultargs['view'] usecached = defaultargs['cached'] if usecached == 1: print ('using cached results') if not os.path.exists(path): msg = help_msg() self.render('global.html', form=form, msg=msg, path=path, status=0) preds = web.get_predictors(path) data = {} if view == 'summary': for P in preds: if P.data is None: continue seqs = web.get_sequences(P) #tables = web.sequences_to_html_table(seqs, classes="seqtable") pb = P.promiscuousBinders(**defaultargs) #print (pb) #cl = analysis.find_clusters(b, min_binders=2) x = pb.groupby('name').agg({'peptide':np.size, P.scorekey:np.median}).reset_index() x = x.rename(columns={'peptide':'binders'}) x = x.merge(seqs, on='name', how='right') x = web.column_to_url(x, 'name', '/sequence?path=%s&name=' %path) data[P.name] = x else: data = web.get_binder_tables(preds, **defaultargs) #add url to prot/seq name for k in data: data[k] = web.column_to_url(data[k], 'name', '/sequence?path=%s&name=' %path) #convert dfs to html tables = web.dataframes_to_html(data, classes='tinytable sortable') #put tables in tabbed divs tables = web.tabbed_html(tables) form.path.data = path form.cutoff.data = defaultargs['cutoff'] form.n.data = defaultargs['n'] form.cutoff_method.data = defaultargs['cutoff_method'] form.view.data = view self.render('global.html', form=form, tables=tables, msg='', status=1, path=path)
def get(self): args = self.request.arguments form = NeoForm() args = get_args(args, defaults={ 'savepath': '', 'view': 'final', 'sample': None }) savepath = args['savepath'] view = args['view'] sample = args['sample'] if not os.path.exists(savepath): self.no_data_render(form, msg='no such path') return labels = pd.read_csv(os.path.join(savepath, 'sample_labels.csv'), index_col=0) samples = list(labels.index) if sample == None: sample = samples[0] print(view) #get results data data = OrderedDict() plots = [] preds = [] s = sample if sample == 'all': s = samples[0] for p in base.predictors: f = os.path.join(savepath, 'results_%s_%s.csv' % (s, p)) if os.path.exists(f): preds.append(p) if sample == 'all': #get all results together for p in preds: data['summary'] = labels res = [] for sample in samples: fname = os.path.join(savepath, 'binders_%s_%s.csv' % (sample, p)) b = pd.read_csv(fname, index_col=0) res.append(b) res = pd.concat(res).reset_index() x = pd.pivot_table(res, index=['name', 'peptide'], columns=['label'], values='score') data[p] = x else: #get table for variants variant_file = os.path.join(savepath, 'variant_effects_%s.csv' % sample) if not os.path.exists(variant_file): self.no_data_render(form, msg='no such file %s' % variant_file) return variants = pd.read_csv(variant_file, index_col=0) #data['variants'] = variants for p in preds: binder_file = fname = os.path.join( savepath, 'binders_%s_%s.csv' % (sample, p)) if not os.path.exists(binder_file): resfile = os.path.join(savepath, 'results_%s_%s.csv' % (sample, p)) res = pd.read_csv(resfile, index_col=0) #get binders here if new cutoff used else: pb = pd.read_csv(binder_file) pb = pb.drop('label', 1) #top genes with most peptides? t = pb['name'].value_counts()[:20] bar = plotting.bokeh_vbar( t, title='top genes with peptide binders: %s' % p, color='#41b6c4') plots.append(bar) self.add_links(pb) #limit table size! data[p] = pb[:1000] x = variants.variant_class.value_counts() pie = plotting.bokeh_pie_chart(x, radius=.25, title='variant classes', height=150) plots.append(pie) #test = plotting.bokeh_test(height=200) v = variants x = v.chr.value_counts().sort_index() bar2 = plotting.bokeh_vbar(x, title='variants per chromosome', color='#225ea8') plots.append(bar2) tables = web.dataframes_to_html(data, classes='sortable') tables = web.tabbed_html(tables) if len(plots) > 0: grid = gridplot(plots, ncols=1, nrows=3, merge_tools=True, sizing_mode='scale_width', toolbar_options=dict(logo=None)) script, div = components(grid) else: script = '' div = '' form.savepath.data = savepath samples.append('all') form.sample.choices = [(i, i) for i in samples] form.sample.data = sample self.render('neoepitope.html', status=1, savepath=savepath, links='', form=form, script=script, div=div, tables=tables)