Example #1
0
def update_figure_polar(value, value_main_tab, value_analysis, gene_name):
    if gene_name is None:
        raise Exception()
    else:
        if value_main_tab == 'main-tab-2' and value_analysis == 'temporal':
            array_gene_time = np.concatenate(
                (gene_data[gene_name]['rep1'], gene_data[gene_name]['rep2'],
                 gene_data[gene_name]['rep3'][:, [0, 2]]),
                axis=1)

            l_time_reg = []
            for x in range(8):
                l_time_reg.append(
                    LinearRegression.make_time_regression(
                        array_gene_time[x, :], simple=False, predict=True))
            l_time_reg_simple = []
            for x in range(8):
                l_time_reg_simple.append(
                    LinearRegression.make_time_regression(
                        array_gene_time[x, :], simple=True, predict=False))

            #correct value
            value = int(value) - 1

            B, SE, adj_r2, aic, bic, pv, X_pred, Y_pred = l_time_reg[value]
            [mu_1, a_1, b_1] = B.flatten()
            [std_mu_1, std_a_1, std_b_1] = np.diagonal(SE)
            bic_1 = bic
            aic_1 = aic
            r2_1 = adj_r2

            B_simple, SE_simple, adj_r2_simple, aic_simple, bic_simple, pv_simple = l_time_reg_simple[
                value]
            [mu_2] = B_simple.flatten()
            [std_mu_2] = np.diagonal(SE_simple)
            bic_2 = bic_simple
            aic_2 = aic_simple
            r2_2 = adj_r2_simple

            table_model_1 = html.Table([
                html.Tr([
                    Styled_th('Parameter'),
                    Styled_th('Mean'),
                    Styled_th('SE')
                ],
                        style={'background-color': colorscale[5]}),
                html.Tr([
                    Styled_th(dash_katex.DashKatex(expression='\mu'),
                              {'background-color': colorscale[5]}),
                    Styled_th('{:.2e}'.format(mu_1)),
                    Styled_th('{:.2e}'.format(std_mu_1))
                ]),
                html.Tr([
                    Styled_th(dash_katex.DashKatex(expression='a'),
                              {'background-color': colorscale[5]}),
                    Styled_th('{:.2e}'.format(a_1)),
                    Styled_th('{:.2e}'.format(std_a_1))
                ]),
                html.Tr([
                    Styled_th(dash_katex.DashKatex(expression='b'),
                              {'background-color': colorscale[5]}),
                    Styled_th('{:.2e}'.format(b_1)),
                    Styled_th('{:.2e}'.format(std_b_1))
                ])
            ])

            table_model_2 = html.Table([
                html.Tr([
                    Styled_th('Parameter'),
                    Styled_th('Mean'),
                    Styled_th('SE')
                ],
                        style={'background-color': colorscale[5]}),
                html.Tr([
                    Styled_th(dash_katex.DashKatex(expression='\mu'),
                              {'background-color': colorscale[5]}),
                    Styled_th('{:.2e}'.format(mu_2)),
                    Styled_th('{:.2e}'.format(std_mu_2))
                ])
            ])
            table_comparison = html.Table([
                html.Tr([
                    Styled_th('Model'),
                    Styled_th('BIC'),
                    Styled_th('AIC'),
                    Styled_th(
                        dash_katex.DashKatex(expression='\\text{Adj. } R^2'))
                ],
                        style={'background-color': colorscale[5]}),
                html.Tr([
                    Styled_th('Intercept-only',
                              {'background-color': colorscale[5]}),
                    Styled_th('{:.2e}'.format(bic_2)),
                    Styled_th('{:.2e}'.format(aic_2)),
                    Styled_th('{:.2e}'.format(r2_2))
                ]),
                html.Tr([
                    Styled_th('Oscillatory',
                              {'background-color': colorscale[5]}),
                    Styled_th('{:.2e}'.format(bic_1)),
                    Styled_th('{:.2e}'.format(aic_1)),
                    Styled_th('{:.2e}'.format(r2_1))
                ])
            ])

            time_domain = np.concatenate(
                (np.linspace(0, 24, 4, endpoint=False),
                 np.linspace(0, 24, 4, endpoint=False),
                 np.linspace(0, 24, 2, endpoint=False)))
            x = int(value)
            B, SE, adj_r2, aic, bic, pv, X_pred, Y_pred = l_time_reg[x]
            figure = Figures.compute_figure_time_tab_3(
                time_domain, array_gene_time[x, :], X_pred,
                Y_pred)  #, yaxis_type, yaxis_scale)

            return [
                html.Div(children=[
                    html.Div(children=[
                        html.H6('Intercept-only model',
                                style={'textAlign': 'center'}), table_model_2
                    ]),
                    html.Div(children=[
                        html.H6('Oscillatory model',
                                style={'textAlign': 'center'}), table_model_1
                    ]),
                    html.Div(children=[
                        html.H6('Models comparison',
                                style={'textAlign':
                                       'center'}), table_comparison,
                        html.
                        P('P-value associated with the oscillatory model (ANOVA): '
                          + str(pv))
                    ],
                             style={
                                 'display': 'flex',
                                 'flex-direction': 'column'
                             }),
                ],
                         style={
                             'display': 'flex',
                             'flex-direction': 'row',
                             'justify-content': 'space-around',
                             'flex-wrap': 'wrap',
                             'flex-align': 'baseline'
                         }),
                dcc.Graph(id='graph-stat-time',
                          figure=figure,
                          config={
                              'displayModeBar': False,
                              'modeBarButtonsToRemove': [],
                              'displaylogo': False
                          },
                          style={'width': '60vw'})
            ]
        else:
            raise PreventUpdate