Beispiel #1
0
def display_value(group_chosen, compare_1_chosen, compare_2_chosen,
                  compare_3_chosen):
    # df_fltrd = df[df['Genre'] == genre_chosen]
    # df_fltrd = df_fltrd.nlargest(10, sales_chosen)
    # fig = px.bar(df_fltrd, x=compare_1_chosen, y=compare_2_chosen, color='Platform')
    # fig = fig.update_yaxes(tickprefix="$", ticksuffix="M")

    print(group_chosen)
    print(compare_1_chosen)
    print(compare_2_chosen)
    print(compare_3_chosen)

    rootBranchesLeaves = [group_chosen, compare_1_chosen]
    if compare_2_chosen.lower() != 'none':
        rootBranchesLeaves.append(compare_2_chosen)
    if compare_3_chosen.lower() != 'none':
        rootBranchesLeaves.append(compare_3_chosen)

    colorSequence = utilities.set_color_sequence(group_chosen)

    # Produce a sunburst plot
    fig = px.sunburst(
        data_frame=df,
        path=rootBranchesLeaves,  # Root, branches, leaves
        color=group_chosen,
        color_discrete_sequence=colorSequence,
        maxdepth=
        -1,  # set the sectors rendered. -1 will render all levels in the hierarchy
        # color="Victim's age",
        # color_continuous_scale=px.colors.sequential.BuGn,
        # range_color=[10,100],
        branchvalues="total",  # or 'remainder'
        hover_name=group_chosen,
        # hover_data={'Unarmed': False},    # remove column name from tooltip  (Plotly version >= 4.8.0)
        title=documentName.capitalize() + ' Data Sunburst Plot',
        template='ggplot2',  # 'ggplot2', 'seaborn', 'simple_white', 'plotly',
        #                                   # 'plotly_white', 'plotly_dark', 'presentation',
        #                                   # 'xgridoff', 'ygridoff', 'gridon', 'none'
        height=600,
    )

    fig.update_traces(textinfo='label+percent entry')
    fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))

    return [dcc.Graph(id='sunburst_plot' + uniqueComponentForApp, figure=fig)]
def update_line(all_rows_data, slctd_row_indices, slct_rows_names, slctd_rows,
                order_of_rows_indices, order_of_rows_names, actv_cell,
                slctd_cell, slctd_columns):
    print(
        '***************************************************************************'
    )
    print('Data across all pages pre or post filtering: {}'.format(
        all_rows_data))
    print('---------------------------------------------')
    print(
        "Indices of selected rows if part of table after filtering:{}".format(
            slctd_row_indices))
    print("Names of selected rows if part of table after filtering: {}".format(
        slct_rows_names))
    print(
        "Indices of selected rows regardless of filtering results: {}".format(
            slctd_rows))
    print('---------------------------------------------')
    print("Indices of all rows pre or post filtering: {}".format(
        order_of_rows_indices))
    print("Names of all rows pre or post filtering: {}".format(
        order_of_rows_names))
    print("---------------------------------------------")
    print("Complete data of active cell: {}".format(actv_cell))
    print("Complete data of all selected cells: {}".format(slctd_cell))
    print("---------------------------------------------")
    print("Indices of selected columns regardless of filtering results: {}".
          format(slctd_columns))

    if slctd_row_indices is None:
        slctd_row_indices = []

    dff_all = df if all_rows_data is None else pd.DataFrame(all_rows_data)
    data = []
    for index, row in dff_all.iterrows():
        for col in slctd_columns:
            dataRow = []
            dataRow.append(row['sample_name'])
            dataRow.append(col)
            dataRow.append(row[col])
            data.append(dataRow)
    dff = pd.DataFrame(data, columns=['sample_name', 'column_name', 'value'])

    colorSequence = utilities.set_color_sequence()

    # used to highlight selected countries on bar chart
    colors = [
        '#7FDBFF' if i in slctd_row_indices else '#0074D9'
        for i in range(len(dff))
    ]

    return [
        dcc.Graph(
            id='line_plot',
            figure=px.line(
                data_frame=dff,
                x='sample_name',
                y='value',
                color='column_name',
                color_discrete_sequence=colorSequence).update_layout(
                    showlegend=True,
                    # xaxis={'categoryorder': 'total ascending'},
                    yaxis={
                        'title': 'Values'
                    },
                    title={
                        'text': 'scRNA-seq Summary Line Plot',
                        'font': {
                            'size': 28
                        },
                        'x': 0.5,
                        'xanchor': 'center'
                    }).update_traces(
                        marker_color=colors,
                        hovertemplate="<b>%{y}%</b><extra></extra>"))
    ]
Beispiel #3
0
def update_bar(all_rows_data, slctd_row_indices, slct_rows_names, slctd_rows,
               order_of_rows_indices, order_of_rows_names, actv_cell,
               slctd_cell, slctd_columns):
    print(
        '***************************************************************************'
    )
    print('Data across all pages pre or post filtering: {}'.format(
        all_rows_data))
    print('---------------------------------------------')
    print(
        "Indices of selected rows if part of table after filtering:{}".format(
            slctd_row_indices))
    print("Names of selected rows if part of table after filtering: {}".format(
        slct_rows_names))
    print(
        "Indices of selected rows regardless of filtering results: {}".format(
            slctd_rows))
    print('---------------------------------------------')
    print("Indices of all rows pre or post filtering: {}".format(
        order_of_rows_indices))
    print("Names of all rows pre or post filtering: {}".format(
        order_of_rows_names))
    print("---------------------------------------------")
    print("Complete data of active cell: {}".format(actv_cell))
    print("Complete data of all selected cells: {}".format(slctd_cell))
    print("---------------------------------------------")
    print("Indices of selected columns regardless of filtering results: {}".
          format(slctd_columns))

    if slctd_row_indices is None:
        slctd_row_indices = []

    dff = df if all_rows_data is None else pd.DataFrame(all_rows_data)
    # dff = pd.DataFrame(all_rows_data)

    colorSequence = utilities.set_color_sequence()

    # used to highlight selected countries on bar chart
    colors = [
        '#7FDBFF' if i in slctd_row_indices else '#0074D9'
        for i in range(len(dff))
    ]

    return [
        dcc.Graph(id=column,
                  figure=px.bar(
                      data_frame=dff,
                      x="sample_name",
                      y=dff[column],
                      labels={
                          "age": "Number of reads"
                      },
                      color_discrete_sequence=colorSequence).update_layout(
                          showlegend=False,
                          xaxis={
                              'categoryorder': 'total ascending'
                          },
                          title={
                              'text': 'scRNA-seq Summary Bar Plot',
                              'font': {
                                  'size': 28
                              },
                              'x': 0.5,
                              'xanchor': 'center'
                          }).update_traces(
                              marker_color=colors,
                              hovertemplate="<b>%{y}%</b><extra></extra>"))
        # check if column exists - user may have deleted it
        # If `column.deletable=False`, then you don't
        # need to do this check.
        for column in slctd_columns if column in dff
    ]
def display_value(group_chosen, compare_1_chosen, compare_2_chosen,
                  compare_3_chosen, range_1):
    # df_fltrd = df[df['Genre'] == genre_chosen]
    # df_fltrd = df_fltrd.nlargest(10, sales_chosen)
    # fig = px.bar(df_fltrd, x=compare_1_chosen, y=compare_2_chosen, color='Platform')
    # fig = fig.update_yaxes(tickprefix="$", ticksuffix="M")

    print(group_chosen)
    print(compare_1_chosen)
    print(compare_2_chosen)
    print(compare_3_chosen)
    print(range_1)

    colorSequence = utilities.set_color_sequence(group_chosen)

    # Filter based on range slider
    df['numeric_age'] = pd.to_numeric(df['age'], errors='coerce')
    dff = df[(df['numeric_age'] >= range_1[0])
             & (df['numeric_age'] <= range_1[1])]

    # Add age to title
    title = documentName.capitalize() + ' Data Scatter Plot for Ages ' + str(
        range_1[0]) + ' to ' + str(range_1[1])

    # If the third compare choice is 'none' then produce a
    # 2D scatter plot, otherwise produce a 3D scatter plot
    if compare_3_chosen.lower() == 'none':
        fig = px.scatter(
            data_frame=dff,
            x=compare_1_chosen,
            y=compare_2_chosen,
            color=group_chosen,
            color_discrete_sequence=colorSequence,
            template='ggplot2',
            title=title,
            # size='age',  # size of bubble
            # size_max=15,  # set the maximum mark size when using size
            hover_name='study_id',  # values appear in bold in the hover tooltip
            height=600)
    else:
        # Use for animation rotation at the end
        x_eye = -1.25
        y_eye = 2
        z_eye = 0.5

        fig = px.scatter_3d(
            data_frame=dff,
            x=compare_1_chosen,
            y=compare_2_chosen,
            z=compare_3_chosen,
            color=group_chosen,
            color_discrete_sequence=colorSequence,
            template='ggplot2',
            title=title,
            size='age',  # size of bubble
            size_max=15,  # set the maximum mark size when using size
            hover_name='study_id',  # values appear in bold in the hover tooltip
            height=600).update_layout(
                scene_camera_eye=dict(x=x_eye, y=y_eye, z=z_eye),
                updatemenus=[
                    dict(type='buttons',
                         showactive=False,
                         y=1,
                         x=0.8,
                         xanchor='left',
                         yanchor='bottom',
                         pad=dict(t=45, r=10),
                         buttons=[
                             dict(label='Play',
                                  method='animate',
                                  args=[
                                      None,
                                      dict(frame=dict(duration=250,
                                                      redraw=True),
                                           transition=dict(duration=0),
                                           fromcurrent=True,
                                           mode='immediate')
                                  ])
                         ])
                ])

        frames = []
        for t in np.arange(0, 6.26, 0.1):
            xe, ye, ze = rotate_z(x_eye, y_eye, z_eye, -t)
            frames.append(
                go.Frame(layout=dict(scene_camera_eye=dict(x=xe, y=ye, z=ze))))
        fig.frames = frames

    return [dcc.Graph(id='scatter_plot' + uniqueComponentForApp, figure=fig)]
Beispiel #5
0
def display_value(group_chosen, compare_1_chosen, compare_2_chosen,
                  compare_3_chosen):
    print(group_chosen)
    print(compare_1_chosen)
    print(compare_2_chosen)
    print(compare_3_chosen)

    colorSequence = utilities.set_color_sequence(group_chosen)

    # If the third compare choice is 'none' then produce a
    # 2D scatter plot, otherwise produce a 3D scatter plot
    if compare_3_chosen.lower() == 'none':
        fig = px.scatter(
            data_frame=df,
            x=compare_1_chosen,
            y=compare_2_chosen,
            color=group_chosen,
            color_discrete_sequence=colorSequence,
            template='ggplot2',
            title=documentName + ' Data Scatter Plot',
            # size='size',  # size of bubble
            # size_max=30,  # set the maximum mark size when using size
            hover_name='study_id',  # values appear in bold in the hover tooltip
            height=600)
    else:
        # Use for animation rotation at the end
        x_eye = -1.25
        y_eye = 2
        z_eye = 0.5

        fig = px.scatter_3d(
            data_frame=df,
            x=compare_1_chosen,
            y=compare_2_chosen,
            z=compare_3_chosen,
            color=group_chosen,
            color_discrete_sequence=colorSequence,
            template='ggplot2',
            title=documentName + ' Data 3D Scatter Plot',
            size='age',  # size of bubble
            size_max=15,  # set the maximum mark size when using size
            hover_name='study_id',  # values appear in bold in the hover tooltip
            height=600).update_layout(
                scene_camera_eye=dict(x=x_eye, y=y_eye, z=z_eye),
                updatemenus=[
                    dict(type='buttons',
                         showactive=False,
                         y=1,
                         x=0.8,
                         xanchor='left',
                         yanchor='bottom',
                         pad=dict(t=45, r=10),
                         buttons=[
                             dict(label='Play',
                                  method='animate',
                                  args=[
                                      None,
                                      dict(frame=dict(duration=250,
                                                      redraw=True),
                                           transition=dict(duration=0),
                                           fromcurrent=True,
                                           mode='immediate')
                                  ])
                         ])
                ])

        frames = []
        for t in np.arange(0, 6.26, 0.1):
            xe, ye, ze = rotate_z(x_eye, y_eye, z_eye, -t)
            frames.append(
                go.Frame(layout=dict(scene_camera_eye=dict(x=xe, y=ye, z=ze))))
        fig.frames = frames

    return [dcc.Graph(id='scatter_plot' + uniqueComponentForApp, figure=fig)]
Beispiel #6
0
def display_value(group_chosen, compare_1_chosen, compare_2_chosen, radioitems_1, range_1):
    # df_fltrd = df[df['Genre'] == genre_chosen]
    # df_fltrd = df_fltrd.nlargest(10, sales_chosen)
    # fig = px.bar(df_fltrd, x=compare_1_chosen, y=compare_2_chosen, color='Platform')
    # fig = fig.update_yaxes(tickprefix="$", ticksuffix="M")

    print(group_chosen)
    print(compare_1_chosen)
    print(compare_2_chosen)
    print(radioitems_1)
    print(range_1)

    colorSequence = utilities.set_color_sequence(group_chosen)

    # Filter based on range slider
    df['numeric_age'] = pd.to_numeric(df['age'], errors='coerce')
    dff = df[(df['numeric_age'] >= range_1[0]) & (df['numeric_age'] <= range_1[1])]

    # Filter based on radio items
    if radioitems_1 != 'BOTH':
        dff2 = dff[dff['phenotype'] == radioitems_1]
    else:
        dff2 = dff

    # Add age to title
    title = documentName.capitalize() + ' Violin Plot for Ages ' + str(range_1[0]) + ' to ' + str(range_1[1])

    fig = px.violin(
        # data_frame=df.query("State == ['{}','{}']".format('ALABAMA','NEW YORK')),
        data_frame=dff2,
        x=compare_1_chosen,
        y=compare_2_chosen,
        category_orders={
            'timepoint': ['D1-PRE', 'D1-POST', 'D2-PRE', 'D2-POST']},
        orientation="v",  # vertical 'v' or horizontal 'h'
        points='all',  # 'outliers','suspectedoutliers', 'all', or False
        box=True,  # draw box inside the violins
        color=group_chosen,  # differentiate markers by color
        violinmode="group",  # 'overlay' or 'group'
        color_discrete_sequence=colorSequence,
        # color_discrete_map={"ALABAMA": "blue" ,"NEW YORK":"magenta"}, # map your chosen colors

        hover_name='study_id',  # values appear in bold in the hover tooltip
        hover_data=[group_chosen, 'timepoint'],  # values appear as extra data in the hover tooltip
        # custom_data=['Program'],    # values are extra data to be used in Dash callbacks

        # facet_row='State',          # assign marks to subplots in the vertical direction
        # facet_col='Period',         # assign marks to subplots in the horizontal direction
        # facet_col_wrap=2,           # maximum number of subplot columns. Do not set facet_row

        # log_x=True,                 # x-axis is log-scaled
        # log_y=True,                 # y-axis is log-scaled

        # labels={"State": "STATE"},  # map the labels
        title=title,
        # width=1050,  # figure width in pixels
        height=600,  # igure height in pixels
        template='ggplot2',  # 'ggplot2', 'seaborn', 'simple_white', 'plotly',
        # 'plotly_white', 'plotly_dark', 'presentation',
        # 'xgridoff', 'ygridoff', 'gridon', 'none'

        # animation_frame='Year',     # assign marks to animation frames
        # animation_group='',         # use only when df has multiple rows with same object
        # range_x=[5,50],             # set range of x-axis
        # range_y=[-5,100],           # set range of y-axis
        # category_orders={'Year':[2015,2016,2017,2018,2019]},    # set a specific ordering of values per column
    )

    return [
        dcc.Graph(id='violin_plot' + uniqueComponentForApp, figure=fig)
    ]
Beispiel #7
0
def update_3d_scatter(all_rows_data, slctd_row_indices, slct_rows_names, slctd_rows,
               order_of_rows_indices, order_of_rows_names, actv_cell, slctd_cell, slctd_columns):
    print('***************************************************************************')
    print('Data across all pages pre or post filtering: {}'.format(all_rows_data))
    print('---------------------------------------------')
    print("Indices of selected rows if part of table after filtering:{}".format(slctd_row_indices))
    print("Names of selected rows if part of table after filtering: {}".format(slct_rows_names))
    print("Indices of selected rows regardless of filtering results: {}".format(slctd_rows))
    print('---------------------------------------------')
    print("Indices of all rows pre or post filtering: {}".format(order_of_rows_indices))
    print("Names of all rows pre or post filtering: {}".format(order_of_rows_names))
    print("---------------------------------------------")
    print("Complete data of active cell: {}".format(actv_cell))
    print("Complete data of all selected cells: {}".format(slctd_cell))
    print("---------------------------------------------")
    print("Indices of selected columns regardless of filtering results: {}".format(slctd_columns))

    if slctd_row_indices is None:
        slctd_row_indices = []

    dff = df if all_rows_data is None else pd.DataFrame(all_rows_data)
    dff['size'] = dff['age'] / 4

    # data = []
    # for index, row in dff_all.iterrows():
    #     for col in slctd_columns:
    #         dataRow = []
    #         dataRow.append(row['sample_name'])
    #         dataRow.append(col)
    #         dataRow.append(row[col])
    #         data.append(dataRow)
    # dff = pd.DataFrame(data, columns=['sample_name', 'column_name', 'value'])

    # used to highlight selected countries on bar chart
    # colors = ['#7FDBFF' if i in slctd_row_indices else '#0074D9'
    #           for i in range(len(dff))]

    if len(slctd_columns) < 3:
        slctd_columns = ['valid_barcodes', 'sequencing_saturation', 'q30_bases_in_barcode']

    # Use for animation rotation at the end
    x_eye = -1.25
    y_eye = 2
    z_eye = 0.5

    group_chosen = 'phenotype'
    colorSequence = utilities.set_color_sequence(group_chosen)

    fig = px.scatter_3d(
        data_frame=dff,
        x=slctd_columns[0],
        y=slctd_columns[1],
        z=slctd_columns[2],
        color=group_chosen,
        color_discrete_sequence=colorSequence,
        template='ggplot2',
        title='scRNA-seq Summary 3D Scatter Plot',
        size='size',  # size of bubble
        size_max=30,  # set the maximum mark size when using size
        hover_name='study_id',  # values appear in bold in the hover tooltip
        height=600
    ).update_layout(scene_camera_eye=dict(x=x_eye, y=y_eye, z=z_eye),
                    updatemenus=[dict(type='buttons',
                                      showactive=False,
                                      y=1,
                                      x=0.8,
                                      xanchor='left',
                                      yanchor='bottom',
                                      pad=dict(t=45, r=10),
                                      buttons=[dict(label='Play',
                                                    method='animate',
                                                    args=[None, dict(frame=dict(duration=250, redraw=True),
                                                                     transition=dict(duration=0),
                                                                     fromcurrent=True,
                                                                     mode='immediate'
                                                                     )]
                                                    )
                                               ]
                                      )
                                 ]
                    )

    frames = []
    for t in np.arange(0, 6.26, 0.1):
        xe, ye, ze = rotate_z(x_eye, y_eye, z_eye, -t)
        frames.append(go.Frame(layout=dict(scene_camera_eye=dict(x=xe, y=ye, z=ze))))
    fig.frames = frames

    return [
        dcc.Graph(id='3d_scatter_plot', figure=fig)
    ]