-
Notifications
You must be signed in to change notification settings - Fork 7
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 segmentation using cell segmentation resolver #55
Comments
Hello @EST09, Thanks for your interest in Sopa. I have a few questions to ensure I understand correctly what you want to do:
In any case, this will be possible with Sopa, I'm trying to answer your question as accurately as possible! |
Thanks for providing these details! I confirm that this can be done with Sopa, but it requires combining a few different functions from the API I'll add a new function to make it easy to use (actually, I also need this for some of my projects, so I needed to do implement it anyway). |
Thank you so much, that would be brilliant if possible! |
Hello @EST09, I think it's because at least one of your shapes is a Meanwhile, I implemented the feature, and you can test it on If you want to try it, here is some code to help you: import sopa.io
from sopa.segmentation import overlay_segmentation
gene_column = "feature_name"
overlay_segmentation(sdata, shapes_key="custom_segmentation", gene_column=gene_column)
You should then have a new shapes_key = ... # something like "cell_boundaries+custom_segmentation"
sopa.io.write(
"file_path", sdata=sdata, shapes_key=shapes_key, gene_column=gene_column, mode="+cob"
) |
Thank you so much! That's fantastic, esp. the updating transcripts in only new cells! I'll try it out tomorrow. You were totally right about Multipolygons, ended up using geopandas explode to solve it, this seems a lot quicker though). Thanks! |
Hello @EST09, just wanted to let you know that I released |
Sorry for the delay in getting back, thank you a lot for all your help with this! |
Hello @EST09, is everything working as expected? Should I close the issue? |
Hi, I actually ended up using a slightly different segmentation in the end, to fill in the gaps around the custom cells, but used your aggregator to compile the table. I did try your segmentation at first and all worked as expected, thank you, although I end up with a slightly different table of counts. I don't know if it's a quirk of my Xenium segmentation but in order to get the aggregator to work (for either your or my changed segmentation) I needed to make the cells valid (using .make_valid()). This transformed some cells into multipolygons and then I chose largest polygon in the multipolygon going forward to represent that cell. After using your aggregator, and checking only the unchanged cells I end up with slightly different counts per cell. I'm putting this down to choosing the largest polygon but I do need to investigate further/not sure if you've come across this issue? I also had a quick question about which transcripts are used in the aggregation. I've set gene_name as feature_name and this gives me 541 (as it includes the control probes) rather than the 377 genes. I ended up just subsetting the anndata back down to the 377 genes but was wondering if you knew if there was a column that did this directly?
Thank you! I think it's basically closable - I think the issues are minor or a quirk of my data I need to investigate but would be interested if you've come across these before - thank you! Best wishes, |
Hi, Indeed it's weird to have a different transcript count. Just to make sure I understand what you did: you tried the two aproaches below, right?
The Concerning your last question, no I think there is no way to prevent this for now. So, subsetting the anndata object is needed, even though it may be inconvenient, I agree... |
Hi,
Thank you for SOPA, it looks really helpful. I'd love to use the cell segmentation resolver. However, I'm struggling a little with how best to implement.
I have custom segmentation for a particular cell type in 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.
Is there a way to do this in SOPA at all please?
Best wishes,
Emily
The text was updated successfully, but these errors were encountered: