broadinstitute / Tangram

Spatial alignment of single cell transcriptomic data.
BSD 3-Clause "New" or "Revised" License
238 stars 46 forks source link

Map multimodal data such as SHARE-seq to reveal spatial patterns of chromatin accessibility #45

Open daixinap opened 2 years ago

daixinap commented 2 years ago

Hi, thank you very much for developing such a helpful tool! I am interested in mapping multimodal data such as SHARE-seq to reveal spatial patterns of chromatin accessibility, but I don't know how to do that. I can map snRNA-seq to spatial data, but I have no idea to transfer snATAC-seq profile of the same cells to space. I want to visualize inferred spatial patterns of chromatin accessibility and transcription factor motif scores at single-cell resolution. Thank you very much if there is a tutorial or code.

gaddamshreya commented 2 years ago

Hi @daixinap,

Thank you for your interest in Tangram! We're glad you like it! You should be able to map snATAC-seq with spatial data as follows:


Let me know if this solution helped solve your issue! I'd be happy to help otherwise. 

Edit: Added changes per suggestions below i.e., align with RNA-Seq data and project ATAC-seq data over space. 
daixinap commented 2 years ago

Hi @gaddamshreya,

Thanks very much for your prompt reply! I downloaded the multimodal scATAC-seq data to map and the result is very great. Since there is no annotated information, I have drawn some specific transcription factors (chromatin accessibility and motif scores). I would like to know why you only emphasize the use of multimodal data (SHARE-seq) in your published paper. I think scATAC-seq data can be used to map even if there is no corresponding scRNA-seq data. Your kind help and swift reply is highly appreciated.

image image image

lewlin commented 2 years ago

Mh - I am a bit confused about what is happening.

When you map, you don't want to align the single cell ATAC-seq data with the spatial RNA data, because the signals are different. What Tangram does, is to align data from the same modality, for example, RNA from single cells with RNA on the spatial data.

If your single cell data are multi-modal (like SHARE-seq, where you measure RNA and ATAC), once you map RNA using map_cell_to_space you can then transfer the other mode (eg ATAC) to space using project_cell_annotations.

I am not exactly sure what your figures are showing (even though the look pretty :)): it is possible that you are visualizing gene expression. If you walk me through your example by pasting code, I'll help.

daixinap commented 2 years ago

Hi @lewlin @gaddamshreya

Thank you for your prompt reply. According to gaddamshreya‘s suggestion before editing, I mapped motif score matrix with spatial data directly (so as gene scores). According to the new suggestions I tried to map RNA and then transfer ATAC, but It looks like the results were wrong. In addition to the spatial pattern of ATAC cell types, I also need to plot spatial patterns of transcription factor motif scores (calculated by R package chromVAR).

Here is code that I mapped motif score matrix with spatial data directly:

path = os.path.join('sp.h5ad')
ad_sp = sc.read_h5ad(path)

path = os.path.join('chromvar.h5ad')
ad_sc = sc.read_h5ad(path)

markers = list(ad_sc.var_names) # use all 746 TF motifs
tg.pp_adatas(ad_sc, ad_sp, genes=markers)

assert ad_sc.uns['training_genes'] == ad_sp.uns['training_genes']

ad_map = tg.map_cells_to_space(
    adata_sc=ad_sc,
    adata_sp=ad_sp,
    device='cpu',
    #device='cuda:0',
)

ad_ge = tg.project_genes(adata_map=ad_map, adata_sc=ad_sc)
genes = ['sox2', 'dlx1', 'lhx2', 'emx1']
ad_map.uns['train_genes_df'].loc[genes]

tg.plot_genes_sc(genes, adata_measured=ad_sp, adata_predicted=ad_ge, spot_size=1.5, perc = 0.001, return_figure=False)
plt.savefig('marTF_chromvar.png')

Here is code that I mapped RNA and then transfer ATAC:

path = os.path.join('sp.h5ad')
ad_sp = sc.read_h5ad(path)

path = os.path.join('multiModal_rna.h5ad')
ad_sc = sc.read_h5ad(path)

path = os.path.join('chromvar.h5ad')
ad_atac = sc.read_h5ad(path)

df_genes = pd.read_csv('markers.csv', index_col=0)
markers = np.reshape(df_genes.values, (-1, )) # 553 marker genes
tg.pp_adatas(ad_sc, ad_sp, genes=markers)

assert ad_sc.uns['training_genes'] == ad_sp.uns['training_genes']

ad_map = tg.map_cells_to_space(
    adata_sc=ad_sc,
    adata_sp=ad_sp,
    device='cpu',
    #device='cuda:0',
)

ad_ge = tg.project_genes(adata_map=ad_map, adata_sc=ad_atac) # ATAC and RNA data have the same obs_names

genes = ['sox2', 'dlx1', 'lhx2', 'emx1']
ad_map.uns['train_genes_df'].loc[genes]

tg.plot_genes_sc(genes, adata_measured=ad_sp, adata_predicted=ad_ge, spot_size=1.5, perc = 0.001, return_figure=False)
plt.savefig('multiModal_marTF_chromvar.png')

Your kind help and swift reply is highly appreciated.

daixinap commented 2 years ago

Here is result that I mapped RNA and then transfer ATAC (motif scores): E13 5_multiModal_marTF_chromvar