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

[Feature & Bug] Xenium explorer displaying both Cellpose and Baysor boundaries #120

Open
lguerard opened this issue Sep 7, 2024 · 6 comments

Comments

@lguerard
Copy link
Contributor

lguerard commented Sep 7, 2024

Hi all,

I just run sopa on a Merscope data and ran both Cellpose and Baysor to improve the segmentation.
My SpatialData object contains all the results as you can see here :

SpatialData object
├── Images
│     └── 'sopa_data_for_sopa_z3': DataTree[cyx] (1, 52053, 27977), (1, 26026, 13988), (1, 13013, 6994), (1, 6506, 3497), (1, 3253, 1748)
├── Points
│     └── 'sopa_data_for_sopa_transcripts': DataFrame with shape: (<Delayed>, 10) (2D points)
├── Shapes
│     ├── 'baysor_boundaries': GeoDataFrame shape: (35199, 1) (2D shapes)
│     ├── 'cellpose_boundaries': GeoDataFrame shape: (38190, 1) (2D shapes)
│     └── 'sopa_patches': GeoDataFrame shape: (180, 3) (2D shapes)
└── Tables
      └── 'table': AnnData (38190, 1)
with coordinate systems:
    ▸ '_2075797613936_intrinsic', with elements:
        sopa_data_for_sopa_transcripts (Points), baysor_boundaries (Shapes)
    ▸ 'global', with elements:
        sopa_data_for_sopa_z3 (Images), sopa_data_for_sopa_transcripts (Points), baysor_boundaries (Shapes), cellpose_boundaries (Shapes), sopa_patches (Shapes)

However, when I run sopa.io.write(os.path.join(result_folder, basename + ".explorer"), sdata, image_key, gene_column=gene_column), Xenium only shows cells as cellpose_boundaries.

I even tried sopa.io.write(os.path.join(result_folder, basename + ".explorer"), sdata, image_key, shapes_key = 'baysor_boundaries', gene_column=gene_column) but Xenium still shows the same.

  1. Is this a bug ?
  2. Would it be possible to show both in Xenium ? I was expecting that not adding the shapes_key would display everything.
  3. I have cells found outside of my sample, any ideas why ?
    image

Thanks for your help !

@quentinblampey
Copy link
Collaborator

Hello @lguerard,
Sopa should show the Baysor boundaries by default, and you should be able to choose the segmentation you want to show (exactly as you did, using shapes_key), so this is definitely a bug! Thanks for reporting, I'll have a look into this (although I'm quite busy these days, so I don't know yet when I'll be able to do that).

Regarding the cells outside of the sample, this is typically a cellpose artefact. You can easily remove this by a filter on the DAPI intensity, there is a parameter for that called min_intensity_ratio, see here for more details. For instance you can choose min_intensity_ratio=0.1. This parameter is also available in the CLI or snakemake pipeline, let me know if you need more information!

@lguerard
Copy link
Contributor Author

Thanks for the tip with the min_intensity_ratio, I'll have a look.

And super for the Xenium, please let me know if I can help/do anything.
In the end, I managed to show the baysor_boundaries but I would still really like to see both to check how things are improving or not.

Thanks again !

@quentinblampey
Copy link
Collaborator

Hello @lguerard, I saw Luca recommended trying Napari. Did you try that?

Napari is more flexible than the Xenium Explorer, and better for developers. The Xenium Explorer is mainly used for PI who prefer a simple and user-friendly interface.
Therefore, I also think that for your specific use-case, i.e. comparing CellPose and Baysor, the solution is probably to use Napari.

Let me know if it works for you and if you still need the feature in the Xenium Explorer!

@lguerard
Copy link
Contributor Author

Hello @quentinblampey,

I have started looking into using Napari instead yes, I still need to figure out how best to load the different layers. Once I have this, I can report back here and maybe do a PR to complete the documentation ? :)

@quentinblampey
Copy link
Collaborator

Yes, please report back!

Regarding the documentation, I was actually intending to update it to mention Napari in the tutorials
For now, I only mention the Xenium Explorer and spatialdata-plot, but it may be indeed better to also say some words about Napari

@KunHHE
Copy link

KunHHE commented Nov 30, 2024

Hi @quentinblampey, I ran Xenium using 10X shared datasets but get error that I never see when I run merscope data. I found in the .zarr folder-shapes: no cellpose_boundaries generation, but as you see I ran cellpose prior to those step. The error showed in CLI after run "sopa aggregate C:/Users/hekun/Downloads/Xenium_V1.zarr --gene-column feature_name --average-intensities --min-transcripts 5" : ValueError: sdata object has no valid segmentation boundary. Consider running Sopa segmentation first. How was the issue be resolved? Thansk very much!

sopa read C:/Users/hekun/Downloads/Xenium_V1 --technology xenium

sopa patchify image C:/Users/hekun/Downloads/Xenium_V1.zarr --patch-width-pixel 6000 --patch-overlap-pixel 150

sopa segmentation cellpose C:/Users/hekun/Downloads/Xenium_V1.zarr --diameter 30 --channels DAPI --flow-threshold 2 --cellprob-threshold -6 --model-type cyto3 --min-area 400 --clip-limit 0.2 --gaussian-sigma 1

sopa patchify baysor C:/Users/hekun/Downloads/Xenium_V1.zarr --config-path C:/Users/hekun/sopa/workflow/config/xenium/xenium.toml --patch-width-microns 1200 --patch-overlap-microns 20
#mandatory
sopa aggregate C:/Users/hekun/Downloads/Xenium_V1.zarr --gene-column feature_name --average-intensities --min-transcripts 5

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

3 participants