scanpy icon indicating copy to clipboard operation
scanpy copied to clipboard

Store multiple Umap Coordinates

Open maflot opened this issue 3 years ago • 2 comments

Set name for storing Umap coordinates explicitly in tl.umap and pl.umap tl.umap(..., x_umap = "X_umap") pl.umap(..., x_umap = "X_umap")

Sometimes it would be helpful to specify the adata obsm field for storing the umap coordinates. For example : -if I want to compute and plot the umap for the raw data and afterwards for the integrated or in any way modified data. The first x_umap is going to be overwritten and needs to be computed again, if I need to plot the first step again. So it would be cool to enable a workflow like the following:

tl.umap(adata, ..., x_umap = "X_umap_raw")
# do some operations ...
tl.umap(adata, ..., x_umap = "X_umap_mod)

# now after computation I might need to take a look on both umaps again, or plot them in direct comparison
pl.umap(adata, ..., x_umap = "X_umap_raw")
pl.umap(adata, ..., x_umap = "X_umap_mod")

I hope I was able to explain what I mean and did not oversee such feature or misunderstood the usage. All the best maflot

maflot avatar Apr 28 '22 07:04 maflot

You can store different versions of coordinates in adata like so before you overwrite it

adata.obsm['X_umap_mod'] = adata.obsm['X_umap'].copy()

And then use pl.embedding to plot the embedding by specifying the new name:

sc.pl.embedding(adata, basis='X_umap_mod')

Edit: it is necessary to use copy() otherwise changing values of one obsm would affect the other.

racng avatar Jun 08 '22 21:06 racng

You are right, still I think this could be done in a more elegant way. For example the sc.tl.leiden(adata,neighbors_key = "some_key") stores the computed values with the name of the key. It would be cool to just add this to pl.umap() As you can already refer to the neighbors_key, why not add the x_umap as x_umap_neighbors_key?

Edit: The same holds for computing the leiden obs information, which is always stored as leiden and not leiden_neighbors_key.

maflot avatar Aug 25 '22 12:08 maflot