martinjzhang / scDRS

Single-cell disease relevance score (scDRS)
https://martinjzhang.github.io/scDRS/
MIT License
98 stars 11 forks source link

Issues Plotting UMAP from quick start tutorial #68

Closed NaomiHuntley closed 10 months ago

NaomiHuntley commented 1 year ago

Dear Dr. Zhang, I worked through the tutorial and it worked well on the test data. However, when I try to plot a UMAP of my own data with the 'tabula-muris-senis-facs-official-raw-obj.h5ad' anndata, I am unable to get the UMAP enrichment plots to work. My thought is that

I get this error:
KeyError: "Could not find 'umap' or 'X_umap' in .obsm"

When I run this code: sc.set_figure_params(figsize=[2.5, 2.5], dpi=150) sc.pl.umap( adata, color="tissue", ncols=1, color_map="RdBu_r", vmin=-5, vmax=5, )

My thought is that there is not UMAP data to plot, and perhaps the UMAP data was included in the 'expr.h5ad' file, but I haven't been able to figure out a solution. Could you please provide details about how I can get this to work for a new dataset?

Thank you in advance!

martinjzhang commented 1 year ago

Hi @NaomiHuntley

You can recompute the UMAP embeddings. Let adata_raw be the AnnData object for the raw count data. I use the following code for generating the processed data adata with the UMAP embeddings:

adata = adata_raw.copy()
sc.pp.normalize_per_cell(adata, counts_per_cell_after=1e4)
sc.pp.log1p(adata)

sc.pp.highly_variable_genes(adata, subset = False, min_disp=.5, 
                            min_mean=.0125, max_mean=10, n_bins=20, n_top_genes=None)
sc.pp.scale(adata, max_value=10, zero_center=False)
sc.pp.pca(adata, n_comps=50, use_highly_variable=True, svd_solver='arpack')
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=20)
sc.tl.louvain(adata, resolution = 0.5)
sc.tl.leiden(adata, resolution = 0.5)
sc.tl.umap(adata)

The UMAP embeddings should be stored at adata.obsm['X_umap'].

Let me know if you have more questions.

Best, Martin