STREAM icon indicating copy to clipboard operation
STREAM copied to clipboard

mapping scATAC-seq data with precomputated UMAP

Open ccshao opened this issue 3 years ago • 1 comments

First thanks for the nice tool!

I was trying to mapping two scATAC-seq data, eg, ko to wt, with stream v1.0

In both datasets I used the precomputated UMAP projections. The codes for wt is shown bellow, in which the steps on add umap were taken from https://github.com/pinellolab/STREAM/issues/100#issuecomment-746414477.

import stream as st
import pandas as pd

st.__version__

st.set_figure_params(dpi=300,
                     style='white',
                     figsize=[5.4, 4.8],
                     rc={'image.cmap': 'viridis'})

adata = st.read(file_name='wt_counts.tsv.gz', workdir='./result_atac')
st.add_cell_labels(adata, file_name='wt_cell_label.tsv')
st.add_cell_colors(adata, file_name='wt_cell_label_col.tsv')

st.cal_qc(adata, assay='atac')
st.normalize(adata, method='tf_idf')
st.select_top_principal_components(adata, first_pc=False, n_pc=50, save_fig=True)

#- Precompuated umap.
umap_res = pd.read_csv("wt_umap.csv", sep="\t")

adata.obsm['X_dr'] = umap_res.to_numpy()
adata.obsm['X_vis_umap'] = umap_res.to_numpy()

st.plot_visualization_2D(adata,
                         n_neighbors=100,
                         color=['label'],
                         use_precomputed=True,
                         save_fig=True)

st.seed_elastic_principal_graph(adata, n_clusters=3, use_vis=True)
st.elastic_principal_graph(adata, epg_alpha=0.05)

However, when trying to align ko to wt:

adata_wt = st.read(file_name='CR_wt_atac_peaks.pkl')
adata_ko = st.read(file_name='CR_ko_atac_peaks.pkl')
adata_all = st.map_new_data(adata_wt, adata_ko)

Got the error:

Traceback (most recent call last): File "", line 1, in File "/home/shao/miniconda3/envs/env_stream/lib/python3.7/site-packages/stream/core.py", line 4040, in map_new_data feature = adata_ref.uns['params']['dimension_reduction']['feature'] KeyError: 'dimension_reduction'

In the source, I saw there is an transform step.

    if(method == 'umap'):
        if('trans_umap' in adata_ref.uns_keys()):
            trans = adata_ref.uns['trans_umap']
            adata_new.obsm['X_umap_mapping'] = trans.transform(input_data)
            adata_new.obsm['X_dr'] = adata_new.obsm['X_umap_mapping'].copy()
        else:
            raise Exception("Please run 'st.dimension_reduction()' using 'umap' first.")  

As I am using the precompuated umap, how could I instruct stream to use that projection?

Thanks and I am happy to provide more details if needed!

ccshao avatar May 25 '22 09:05 ccshao

Hi @ccshao were you able to figure this out in the end and would you be so kind to share the solution? Encountering the same problem here.

Thanks,

Jore

JVW1993 avatar Oct 07 '25 12:10 JVW1993