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

Overlay custom shape onto cell boundaries from Xenium #547

Closed
EST09 opened this issue Apr 17, 2024 · 3 comments
Closed

Overlay custom shape onto cell boundaries from Xenium #547

EST09 opened this issue Apr 17, 2024 · 3 comments

Comments

@EST09
Copy link

EST09 commented Apr 17, 2024

Hi,

This may be a question for SOPA but I thought it was also worth asking here as well please.

I have custom polygon segmentation for a particular cell type derived from H&E. I've added this as a shape to my spatialdata object in the same coordinate system as cell boundaries (the default Xenium segmentation). I'd love to overlay this custom segmentation onto the default Xenium cell segmentation (cell boundaries) so that any cells/transcripts in the default under the custom segmentation get merged into the custom segmentation but the other cells from the default are kept.

In an ideal world I'd end up a new segmentation which is mostly cell_boundaries with the custom segmentation replacing cells it overlaid.

I've been struggling a bit with how to achieve this and was wondering if the functionalities already present in spatialdata/SOPA. I've been looking at https://spatialdata.scverse.org/en/latest/tutorials/notebooks/notebooks/examples/tables.html, a use case for table, but haven't managed to implement it yet.

Best wishes,
Emily

@giovp
Copy link
Member

giovp commented Apr 23, 2024

hi @EST09 thank you for the question, this is a very interesting use case that we currently do not support. I quickly googled at potential solutions in shapely/geopandas and found these two that it is worth to take a look:

  1. https://shapely.readthedocs.io/en/stable/manual.html#shapely.ops.unary_union
  2. https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.union.html

I think if the two shapes have the same index (i.e. a row refers to the same cells, in the two segmentation view), the second option could be relatively straightforward, that would output a new shape (union) that you could parse and make the default for the table annotations. HTH

@EST09
Copy link
Author

EST09 commented Apr 23, 2024

Thank you so much for getting back to me. I ended up initially using the GeoPandas overlay function but also asked SOPA the same question and he's very kindly implemented a new feature which I'm hoping to try soon. Thank you for spatial data - it's a really fantastic package and I'm v much enjoying using it

@LucaMarconato
Copy link
Member

Thanks for the appreciated feedback, and great to hear that now the feature is implemented in SOPA! 🎉 I'll close the issue.

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