chanzuckerberg / cellxgene

An interactive explorer for single-cell transcriptomics data
https://chanzuckerberg.github.io/cellxgene/
MIT License
614 stars 116 forks source link

[BUG] Spatial coordinates not detected as layout/embedding for AnnData #2553

Open aeisenbarth opened 2 years ago

aeisenbarth commented 2 years ago

Describe the bug

When loading a spatial AnnData file, only embeddings like "pca", "umap" are offered but not "spatial". According to the documentation, it should be possible to display spatial x, y coordinates.

To Reproduce Steps to reproduce the behavior:

  1. Download a spatial AnnData file: https://github.com/scverse/squidpy/blob/03ee8faa12d1fc7fe2b8edb4386941a1c96f49ce/tests/_data/test_data.h5ad
  2. Launch cellxgene with the downloaded .h5ad file
  3. Click on 'Embedding Choice'

Expected behavior Spatial coordinates should be shown as another choice next to available embeddings.

Version (please complete the following information):

Additional context By convention, Scanpy/Squidpy store spatial coordinates in a 2-dimensional obsm column named "spatial". However, CellXGene's AnnData adapter looks only for obsm columns prefixed with X_, like X_umap for embedding "umap". This means another branch needs to be added that checks for the presence of obsm["spatial"] (not prefixed) and adds it with the same name to available embeddings.

MaximilianLombardo commented 2 years ago

Hey @aeisenbarth thanks for this bug report. One quick clarification:

How come it is not sufficient to simply rename your spatial embedding in the resulting AnnData object to X_spatial?

According to the anndata docs, the obsm key need not be defined strictly as spatial - see the screenshot below

image
colinmegill commented 1 year ago

@aeisenbarth checking back in on this — is this issue resolved with the above fix?

aeisenbarth commented 1 year ago

Hello, yes, renaming works around the issue (with the downside of not being in line with scanpy's default; we aim to generate standard scanpy AnnData files). To satisfy scanpy and CellXGene, I could also copy the key, consuming more disk space and having redundancy.

If that is the solution, it would be helpful to mention it in the documentation, which can be easily understood that default spatial coordinates would be supported.