You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow using arbitrary vectors in plotting (not only obs columns) #1500
Additional function parameters / changed functionality / changed defaults?
New analysis tool: A simple analysis tool you have been using and are missing in sc.tools?
New plotting function: A kind of plot you would like to seein sc.pl?
External tools: Do you know an existing package that should go into sc.external.*?
Other?
Quite often I need to color UMAPs based on features that are not part of adata.X but adata.obsm for the reason that they are special. E.g. KO data with gRNAs versus endogenes/ target genes, or viral genes versus edogenes.
Example use case:
Cluster cells based on endogenes
UMAP and color by a bunch of viral genes
Clustering must not include these viral genes -> must be excluded from X.
I don't want to store so many additional columns in obs and I need to have these features separated in their own matrix for downstream analysis, which is why I want to use obsm.
Can we have sth. like this:
sc.pl.umap(adata, color='viral_genes') # adata.obsm['viral_genes'] is a pandas.DataFrame ?
It shouldn't be overcomplicated I think, since this only involves an additional check: if the elements in the color arg list are not found in obs.columns nor var.columns, then check the keys in obsm and use the entire dataframe behind this key.
The idea is to allow any vector from the anndata object to be used for coloring, but that PR seems a bit stalled at the moment. This would also be useful for providing parameters in other places, like regress_out.
changed the title [-]Support obsm key to color UMAP[/-][+]Allow using several `pp`, `tl`, and `pl` functions to operate on obsm representations[/+]on Oct 28, 2025
changed the title [-]Allow using several `pp`, `tl`, and `pl` functions to operate on obsm representations[/-][+]Allow using arbitrary vectors in plotting (not only `obs` columns)[/+]on Oct 31, 2025
This is neat! But is there not a smaller scanpy-specific fix that might cover 99% of the use-cases people might have, without the deeper infrastructure overhead that seems to be quite onerous? (using obsm feels quite obvious and useful to me, though all the extra accessors seem interesting)
In some of my own custom commands, I parse list-like strings (X_pca[:], X_pca[:10] or X_pca[2:6]) as references to obsm vectors that are expanded (e.g., ["X_pca[2]", "X_pca[3]", "X_pca[4]", "X_pca[5]"]. This is a bit like @picciama's suggestion, but doesn't opportunistically expand a string into looking in obsm (e.g., viral_genes) and auto-expanding in potentially unexpected ways into a list of column-wise vectors (e.g., ["viral_genes[0]", "viral_genes[1]", "viral_genes[2]", ...] which I read as implied by his message).
We’re open to PRs that add that stuff, as long as they are well-designed and there is no guessing!
I think one of the early design mistakes of scanpy is “search this vector in multiple parts of the AnnData object, and if it’s in multiple, don’t give any way to select which one is meant”.
Activity
ivirshup commentedon Nov 19, 2020
This has been worked on here: scverse/anndata#342
The idea is to allow any vector from the anndata object to be used for coloring, but that PR seems a bit stalled at the moment. This would also be useful for providing parameters in other places, like
regress_out.obsminstead ofX/layersin more functions #3846 as a duplicate of this issue[-]Support obsm key to color UMAP[/-][+]Allow using several `pp`, `tl`, and `pl` functions to operate on obsm representations[/+]obsminstead ofX/layersin more functions #3846 as a duplicate of this issue[-]Allow using several `pp`, `tl`, and `pl` functions to operate on obsm representations[/-][+]Allow using arbitrary vectors in plotting (not only `obs` columns)[/+]flying-sheep commentedon Oct 31, 2025
I’ll finally tackle this soon! scverse/anndata#2189
patcon commentedon Jan 13, 2026
This is neat! But is there not a smaller scanpy-specific fix that might cover 99% of the use-cases people might have, without the deeper infrastructure overhead that seems to be quite onerous? (using obsm feels quite obvious and useful to me, though all the extra accessors seem interesting)
In some of my own custom commands, I parse list-like strings (
X_pca[:],X_pca[:10]orX_pca[2:6]) as references to obsm vectors that are expanded (e.g.,["X_pca[2]", "X_pca[3]", "X_pca[4]", "X_pca[5]"]. This is a bit like @picciama's suggestion, but doesn't opportunistically expand a string into looking in obsm (e.g.,viral_genes) and auto-expanding in potentially unexpected ways into a list of column-wise vectors (e.g.,["viral_genes[0]", "viral_genes[1]", "viral_genes[2]", ...]which I read as implied by his message).flying-sheep commentedon Jan 13, 2026
We’re open to PRs that add that stuff, as long as they are well-designed and there is no guessing!
I think one of the early design mistakes of scanpy is “search this vector in multiple parts of the AnnData object, and if it’s in multiple, don’t give any way to select which one is meant”.