You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?[/+]on 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?
@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?:
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.
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.
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.
Thank you. This is helpful.
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.
I figured from the bin2cell demo that because sc.pl.spatial() plots the stardist/b2c cell segments and H&E from within a single AnnData object input (bdata or cdata), these AnnData objects (I only tried cdata) could be converted to SpatialData using from_legacy_anndata() to using SpatialData to visualize these outputs (with 2um bin info) instead of sc.pl.spatial(). It was probably a quick and dirty attempt to "just see if it works".
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.
Thank you. This is helpful information. While beginning to make an issue/feature request in the spatialdata. I went to find other pertinent info I remembered seeing here. I found #4 (comment), which actually helps me think of a plan on how to do this. After reading your explanation there again, I realized that there is a point in the bin2cell pipeline (immediately prior to b2c.bin_to_cell()) when all of the needed information (2um bins + segments) is available in one aligned place and space. Using this point to convert the bin2cell AnnData to SpatialData, could be a reasonable starting point.
I also just thought based on the solution you provided here (#24 (comment)) for my visualization question. Maybe converting to SpatialData is not all that necessary, and it might even be easier, for now, to just accomplish what I need to do from your solution there.
After reading your explanation there again, I realized that there is a point in the bin2cell pipeline (immediately prior to b2c.bin_to_cell()) when all of the needed information (2um bins + segments) is available in one aligned place and space. Using this point to convert the bin2cell AnnData to SpatialData, could be a reasonable starting point.
This is literally what I wrote you in my answer, yes.
I am not versed in SpatialData. How did you insert the segmentation mask into the object?
This is literally what I wrote you in my answer, yes.
Ahh. You're right. I apologize. I guess I needed a little bit more context to form the connection in my mind. I just learned of bin2cell about 3-4 weeks ago from the 10X webinar.
I am not versed in SpatialData. How did you insert the segmentation mask into the object?
I am definitely not well-versed either!
I have not yet tried to explicitly specify the segmentation mask in any way. From the tutorial I linked above of from_legacy_anndata(adata), I more or less tried the spatialdata defaults with the bin2cell cdata-stage AnnData, so:
Activity
[-]bin2cell segementation AnnData with VisiumHD 2um bins conversion to SpatialData, please?[/-][+]bin2cell segementation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please?[/+][-]bin2cell segementation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please?[/-][+]bin2cell segmentation (with VisiumHD 2um bins information) AnnData conversion to SpatialData, please?[/+]ktpolanski commentedon 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 commentedon Dec 4, 2024
@ktpolanski thank you for your fast responsiveness.
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?: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 commentedon 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.Pancreas-Pratik commentedon Dec 5, 2024
Thank you. This is helpful.
I figured from the bin2cell demo that because
sc.pl.spatial()plots the stardist/b2c cell segments and H&E from within a single AnnData object input (bdataorcdata), these AnnData objects (I only triedcdata) could be converted to SpatialData usingfrom_legacy_anndata()to using SpatialData to visualize these outputs (with 2um bin info) instead ofsc.pl.spatial(). It was probably a quick and dirty attempt to "just see if it works".Thank you. This is helpful information. While beginning to make an issue/feature request in the spatialdata. I went to find other pertinent info I remembered seeing here. I found #4 (comment), which actually helps me think of a plan on how to do this. After reading your explanation there again, I realized that there is a point in the bin2cell pipeline (immediately prior to
b2c.bin_to_cell()) when all of the needed information (2um bins + segments) is available in one aligned place and space. Using this point to convert the bin2cell AnnData to SpatialData, could be a reasonable starting point.I also just thought based on the solution you provided here (#24 (comment)) for my visualization question. Maybe converting to SpatialData is not all that necessary, and it might even be easier, for now, to just accomplish what I need to do from your solution there.
I will re-visit all of this hopefully soon.
ktpolanski commentedon Dec 5, 2024
This is literally what I wrote you in my answer, yes.
I am not versed in SpatialData. How did you insert the segmentation mask into the object?
Pancreas-Pratik commentedon Dec 5, 2024
Ahh. You're right. I apologize. I guess I needed a little bit more context to form the connection in my mind. I just learned of bin2cell about 3-4 weeks ago from the 10X webinar.
I am definitely not well-versed either!
I have not yet tried to explicitly specify the segmentation mask in any way. From the tutorial I linked above of
from_legacy_anndata(adata), I more or less tried the spatialdata defaults with the bin2cellcdata-stage AnnData, so:thank you for your blazing fast response
ktpolanski commentedon Dec 5, 2024
In that case, I have no idea what you mean by the "segments" that got lost or misaligned earlier.