cellxgene icon indicating copy to clipboard operation
cellxgene copied to clipboard

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

Open aeisenbarth opened this issue 1 year ago • 3 comments

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):

  • Desktop or hosted?: Desktop
  • Browser: Firefox
  • Version: 1.0.1

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.

aeisenbarth avatar Aug 08 '22 17:08 aeisenbarth

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

MaximilianLombardo avatar Aug 09 '22 17:08 MaximilianLombardo

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

colinmegill avatar Oct 25 '22 19:10 colinmegill

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.

aeisenbarth avatar Oct 26 '22 09:10 aeisenbarth