JEFworks-Lab / SEraster

Spatial Experiments raster - a rasterization preprocessing framework for scalable spatial omics data analysis
https://jef.works/SEraster/
16 stars 4 forks source link

Hexagonal spatial bins #3

Open lambdamoses opened 9 months ago

lambdamoses commented 9 months ago

I saw your paper on bioRxiv. Just wondering, what if you use a hexagonal grid rather than a square grid? How would it affect the SVG results?

GohtaAihara commented 9 months ago

Thank you @lambdamoses for a great question/suggestion! Since we observed consistent SVG results with rotation-based permutations (rotate the x,y coordinates of the dataset prior to applying SEraster), we believe using a hexagonal grid rather than a square grid would not significantly affect the SVG results.

We would love to know if there is a case in which a hexagonal grid offers an advantage over a square grid!

If you would like to further explore, we implemented the square parameter to rasterizeMatrix(), rasterizeGeneExpression(), and rasterizeCellType() functions. The square parameter allows you to choose between square or hexagonal pixels for rasterization, and it works the same way as the square parameter in the sf::st_make_grid().

This feature was added in the following commit. https://github.com/JEFworks-Lab/SEraster/commit/96ccb8a047c1d5540d5991832bc10aaa7d491b39

We are currently working on plotRaster() function to visualize hexagonal pixels.

GohtaAihara commented 9 months ago

plotRaster() function is updated to visualize square or hexagonal pixels. To do so, we decided to store pixels' geometries as sfc_POLYGON in the colData slot of the resulting SpatialExperiment object. plotRaster() uses ggplot2::geom_sf() to plot pixels and their corresponding values based on user inputs (e.g. total rasterized gene expression, rasterized gene expression for specific gene, rasterized cell counts for specific cell-type).

This feature was added in the following commit. https://github.com/JEFworks-Lab/SEraster/commit/a69f230f630763b0fb5ba0d0940df3f41325304d

Since SEraster now stores pixels' geometries as sfc_POLYGON using sf package, it may makes sense to return the output as SpatialFeatureExperiment instead of SpatialExperiment (or switch based on an user input). We will explore this option.

lambdamoses commented 9 months ago

For SFE, we've added functionalities to deal with smFISH transcript spot geometries. I think when those are available, the spatial binning should use the transcript spots rather than the cell coordinates, because transcript spots are not uniformly distributed within cells. Also, I'm debating what to do with Visium spot and cell polygons that sit at the boundary of two spatial bins during spatial binning when transcript spots are not available. Maybe assume uniform distribution and distribute the UMI or transcript spot counts proportionally with the area of overlap.

I have long had the idea of adding general spatial binning or aggregation with any kind of geometry (including but not limited to spatial grids) to the SFE package itself. If you implement it in your package, then I'll simply suggest your package in SFE.