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

Hexagonal spatial bins #3

Open
lambdamoses opened this issue Feb 6, 2024 · 3 comments
Open

Hexagonal spatial bins #3

lambdamoses opened this issue Feb 6, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@lambdamoses
Copy link

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
Copy link
Collaborator

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.
96ccb8a

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

@GohtaAihara
Copy link
Collaborator

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.
a69f230

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.

@GohtaAihara GohtaAihara added the enhancement New feature or request label Feb 20, 2024
@lambdamoses
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants