Beispiel #1
0
    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)
Beispiel #2
0
 def update_header(target, event):
     names = web.get_file_lists(event.new)
     target.object = "_total sequences: %s_" % str(len(names))
     return
Beispiel #3
0
def predictions_dashboard(path):
    """Dashboard for viewing results from epitopepredict runs."""

    #folder_input = pn.widgets.TextInput(name='path', value='../zaire_test', width=400,width_policy='fit')
    #reload_btn = pn.widgets.Button(name='reload',width=100,button_type='primary')

    names = web.get_file_lists(path)
    if names is None:
        return
    preds = web.get_predictors(path, name=names[0])
    print(preds)
    seqname = pnw.Select(name='name', value=names[0], options=names)
    cutoff_slider = pnw.FloatSlider(name='cutoff',
                                    value=.95,
                                    start=.75,
                                    end=.99,
                                    step=0.01)
    cutoff_method = pnw.Select(name='cutoff method',
                               value='default',
                               options=['default', 'rank'])
    n_select = pnw.FloatSlider(name='n', value=1, start=1, end=8, step=1)
    plot_select = pnw.Select(name='plot view',
                             value='tracks',
                             options=['tracks', 'sequence'])
    table_select = pnw.Select(name='table view',
                              value='promiscuous',
                              options=['promiscuous', 'binders'])
    colorseq_box = pnw.Checkbox(name='color sequences', value=False)

    header = pn.pane.Markdown('__total sequences: %s__' % len(names),
                              css_classes=['main'])
    tables = pn.Tabs(width=900)
    plot = pn.pane.Bokeh(width=800)
    debug = pn.pane.Markdown('test',
                             style={
                                 'font-size': '10pt',
                                 'background-color': 'yellow'
                             })
    summary_plot = pn.pane.Bokeh()
    summary_table_tabs = pn.Tabs()
    recalc_button = pnw.Button(name='recalculate', width=200)

    def update_banner():
        """Update the banner"""

        fullpath = os.path.abspath(path)
        banner = pn.Row(
            pn.pane.Markdown(
                '<h4>epitopepredict: %s</h4> [help](%s) version %s' %
                (fullpath, helppage, __version__),
                css_classes=['divheader'],
                sizing_mode='stretch_width'))
        return banner

    def update_header(target, event):
        names = web.get_file_lists(event.new)
        target.object = "_total sequences: %s_" % str(len(names))
        return

    def callback_getpath(event):
        path = os.path.getcwd()
        folder.value = path

    def update_plot(preds, name, cutoff, n, kind):
        """Plot data view"""

        if kind == 'tracks':
            p = plotting.bokeh_plot_tracks(preds,
                                           name=name,
                                           cutoff=cutoff,
                                           n=n,
                                           width=1000,
                                           title=name)
            plot.object = p
        elif kind == 'sequence':
            p = plotting.bokeh_plot_sequence(preds,
                                             name=name,
                                             cutoff=cutoff,
                                             n=n,
                                             width=1000,
                                             title=name,
                                             color_sequence=colorseq_box.value)
            plot.object = p
        return p

    def update_tables(preds, name, n):
        """Tabular views of results"""

        P = preds[0]
        view = table_select.value
        tables.clear()
        for P in preds:
            if view == 'promiscuous':
                df = P.promiscuous_binders(n=n, name=name)
            else:
                df = P.get_binders(name=name)
            res = df.to_html(classes="tinytable sortable")
            div = '<div class="scrollingArea">%s</div>' % res
            tables.append((P.name, div))
            #tables.append((P.name,pn.pane.HTML('<p>hddsadsadsasda</p>',width=700)))
        return

    def update(event):
        """Update all elements"""

        name = seqname.value
        n = n_select.value
        cutoff = cutoff_slider.value
        kind = plot_select.value
        debug.object = name
        preds = web.get_predictors(path, name=name)
        update_plot(preds, name=name, cutoff=cutoff, n=n, kind=kind)
        update_tables(preds, name, n)
        return

    def update_summary(path):
        """Summary info for folder"""

        data = web.get_summary_tables(path)
        df = pd.concat(data, sort=True).reset_index()
        #plot = plotting.bokeh_summary_plot(df)
        #summary_plot.object = plot
        summary_table_tabs.clear()
        a = web.aggregate_summary(data)
        div = web.get_scrollable_table(a)
        summary_table_tabs.append(('all', div))
        names = list(data.keys())
        for n in names:
            df = data[n]
            res = df.to_html(classes="tinytable sortable")
            div = '<div class="scrollingArea">%s</div>' % res
            summary_table_tabs.append((n, div))
        return

    @pn.depends(seqname.param.value, n_select.param.value)
    def download_link(name, n):
        if preds is None:
            return
        df = preds[0].promiscuous_binders(n=n, name=name)
        df.to_csv()
        return pn.Pane(HTML('<a>download</a>'), width=700)

    info = pn.pane.Markdown(web.get_readme())
    banner = update_banner()
    update_summary(path)
    #reload_btn.param.watch(load_predictors, 'clicks')
    #reload_btn.param.trigger()
    seqname.param.watch(update, 'value')
    cutoff_slider.param.watch(update, 'value')
    n_select.param.watch(update, 'value')
    table_select.param.watch(update, 'value')
    plot_select.param.watch(update, 'value')
    seqname.param.trigger('options', 'value')

    top = pn.Row(header)  #,download_link)
    left = pn.Column(plot, tables, margin=10, sizing_mode='stretch_width')
    right = pn.Column(seqname,
                      cutoff_slider,
                      cutoff_method,
                      n_select,
                      plot_select,
                      table_select,
                      colorseq_box,
                      css_classes=['widget-box'],
                      width=200)
    center = pn.Row(left, right)
    #bottom = pn.Row(table)
    main = pn.Column(top, center)
    summarypane = pn.Column(recalc_button, (pn.Row(summary_table_tabs)))
    tabs = pn.Tabs(('summary', summarypane), ('sequence', main),
                   ('about', info))
    #tabs.append()
    app = pn.Column(banner, tabs, sizing_mode='stretch_width')
    return app