예제 #1
0
    ys_entire = np.sum(common_otu_entire[np.ix_(windows_entire_ids, otus_dn_cols)], axis=1)
    ys_entire_dn.append(ys_entire)
    trace = go.Box(
        y=ys_entire,
        name="W" + str(w_id + 1),
        boxpoints=box_points,
        marker_color=marker_color,
        line_color=line_color
    )
    traces_entire_dn.append(trace)

layout = go.Layout(
    margin=get_margin(),
    autosize=True,
    showlegend=False,
    xaxis=get_axis(''),
    yaxis=get_axis('Cumulated Abundance')
)

fig = go.Figure(data=traces_t0_dp, layout=layout)
plotly.offline.plot(fig, filename=out_path + '/cumulated_abundance_t0_diet_positive_box_plot.html', auto_open=False, show_link=True)
plotly.io.write_image(fig, out_path + '/cumulated_abundance_t0_diet_positive_box_plot.png')
plotly.io.write_image(fig, out_path + '/cumulated_abundance_t0_diet_positive_box_plot.pdf')

fig = go.Figure(data=traces_t1_dp, layout=layout)
plotly.offline.plot(fig, filename=out_path + '/cumulated_abundance_t1_diet_positive_box_plot.html', auto_open=False, show_link=True)
plotly.io.write_image(fig, out_path + '/cumulated_abundance_t1_diet_positive_box_plot.png')
plotly.io.write_image(fig, out_path + '/cumulated_abundance_t1_diet_positive_box_plot.pdf')

fig = go.Figure(data=traces_entire_dp, layout=layout)
plotly.offline.plot(fig, filename=out_path + '/cumulated_abundance_entire_diet_positive_box_plot.html', auto_open=False, show_link=True)
예제 #2
0
파일: plot.py 프로젝트: AaronBlare/mdi
def pcoa_plot(path, ord_result, common_subjects, metrics_key, metrics_dict):

    coord_matrix = ord_result.samples.values.T
    xs_all = coord_matrix[0]
    ys_all = coord_matrix[1]
    zs_all = coord_matrix[2]

    traces_3d = []
    traces_2d = []
    for status in metrics_dict:
        curr_subjects = metrics_dict[status]
        xs = []
        ys = []
        zs = []
        for subj in curr_subjects:
            index = common_subjects.index(subj)
            xs.append(xs_all[index])
            ys.append(ys_all[index])
            zs.append(zs_all[index])

        color = cl.scales['8']['qual']['Set1'][list(
            metrics_dict.keys()).index(status)]
        coordinates = color[4:-1].split(',')
        color_transparent = 'rgba(' + ','.join(coordinates) + ',' + str(
            0.3) + ')'
        color_border = 'rgba(' + ','.join(coordinates) + ',' + str(0.8) + ')'

        trace = go.Scatter3d(x=xs,
                             y=ys,
                             z=zs,
                             name=status,
                             mode='markers',
                             marker=dict(size=8,
                                         color=color_border,
                                         line=dict(color=color_transparent,
                                                   width=0.5),
                                         opacity=0.8))
        traces_3d.append(trace)

        trace = go.Scatter(x=ys,
                           y=xs,
                           name=status,
                           mode='markers',
                           marker=dict(size=8,
                                       color=color_border,
                                       line=dict(color=color_transparent,
                                                 width=0.5),
                                       opacity=0.8))
        traces_2d.append(trace)

    layout_3d = go.Layout(margin=get_margin(),
                          autosize=True,
                          legend=get_legend())

    layout_2d = go.Layout(margin=get_margin(),
                          autosize=True,
                          legend=get_legend(),
                          xaxis=get_axis("PC1"),
                          yaxis=get_axis("PC2"))

    fig_3d = go.Figure(data=traces_3d, layout=layout_3d)
    fig_3d.update_layout(scene=dict(
        xaxis=get_axis("PC1"), yaxis=get_axis("PC2"), zaxis=get_axis("PC3")))
    fig_2d = go.Figure(data=traces_2d, layout=layout_2d)

    if not os.path.exists(path):
        os.makedirs(path)

    plotly.offline.plot(fig_3d,
                        filename=path + '/pcoa_3d_' + metrics_key + '.html',
                        auto_open=False,
                        show_link=True)
    plotly.io.write_image(fig_3d, path + '/pcoa_3d_' + metrics_key + '.png')
    plotly.io.write_image(fig_3d, path + '/pcoa_3d_' + metrics_key + '.pdf')

    plotly.offline.plot(fig_2d,
                        filename=path + '/pcoa_2d_' + metrics_key + '.html',
                        auto_open=False,
                        show_link=True)
    plotly.io.write_image(fig_2d, path + '/pcoa_2d_' + metrics_key + '.png')
    plotly.io.write_image(fig_2d, path + '/pcoa_2d_' + metrics_key + '.pdf')
예제 #3
0
    ['Reduced Frailty', 'No change in Frailty', 'Increased Frailty']):

    color = cl.scales['8']['qual']['Set1'][color_id]
    coordinates = color[4:-1].split(',')
    marker_color = 'rgba(' + ','.join(coordinates) + ',' + str(1.0) + ')'

    ys = [
        frailty_changes_count['Subject'][fc_type],
        frailty_changes_count['Control'][fc_type],
    ]
    traces.append(go.Bar(x=xs, y=ys, name=fc_type, marker_color=marker_color))

layout = go.Layout(margin=get_margin(),
                   autosize=True,
                   showlegend=True,
                   xaxis=get_axis(''),
                   yaxis=get_axis('Number of subjects'))

fig = go.Figure(data=traces, layout=layout)
plotly.offline.plot(fig,
                    filename=out_path + '/frailty_changes_box_plot.html',
                    auto_open=False,
                    show_link=True)
plotly.io.write_image(fig, out_path + '/frailty_changes_box_plot.png')
plotly.io.write_image(fig, out_path + '/frailty_changes_box_plot.pdf')

traces = []
xs = ['Intervention', 'Control']
for fc_type in ['Reduced Frailty', 'Increased Frailty']:

    if fc_type == 'Reduced Frailty':
예제 #4
0
        ys.append(float(metadata_t0[code]['compliance160']) / 160.0 * 100.0 )

    color = cl.scales['8']['qual']['Set1'][countries.index(country)]
    coordinates = color[4:-1].split(',')
    marker_color = 'rgba(' + ','.join(coordinates) + ',' + str(0.5) + ')'
    line_color = 'rgba(' + ','.join(coordinates) + ',' + str(1.0) + ')'

    trace = go.Box(
        y=ys,
        name=country,
        boxpoints='outliers',
        marker_color=marker_color,
        line_color=line_color
    )

    traces.append(trace)

layout = go.Layout(
    margin=get_margin(),
    autosize=True,
    showlegend=False,
    xaxis=get_axis(''),
    yaxis=get_axis('adherence')
)

fig = go.Figure(data=traces, layout=layout)

plotly.offline.plot(fig, filename=out_path + '/adherence_t0_countries_box_plot.html', auto_open=False, show_link=True)
plotly.io.write_image(fig, out_path + '/adherence_t0_countries_box_plot.png')
plotly.io.write_image(fig, out_path + '/adherence_t0_countries_box_plot.pdf')
예제 #5
0
markers_orig_mse, markers_orig_corr = run_iterative_regressor(
    markers_orig_df, adherence[target_country], markers_orig,
    'Markers original')
non_markers_orig_mse, non_markers_orig_corr = run_iterative_regressor(
    non_markers_orig_df, adherence[target_country], non_markers_orig,
    'Non-Markers original')

traces = []
traces.append(go.Box(y=markers_orig_mse, name='Markers', boxpoints=box_points))
traces.append(
    go.Box(y=non_markers_orig_mse, name='Non-Markers', boxpoints=box_points))

layout = go.Layout(margin=get_margin(),
                   autosize=True,
                   showlegend=True,
                   xaxis=get_axis(''),
                   yaxis=get_axis('MSE across iterative models at Baseline'))

fig = go.Figure(data=traces, layout=layout)
plotly.offline.plot(fig,
                    filename=out_path + '/mse_original_boxplot_' +
                    target_country + '.html',
                    auto_open=False,
                    show_link=True)
plotly.io.write_image(
    fig, out_path + '/mse_original_boxplot_' + target_country + '.png')
plotly.io.write_image(
    fig, out_path + '/mse_original_boxplot_' + target_country + '.pdf')

traces = []
traces.append(go.Box(y=markers_orig_corr, name='Markers',
예제 #6
0
    mse[country] = run_regressor(otu_df[country], adherence[country])
    rmse[country] = np.sqrt(mse[country])

traces = []
for country in countries:
    ys = rmse[country]

    color = cl.scales['8']['qual']['Set1'][countries.index(country)]
    coordinates = color[4:-1].split(',')
    marker_color = 'rgba(' + ','.join(coordinates) + ',' + str(0.5) + ')'
    line_color = 'rgba(' + ','.join(coordinates) + ',' + str(1.0) + ')'

    traces.append(go.Box(
        y=ys,
        name=country,
        boxpoints=box_points
    ))

layout = go.Layout(
    margin=get_margin(),
    autosize=True,
    showlegend=True,
    xaxis=get_axis(''),
    yaxis=get_axis('RMSE across countries at T0')
)

fig = go.Figure(data=traces, layout=layout)
plotly.offline.plot(fig, filename=out_path + '/country_t0_box_plot.html', auto_open=False, show_link=True)
plotly.io.write_image(fig, out_path + '/country_t0_box_plot.png')
plotly.io.write_image(fig, out_path + '/country_t0_box_plot.pdf')
# plot bar plots
x = ['Baseline', 'Final']
traces = []
for status in frailty_statuses:
    if status in obs_dict_t0['frailty_status']:
        y_t0 = len(obs_dict_t0['frailty_status'][status])
    else:
        y_t0 = 0
    ys = [y_t0, len(obs_dict_t1['frailty_status'][status])]

    traces.append(go.Bar(x=x, y=ys, name=status))

layout = go.Layout(margin=get_margin(),
                   autosize=True,
                   showlegend=True,
                   xaxis=get_axis(''),
                   yaxis=get_axis('Number of subjects'))

fig = go.Figure(data=traces, layout=layout)
plotly.offline.plot(fig,
                    filename=out_path + '/frailty_status_box_plot.html',
                    auto_open=False,
                    show_link=True)
plotly.io.write_image(fig, out_path + '/frailty_status_box_plot.png')
plotly.io.write_image(fig, out_path + '/frailty_status_box_plot.pdf')

f = open(path + '/' + dr_otus_source + '/diet_positive.txt')
otus_dp = f.read().splitlines()
f.close()
otus_dp_cols = np.array(
    [common_otu_col_dict[x] for x in otus_dp if x in common_otu_col_dict])