Ejemplo n.º 1
0
        def switch_plot_tab(at):
            pca_data = PCAModel()
            plot_data = pca_data.get_plot_data()
            pca_data.load_results()
            pca_data.load_labels()
            theme = get_plot_theme()
            if at == 'score-plot-tab':
                score_plots = [
                    pca_data.get_score_plot(plot['ordinate'],
                                            plot['abscissa'],
                                            plot['applicate'],
                                            plot['color_by'],
                                            plot['include_db_index'],
                                            plot['label_by'],
                                            plot['encircle_by'],
                                            plot['include_centroid'],
                                            plot['include_medoid'],
                                            theme=theme)
                    for plot in plot_data['score_plots']
                ]

                return [
                    dbc.Card(
                        dbc.CardBody(
                            [item for pair in score_plots for item in pair]))
                ]
            elif at == 'loadings-plot-tab':
                return [
                    dbc.Card(
                        dbc.CardBody([
                            pca_data.get_loading_plot(plot['indices'],
                                                      theme=theme)
                            for plot in plot_data['loading_plots']
                        ]))
                ]
            elif at == 'variance-plot-tab':
                return [
                    dbc.Card(
                        dbc.CardBody([
                            pca_data.get_variance_plot(plot['scale_y'],
                                                       plot['indices'],
                                                       theme=theme)
                            for plot in plot_data['variance_plots']
                        ]))
                ]
            elif at == 'cumulative-variance-plot-tab':
                return [
                    dbc.Card(
                        dbc.CardBody([
                            pca_data.get_cumulative_variance_plot(
                                plot['threshold'], theme=theme)
                            for plot in plot_data['cumulative_variance_plots']
                        ]))
                ]
            else:
                return [
                    dbc.Card(
                        dbc.CardBody(html.H6('This should never be reached.')))
                ]
Ejemplo n.º 2
0
 def selection_changed(relayout_data, queries, labels):
     if relayout_data is not None:
         if 'xaxis.range[0]' and 'xaxis.range[1]' in relayout_data:
             val1, val2 = relayout_data['xaxis.range[0]'], relayout_data['xaxis.range[1]']
             x_min = min(val1, val2)
             x_max = max(val1, val2)
             viz_data = VisualizationModel(True)
             return [viz_data.get_summary(queries, labels, x_min, x_max, get_plot_theme())]
     return ['']
Ejemplo n.º 3
0
 def update_plot(n_clicks, queries, group_by, labels, bin_collection_id, legend_style, background_color):
     VisualizationDashboard.check_clicks(n_clicks)
     print(background_color)
     if not queries:
         raise PreventUpdate('Nothing to plot!')
     viz_data = VisualizationModel(True)
     return [
         viz_data.get_plot(queries, group_by, labels, get_plot_theme(), bin_collection_id, legend_style,
                           background_color)
     ]
Ejemplo n.º 4
0
 def update_plot(spectrum_index, region_min, region_max, show_box):
     show_box = 'show_range_box' in show_box
     spectrum_index = spectrum_index if spectrum_index is not None else 0
     model = CollectionProcessingModel(True)
     theme = get_plot_theme()
     return [
         model.get_plot(spectrum_index, show_box, region_min,
                        region_max, theme), {
                            'editable': show_box
                        },
         [html.Strong('Processing log: '), f'{model.processing_log}']
     ]
Ejemplo n.º 5
0
 def get_plots(
     self,
     score_plot_data,
     loading_plot_data,
     variance_plot_data,
     cumulative_variance_plot_data,
     include_db_index_tables=True
 ) -> (List[Union[dcc.Graph, dash_table.DataTable]], List[dcc.Graph], List[
         dcc.Graph], List[dcc.Graph]):
     self.load_labels()
     self.load_results()
     from dashboards.dashboard import get_plot_theme
     theme = get_plot_theme()
     score_plots = [
         self.get_score_plot(plot['ordinate'],
                             plot['abscissa'],
                             plot['applicate'],
                             plot['color_by'],
                             include_db_index_tables
                             and plot['include_db_index'],
                             plot['label_by'],
                             plot['encircle_by'],
                             plot['include_centroid'],
                             plot['include_medoid'],
                             theme=theme) for plot in score_plot_data
     ]
     return ([item for pair in score_plots
              for item in pair] if include_db_index_tables else
             [pair[0] for pair in score_plots], [
                 self.get_loading_plot(plot['indices'], theme=theme)
                 for plot in loading_plot_data
             ], [
                 self.get_variance_plot(plot['scale_y'],
                                        plot['indices'],
                                        theme=theme)
                 for plot in variance_plot_data
             ], [
                 self.get_cumulative_variance_plot(plot['threshold'],
                                                   theme=theme)
                 for plot in cumulative_variance_plot_data
             ])
Ejemplo n.º 6
0
 def switch_results_tab(at):
     try:
         opls_data = OPLSModel()
         theme = get_plot_theme()
         if at == 'summary-tab':
             return [
                 dbc.Card(
                     dbc.CardBody(opls_data.get_summary_tables(theme)))
             ]
         elif at == 'quality-tab':
             return [
                 dbc.Card(
                     dbc.CardBody(opls_data.get_quality_plots(theme)))
             ]
         elif at == 'kde-tab':
             return [
                 dbc.Card(
                     dbc.CardBody(
                         opls_data.get_metric_kde_plots(theme)))
             ]
         elif at == 'feature-significance-tab':
             return [
                 dbc.Card(
                     dbc.CardBody(
                         opls_data.get_loading_significance_tables(
                             theme)))
             ]
         else:
             return [dbc.Card(dbc.CardBody(html.H6('Error occurred.')))]
     except Exception as e:
         log_internal_exception(e)
         return [
             dbc.Card(
                 dbc.CardBody([
                     html.H6('Error occurred.'),
                     html.Code(traceback.format_exc())
                 ]))
         ]
Ejemplo n.º 7
0
        def action_button(finalize_n_clicks, normalize_n_clicks,
                          baseline_n_clicks, region_n_clicks,
                          normalization_method, norm_sum,
                          region_peak_intensity, norm_label, hist_ref_type,
                          hist_ref_query, pqn_ref_type, pqn_ref_query,
                          baseline_method, rolling_ball_min_max,
                          rolling_ball_smoothing, region_method,
                          spectrum_index, region_min, region_max, show_box):
            try:
                model = CollectionProcessingModel(True)
                if not any([
                        finalize_n_clicks, normalize_n_clicks,
                        baseline_n_clicks, region_n_clicks
                ]):
                    raise PreventUpdate('Callback triggered without action!')
                if normalize_n_clicks and (normalize_n_clicks !=
                                           model.normalize_n_clicks):
                    print(
                        f'normalize: ({normalize_n_clicks}, {model.normalize_n_clicks})'
                    )
                    pqn_ref_query = ' | '.join(
                        pqn_ref_query
                    ) if pqn_ref_query and len(pqn_ref_query) else None
                    hist_ref_query = ' | '.join(
                        hist_ref_query
                    ) if hist_ref_query and len(hist_ref_query) else None
                    model.normalize(
                        normalization_method,
                        norm_sum=norm_sum,
                        region_peak_intensity=region_peak_intensity,
                        norm_label=norm_label,
                        region_min=region_min,
                        region_max=region_max,
                        hist_ref_type=hist_ref_type,
                        hist_ref_query=hist_ref_query,
                        pqn_ref_type=pqn_ref_type,
                        pqn_ref_query=pqn_ref_query)
                    model.normalize_n_clicks = normalize_n_clicks
                if baseline_n_clicks and (baseline_n_clicks !=
                                          model.baseline_n_clicks):
                    print(
                        f'baseline: ({baseline_n_clicks}, {model.baseline_n_clicks})'
                    )
                    model.correct_baseline(
                        baseline_method,
                        rolling_ball_min_max=rolling_ball_min_max,
                        rolling_ball_smoothing=rolling_ball_smoothing)
                    model.baseline_n_clicks = baseline_n_clicks
                if region_n_clicks and (region_n_clicks !=
                                        model.region_n_clicks):
                    print(
                        f'region: ({region_n_clicks}, {model.region_n_clicks})'
                    )
                    model.process_region(region_method, region_min, region_max)
                    model.region_n_clicks = region_n_clicks
                if finalize_n_clicks and (finalize_n_clicks !=
                                          model.finalize_n_clicks):
                    print(
                        f'finalize: ({finalize_n_clicks}, {model.finalize_n_clicks})'
                    )
                    model.finalize()
                    model.finalize_n_clicks = finalize_n_clicks

                show_box = 'show_range_box' in show_box
                theme = get_plot_theme()
                figure = model.get_plot(spectrum_index, show_box, region_min,
                                        region_max, theme)
            except Exception as e:
                print(e)
                traceback.print_exc()
                figure = None

            return [
                dcc.Graph(id='preview-graph',
                          config={'editable': True},
                          figure=figure),
                html.P([
                    html.Strong('Processing log: '), f'{model.processing_log}'
                ],
                       id='processing-log')
            ]