예제 #1
0
def update_dr(color, alpha):
    fig_sc = st.plot_stream_sc(adata, root='S1', color=[color], alpha=alpha,
                               dist_scale=0.3, show_graph=True, show_text=True, plotly=True, return_fig=True)
    fig_sc.update_layout(
        autosize=False,
        width=450,
        height=350,
        margin=dict(
            l=30,
            r=30,
            b=5,
            t=5,
            pad=4
        ),
        plot_bgcolor='rgba(0,0,0,0)'
    )
    fig_st = st.plot_stream(adata, root='S1', color=[color], return_svg=True)

    fig_dr = st.plot_dimension_reduction(adata, color=[color], n_components=3, alpha=alpha, show_graph=True,
                                         show_text=False, plotly=True, return_fig=True)
    fig_dr.update_layout(
        autosize=False,
        width=450,
        height=350,
        margin=dict(
            l=30,
            r=30,
            b=5,
            t=5,
            pad=4
        ),
        plot_bgcolor='rgba(0,0,0,0)'
    )

    return html.Div([
        dbc.Row([dcc.Graph(figure=fig_sc, style={'margin-left': 'auto', 'margin-right': 'auto',
                                                 'lineHeight': '60px',
                                                 'borderWidth': '1px',
                                                 'borderStyle': 'dashed',
                                                 'borderRadius': '5px'}),
                 html.Img(src="data:image/svg+xml;base64,{}".format(fig_st),
                          style={'margin-left': 'auto', 'margin-right': 'auto', 'width': '350px%', 'height': '350px',
                                 'lineHeight': '60px',
                                 'borderWidth': '1px',
                                 'borderStyle': 'dashed',
                                 'borderRadius': '5px'})]),
        html.Br(),
        dbc.Row([dcc.Graph(figure=fig_dr, style={'margin-left': 'auto', 'margin-right': 'auto',
                                                 'lineHeight': '60px',
                                                 'borderWidth': '1px',
                                                 'borderStyle': 'dashed',
                                                 'borderRadius': '5px'})
                 ])
    ])
예제 #2
0
def tab_content(active_tab):
    if active_tab == "tab-qc":

        return html.Div(id='qc-graphic'), card_qc
    elif active_tab == "tab-dr":
        return html.Div(id="dr-graphic"), card_dr
    elif active_tab == "tab-sp":
        return html.Div(id="st-graphic"), card_sp
    else:
        fig = st.plot_stream(adata, root='S1', return_svg=True)
        return html.Img(
            src="data:image/svg+xml;base64,{}".format(fig)), card_ds
예제 #3
0
def tab_content(active_tab):
    if active_tab == "tab-qc":
        fig_qc = st.plot_qc(adata,
                            jitter=0.2,
                            fig_size=(2, 2),
                            return_svg=True)
        return html.Img(
            src="data:image/svg+xml;base64,{}".format(fig_qc)), card_qc
    elif active_tab == "tab-dr":
        return html.Div(id="dr-graphic"), card_dr
    elif active_tab == "tab-sp":
        return html.Div(id="st-graphic"), card_sp
    else:
        fig = st.plot_stream(adata, root='S1', return_svg=True)
        return card_content_ds, card_ds
예제 #4
0
def update_dr(colors, alpha):
    fig5 = st.plot_stream_sc(adata,
                             root='S1',
                             color=[colors],
                             alpha=alpha,
                             dist_scale=0.3,
                             show_graph=True,
                             show_text=True,
                             plotly=True,
                             return_fig=True)
    fig6 = st.plot_stream(adata, root='S1', color=[colors], return_svg=True)

    return html.Div([
        dbc.Row([
            dbc.Col(dcc.Graph(figure=fig5), align="center"),
            dbc.Col(html.Img(src="data:image/svg+xml;base64,{}".format(fig6)),
                    align="center")
        ])
    ])
예제 #5
0
                       'label': 'Sample Datasets',
                       'value': 'sample'
                   }, {
                       'label': 'Personal Datasets',
                       'value': 'personal'
                   }],
                   inputStyle={
                       "margin-right": "20px",
                       "margin-left": "20px"
                   },
                   value='sample',
                   labelStyle={'display': 'inline-block'}),
    html.Div(id='data-selection')
])

fig_ds = st.plot_stream(adata, root='S1', return_svg=True)
fig_ds = html.Img(src="data:image/svg+xml;base64,{}".format(fig_ds))

card_content_ds_1 = dbc.FormGroup(
    [dbc.Row([dbc.Col(fig_ds)]),
     html.P(adata.uns['discription'])])

card_content_ds = dbc.Card(
    [
        dbc.CardImg(fig_ds, top=True),
        dbc.CardBody([
            html.H4("Description", className="card-title"),
            html.P(
                "Some quick example text to build on the card title and "
                "make up the bulk of the card's content.",
                className="card-text",
예제 #6
0
def stream_test_Nestorowa_2016():

    workdir = os.path.join(_root, 'datasets/Nestorowa_2016/')

    temp_folder = tempfile.gettempdir()

    tar = tarfile.open(workdir + 'output/stream_result.tar.gz')
    tar.extractall(path=temp_folder)
    tar.close()
    ref_temp_folder = os.path.join(temp_folder, 'stream_result')

    print(workdir + 'data_Nestorowa.tsv.gz')
    input_file = os.path.join(workdir, 'data_Nestorowa.tsv.gz')
    label_file = os.path.join(workdir, 'cell_label.tsv.gz')
    label_color_file = os.path.join(workdir, 'cell_label_color.tsv.gz')
    comp_temp_folder = os.path.join(temp_folder, 'stream_result_comp')

    try:
        st.set_figure_params(dpi=80,
                             style='white',
                             figsize=[5.4, 4.8],
                             rc={'image.cmap': 'viridis'})
        adata = st.read(file_name=input_file, workdir=comp_temp_folder)
        adata.var_names_make_unique()
        adata.obs_names_make_unique()
        st.add_cell_labels(adata, file_name=label_file)
        st.add_cell_colors(adata, file_name=label_color_file)
        st.cal_qc(adata, assay='rna')
        st.filter_features(adata, min_n_cells=5)
        st.select_variable_genes(adata, n_genes=2000, save_fig=True)
        st.select_top_principal_components(adata,
                                           feature='var_genes',
                                           first_pc=True,
                                           n_pc=30,
                                           save_fig=True)
        st.dimension_reduction(adata,
                               method='se',
                               feature='top_pcs',
                               n_neighbors=100,
                               n_components=4,
                               n_jobs=2)
        st.plot_dimension_reduction(adata,
                                    color=['label', 'Gata1', 'n_genes'],
                                    n_components=3,
                                    show_graph=False,
                                    show_text=False,
                                    save_fig=True,
                                    fig_name='dimension_reduction.pdf')
        st.plot_visualization_2D(adata,
                                 method='umap',
                                 n_neighbors=100,
                                 color=['label', 'Gata1', 'n_genes'],
                                 use_precomputed=False,
                                 save_fig=True,
                                 fig_name='visualization_2D.pdf')
        st.seed_elastic_principal_graph(adata, n_clusters=20)
        st.plot_dimension_reduction(adata,
                                    color=['label', 'Gata1', 'n_genes'],
                                    n_components=2,
                                    show_graph=True,
                                    show_text=False,
                                    save_fig=True,
                                    fig_name='dr_seed.pdf')
        st.plot_branches(adata,
                         show_text=True,
                         save_fig=True,
                         fig_name='branches_seed.pdf')
        st.elastic_principal_graph(adata,
                                   epg_alpha=0.01,
                                   epg_mu=0.05,
                                   epg_lambda=0.01)
        st.plot_dimension_reduction(adata,
                                    color=['label', 'Gata1', 'n_genes'],
                                    n_components=2,
                                    show_graph=True,
                                    show_text=False,
                                    save_fig=True,
                                    fig_name='dr_epg.pdf')
        st.plot_branches(adata,
                         show_text=True,
                         save_fig=True,
                         fig_name='branches_epg.pdf')
        ###Extend leaf branch to reach further cells
        st.extend_elastic_principal_graph(adata,
                                          epg_ext_mode='QuantDists',
                                          epg_ext_par=0.8)
        st.plot_dimension_reduction(adata,
                                    color=['label'],
                                    n_components=2,
                                    show_graph=True,
                                    show_text=True,
                                    save_fig=True,
                                    fig_name='dr_extend.pdf')
        st.plot_branches(adata,
                         show_text=True,
                         save_fig=True,
                         fig_name='branches_extend.pdf')
        st.plot_visualization_2D(
            adata,
            method='umap',
            n_neighbors=100,
            color=['label', 'branch_id_alias', 'S4_pseudotime'],
            use_precomputed=False,
            save_fig=True,
            fig_name='visualization_2D_2.pdf')
        st.plot_flat_tree(adata,
                          color=['label', 'branch_id_alias', 'S4_pseudotime'],
                          dist_scale=0.5,
                          show_graph=True,
                          show_text=True,
                          save_fig=True)
        st.plot_stream_sc(adata,
                          root='S4',
                          color=['label', 'Gata1'],
                          dist_scale=0.5,
                          show_graph=True,
                          show_text=False,
                          save_fig=True)
        st.plot_stream(adata,
                       root='S4',
                       color=['label', 'Gata1'],
                       save_fig=True)
        st.detect_leaf_markers(adata,
                               marker_list=adata.uns['var_genes'][:300],
                               root='S4',
                               n_jobs=4)
        st.detect_transition_markers(adata,
                                     root='S4',
                                     marker_list=adata.uns['var_genes'][:300],
                                     n_jobs=4)
        st.detect_de_markers(adata,
                             marker_list=adata.uns['var_genes'][:300],
                             root='S4',
                             n_jobs=4)
        # st.write(adata,file_name='stream_result.pkl')
    except:
        print("STREAM analysis failed!")
        raise
    else:
        print("STREAM analysis finished!")

    print(ref_temp_folder)
    print(comp_temp_folder)

    pathlist = Path(ref_temp_folder)
    for path in pathlist.glob('**/*'):
        if path.is_file() and (not path.name.startswith('.')):
            file = os.path.relpath(str(path), ref_temp_folder)
            print(file)
            if (file.endswith('pdf')):
                if (os.path.getsize(os.path.join(comp_temp_folder, file)) > 0):
                    print('The file %s passed' % file)
                else:
                    raise Exception('Error! The file %s is not matched' % file)
            else:
                checklist = list()
                df_ref = pd.read_csv(os.path.join(ref_temp_folder, file),
                                     sep='\t')
                # print(df_ref.shape)
                # print(df_ref.head())
                df_comp = pd.read_csv(os.path.join(comp_temp_folder, file),
                                      sep='\t')
                # print(df_comp.shape)
                # print(df_comp.head())
                for c in df_ref.columns:
                    # print(c)
                    if (is_numeric_dtype(df_ref[c])):
                        checklist.append(all(np.isclose(df_ref[c],
                                                        df_comp[c])))
                    else:
                        checklist.append(all(df_ref[c] == df_comp[c]))
                if (all(checklist)):
                    print('The file %s passed' % file)
                else:
                    raise Exception('Error! The file %s is not matched' % file)

    print('Successful!')

    rmtree(comp_temp_folder, ignore_errors=True)
    rmtree(ref_temp_folder, ignore_errors=True)
예제 #7
0
import matplotlib

matplotlib.use('Agg')

from app import app

### preset data
adata_computed = st.read(
    file_name='./SampleData/Nestorowa_2016/Nestorowa-2016.pkl',
    workdir='./stream_result')
adata = st.read(
    file_name='./SampleData/Nestorowa_2016/Nestorowa-2016-raw.h5ad',
    workdir='./stream_result')
adata.uns[
    'discription'] = 'This scRNA-seq dataset contains 1656 cells and 40594 genes from mouse hematopoietic stem and progenitor cell differentiation. A single-cell resolution map of mouse hematopoietic stem and progenitor cell differentiation. Blood 128, e20-31 (2016).'
fig_ds = st.plot_stream(adata_computed, root='S1', return_svg=True)

### Set optionals
available_samples = [
    'Nestorowa, S. et al. 2016', 'Harrison, S. et al. 2021',
    'Trapnell, C. et al. 2014', ' Tang, Q. et al. 2017'
]
available_normalization = [
    'Library size correction', 'TF-IDF transformation', 'None'
]
available_DR = [
    'Spectral embedding(SE)', 'Modified locally linear embedding(MLLE)',
    'UMAP', 'PCA'
]

###----- Header for data selection -----###
예제 #8
0
def update_dr(gene_source, branch, high, gene):
    if high is None:
        high = str(eval(branch)[0])
    if gene is None:
        gene = avaliable_features[0]

    if gene_source == "transition":
        data_df = adata.uns['transition_markers'][eval(branch)].round(2)

    elif gene_source == "leaf":
        data_df = adata.uns['leaf_markers'][eval(branch)].astype(float).round(2)

    elif gene_source == "diverging":
        if high == str(eval(branch)[0]):
            data_df = adata.uns['de_markers_greater'][eval(branch)].round(2)
        else:
            data_df = adata.uns['de_markers_less'][eval(branch)].round(2)

    data_df = data_df.reset_index()
    data_df.rename(columns={'index': 'gene'}, inplace=True)

    fig = go.Figure(data=[go.Table(
        header=dict(
            values=list(data_df.columns),
            line_color='darkslategray', fill_color='lightgrey',
            align='center', font=dict(color='black', size=12)
        ),
        cells=dict(values=data_df.T.values,
                   line_color='darkslategray', align='center', font=dict(color='black', size=11)
                   ))
    ])

    fig_sc = st.plot_stream_sc(adata, root='S1', color=[gene],
                               dist_scale=0.3, show_graph=True, show_text=True, plotly=True, return_fig=True)
    fig_sc.update_layout(
        autosize=False,
        width=450,
        height=350,
        margin=dict(
            l=30,
            r=30,
            b=5,
            t=5,
            pad=4
        ),
        plot_bgcolor='rgba(0,0,0,0)'
    )
    fig_st = st.plot_stream(adata, root='S1', color=[gene], return_svg=True)

    return html.Div([
        dbc.Row([dcc.Graph(figure=fig,
                           style={"maxHeight": "350px", 'width': '100%', "overflow": "scroll", 'margin-left': 'auto',
                                  'margin-right': 'auto'})]),
        html.Br(),
        dbc.Row([
            dcc.Graph(figure=fig_sc, style={'margin-left': 'auto', 'margin-right': 'auto',
                                            'lineHeight': '60px',
                                            'borderWidth': '1px',
                                            'borderStyle': 'dashed',
                                            'borderRadius': '5px'}),
            html.Img(src="data:image/svg+xml;base64,{}".format(fig_st),
                     style={'margin-left': 'auto', 'margin-right': 'auto', 'width': '350px%', 'height': '350px',
                            'lineHeight': '60px',
                            'borderWidth': '1px',
                            'borderStyle': 'dashed',
                            'borderRadius': '5px'})]),
    ])
예제 #9
0
@app.callback(
    Output("card_C_ti", "children"),
    Output("C4-spinners", "children"),
    Input("Compute4-button", "n_clicks")
)
def loading_output(n):
    if n:
        time.sleep(10)
        return card_C_ti_finished, 'Finished'
    return "This step is not ready yet. Click the COMPUTE button above and waite it to finish.", "Compute Step 4"


### Fill in contents for each card body
# DS
fig_ds = st.plot_stream(adata_computed, root='S1', return_svg=True)

card_assay = dbc.Card(
    [
        dbc.CardImg(src="/assets/Data_selection/Assays.png", top=True,
                    style={'width': '110px', 'margin-left': 'auto', 'margin-right': 'auto', 'marginTop': 5}),
        dbc.CardBody(
            html.H5("RNA", className="card-text", style={"text-align": 'center'})
        ),
    ], color="dark", outline=True
)

card_cell = dbc.Card(
    [
        dbc.CardImg(src="/assets/Data_selection/NumCells.png", top=True,
                    style={'width': '110px', 'margin-left': 'auto', 'margin-right': 'auto', 'marginTop': 5}),