Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using TableModel.parse, region_key must be provided. #306

Closed
yedeer12 opened this issue Jun 21, 2023 · 4 comments · Fixed by #455
Closed

When using TableModel.parse, region_key must be provided. #306

yedeer12 opened this issue Jun 21, 2023 · 4 comments · Fixed by #455

Comments

@yedeer12
Copy link

I want to use TableModel.parse to parse the whole anndata, I set region=None, region_key=None, instance_key=None. But there is an error says region_key must be provided. Could I combine the anndata and spatialdata without region and region_key?
image

image

@giovp
Copy link
Member

giovp commented Jun 22, 2023

hi @yedeer12 ,

no you can't, spatialdata assumes that when a table it's present, it annotates a region element (shapes, labels).

We are working toward building a converter for anndata to spatialdata for anndata that are already available. pinging @LLehner who is working on it.

@EliHei2
Copy link
Collaborator

EliHei2 commented Jun 27, 2023

Related to this, @giovp, if one plug in an anndata as the table using sd.TableModel.parse if the region_key column is not existing in the .obs the function does not return an error, while if one save the whole SpatialData object and try to reload it, they will receive the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/e915i/.conda/envs/py39/lib/python3.9/site-packages/spatialdata/_io/io_zarr.py", line 85, in read_zarr
    sdata = SpatialData(
  File "/home/e915i/.conda/envs/py39/lib/python3.9/site-packages/spatialdata/_core/spatialdata.py", line 161, in __init__
    Table_s.validate(table)
  File "/home/e915i/.conda/envs/py39/lib/python3.9/site-packages/spatialdata/models/models.py", line 644, in validate
    raise ValueError(f"`{attr[self.REGION_KEY_KEY]}` not found in `adata.obs`.")
ValueError: `None` not found in `adata.obs`.

I used the defaults (hence region_key=None)

I suggest either assert this in the TableModel.parse or write or drop the assert in read_zarr.

@LucaMarconato
Copy link
Member

Thanks @EliHei2, I think we should assert it in TableModel.parse().

@LucaMarconato
Copy link
Member

Now with #455, we support multiple tables and also tables that are not associated with any set of geometries (i.e. region_key not provided).

@LucaMarconato LucaMarconato linked a pull request Feb 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants