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

[Bug]"Could not find element with name ['cell_circles']" #117

Open
Yifan-debug opened this issue Sep 2, 2024 · 7 comments
Open

[Bug]"Could not find element with name ['cell_circles']" #117

Yifan-debug opened this issue Sep 2, 2024 · 7 comments

Comments

@Yifan-debug
Copy link

Dear Developer,

I'm trying to use the sopa to output the xenium file, so I can open it with xenium.
but I got the error said no cell circles, I actually have this one in my spatialdata (pelase check the image)
Please let me know how to solve it.

image


KeyError Traceback (most recent call last)
Cell In[8], line 4
2 query_sdata
3 explorer_path = "./Crop_sdata"
----> 4 sopa.io.write(explorer_path, query_sdata)

File d:\Yifan_Wang\Software\envs\sopa\lib\site-packages\sopa\io\explorer\converter.py:113, in write(path, sdata, image_key, shapes_key, points_key, gene_column, pixel_size, layer, polygon_max_vertices, lazy, ram_threshold_gb, mode, save_h5ad)
110 adata = sdata.tables[SopaKeys.TABLE]
112 shapes_key = adata.uns["spatialdata_attrs"]["region"]
--> 113 geo_df = sdata[shapes_key]
115 if _should_save(mode, "c"):
116 write_gene_counts(path, adata, layer=layer)

File d:\Yifan_Wang\Software\envs\sopa\lib\site-packages\spatialdata_core\spatialdata.py:2124, in SpatialData.getitem(self, item)
2111 def getitem(self, item: str) -> SpatialElement:
2112 """
2113 Return the element with the given name.
2114
(...)
2122 The element.
2123 """
-> 2124 _, _, element = self._find_element(item)
2125 return element

File d:\Yifan_Wang\Software\envs\sopa\lib\site-packages\spatialdata_core\spatialdata.py:2031, in SpatialData.find_element(self, element_name)
2028 found.append((element_type, element_name
, element))
2030 if len(found) == 0:
-> 2031 raise KeyError(f"Could not find element with name {element_name!r}")
2033 if len(found) > 1:
2034 raise ValueError(f"Found multiple elements with name {element_name!r}")

KeyError: "Could not find element with name ['cell_circles']"

@quentinblampey
Copy link
Collaborator

Hello @Yifan-debug, can you show me which line of code you used to get this error? My guess is that you provided shapes_key=["cell_circles"] instead of shapes_key="cell_circles". Indeed, the key should be a str corresponding to the name of the spatial element, and we don't handle lists of strings (yet).

@Yifan-debug
Copy link
Author

import sopa

Hi @quentinblampey

Here is the line which got this error.
explorer_path = "./Crop_sdata"
sopa.io.write(explorer_path, query_sdata)
Actually, I tried to read the xenium data with spatial_io.xenium and then write back to xenium with sopa.io.write and got the same error.

@quentinblampey
Copy link
Collaborator

I think I understand the error now, but this is due to the fact that your data is not formated as an output of Sopa. Indeed, the sopa.io.write function expects that the SpatialData object has been segmented and aggregated via Sopa, which is not the case here.

Can you try this, though? sopa.io.write(explorer_path, query_sdata, shapes_key="cell_circles")

@Yifan-debug
Copy link
Author

image
Hi it's the same error code

@quentinblampey
Copy link
Collaborator

Okay, thanks for giving a try. I'll try to fix sopa.io.write to make it more general, i.e. handle non-sopa outputs.

What is your actual use case? I have a few questions, it will help me better understand what you want to do:

  • are you satisfied with the current Xenium segmentation?
  • which objects from the visualization do you want to update? Indeed, since you already have Xenium data, I guess you already have the visualization files. For instance, do you want to update the cell boundaries? Or, for instance, do you only want to re-create the visualization files for one crop?
  • are you planning to perform analysis using the SpatialData object, or you use it only as a temporary object to update the visualization?

@Yifan-debug
Copy link
Author

Hi @quentinblampey
Thank you so much for helping. Please let me know when the package is updated
For the questions:
1 I'm not satisfied with the current Xenium segmentation and currently looking for some other segmentation methods.
2 I want to create the visualization files for just one crop, and if it can be 3D visualization would be perfect for me.
3 Yes. I am planning to use spatial data objects for my following analyses.

@quentinblampey
Copy link
Collaborator

Thanks for sharing these details! In that case, since you want to use Sopa for segmentation, you should do the following:

  1. Read only the morphology_focus and transcripts elements in your SpatialData object (you don't need the others). The boundaries and the table will be created when using Sopa. Note that, by default, sopa.io.xenium only loads the latter elements.
  2. Then, run Sopa according to the tutorials, using either the API or CLI or Snakemake pipeline.
  3. Then, you'll have boundaries (Cellpose or Baysor) and a new table. These elements have the right format and you'll be able to use sopa.io.write to visualize it.

Hope that helps, let me know!
Still, I keep the issue open, as I'll try to fix it to make the writing more general to non-Sopa formats :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants