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

bin2cell segmentation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please? #31

Open
Pancreas-Pratik opened this issue Nov 29, 2024 · 3 comments

Comments

@Pancreas-Pratik
Copy link

Pancreas-Pratik commented Nov 29, 2024

Hi, I tried to convert bin2cell's AnnData to a SpatialData object using this tutorial, but I found that the 2um bins are missing after conversion. The segmentation masks also do not convert over well.

This is kind-of related to the visualization question I had here (#24 (comment)), but a perfect conversion of bin2cell segementation AnnData to SpatialData (without loss of the 2um bin coordinate information) would allow 10X VisiumHD to generate images very close to these 10X Xenium images at the bottom of the SpatialData - 10X Xenium tutorial.

So, with bin2cell segments + hi-res images + 2um transcript bins.

SpatialData already supports plotting of 2um VisiumHD bins (VisiumHD SpatialData tutorial). I guess, just the bin2cell segments would have to be transferred over, and 2um bins would have to somehow remain in the bin2cell AnnData object.

Could this be a future feature, please?

@Pancreas-Pratik Pancreas-Pratik changed the title bin2cell segementation AnnData with VisiumHD 2um bins conversion to SpatialData, please? bin2cell segementation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please? Nov 29, 2024
@Pancreas-Pratik Pancreas-Pratik changed the title bin2cell segementation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please? bin2cell segmentation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please? Nov 29, 2024
@ktpolanski
Copy link
Contributor

ktpolanski commented Nov 29, 2024

If you're converting the cell output of b2c, then yes, that doesn't have 2um bins in it anymore. The 2um bin object has 2um bins in it. Convert that one?

@Pancreas-Pratik
Copy link
Author

Pancreas-Pratik commented Dec 4, 2024

@ktpolanski thank you for your fast responsiveness.

The 2um bin object has 2um bins in it. Convert that one?
I am wondering what you mean by the 2um bin object.

  • I think I can convert the "upstream" AnnData from bin2cell immediately after b2c.read_visium(), but this would lack the cell segmentations from b2c, but I am guessing that this would still have the 2um bin?:

    adata = b2c.read_visium(path, 
                            source_image_path = source_image_path, 
                            spaceranger_image_path = spaceranger_image_path
                           )
    

    I think I do understand what you may mean, that I can convert this initial 2um bin AnnData object to a SpatialData, and then also the "downstream" b2c segmentation AnnData to another separate SpatialData. and then merge the info someway. This does sound doable.

  • Another issue I had though was after converting the downstream b2c segmented AnnData to SpatialData using the tutorial I linked in the original post here. When seeing an image generated through SpatialData, the image appeared as though a very large majority of segments had been lost through the conversion and for what segments had remained, these remaining segments looked misaligned.

I will try your suggestion and try to create a reproducible example of the the second bullet point, hopefully soon.

@ktpolanski
Copy link
Contributor

ktpolanski commented Dec 5, 2024

The entire demo notebook takes that freshly loaded 2um bin object and does things to it. Use the form you'd use as input for b2c.bin_to_cell() to get the cell level object for most complete results. The bin level segmentation assignments will be present in .obs.

Looking at from_legacy_anndata() source code, it transfers over the basic Spaceranger spatial coordinates, scale factors, and hires/lowres images. It does not expect, nor allow the user to account for, any alternate images, scale factors, or spatial coordinates. The morphology image bin2cell generates, and subsequently segments, has all three of those be different. I'm not sure exactly what you're trying to convey, but if I'm reading you right you tried to shoehorn in the segmented StarDist mask into a converted bin2cell cell-level adata, 6000 pixel "hires" image and all, and it unsurprisingly did not work.

A pragmatic way to get the from_legacy_anndata() conversion across would be to delete the Spaceranger coordinates/images/scalefactors stored in the object, and relocate the custom bin2cell ones into appropriate slots pretending to be a "hires" so it gets picked up and converted. However, I'm not sure how this would interact with trying to force the segmentation mask in, as that's technically shaped like the "hires" image rather than the full resolution one. One way I can see would be to multiply the spatial coordinates (as well as the spot diameter from the size factors) by the scale factor, and populating a fake scale factor of 1. Maybe the tool's developers would have more elegant ideas though.

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