pachterlab / voyager

From geospatial to spatial -omics
https://pachterlab.github.io/voyager/
Artistic License 2.0
79 stars 9 forks source link

Loading Pre-Annotated Regions for Visium Analysis #41

Open abadgerw opened 3 days ago

abadgerw commented 3 days ago

I have pre-annotated regions in QuPath and exported them as geoJSON files. Can these be loaded directly or converted in some way so that I may perform spatially-aware DE of my Visium data?

lambdamoses commented 2 days ago

Yes, I also do that. You can use sf::st_read() to read GeoJSON file as a sf data frame, make sure to set crs = NA; CRS is the different ways to project the globe onto a 2D map, which is irrelevant to histological space. The catch though is if the QuPath annotations have the same unit as the Visium coordinates. If you did the annotations with the full resolution image and the Visium coordinates are also in full res pixels, then they should match. If you have terra >= 1.17.83, then the image will appear flipped compared to QuPath so y would increase going up just as in the geometries so the geometries should match the images as well. Here's some pseudocode, say you saved your annotations in annotations.geojson:

library(sf)
g <- st_read("annotations.geojson", crs = NA)
annotGeometry(sfe, "annotations") <- g # suppose you have one sample

If you have multiple samples in the SFE object, you should add a column named "sample_id" specifying which geometry belongs to which sample.

abadgerw commented 1 day ago

Thanks, @lambdamoses this is very helpful! I will give it a try. Once I have created an SFE object that has the geojson read annotations in annotGeometries, can the object be converted to a Seurat object without losing this information or can the geojson read by st_read be directly loaded into a Seurat object or read by the CreateSegmentation function?

lambdamoses commented 1 day ago

Right now while we have a function to convert Seurat to SFE, we don't have a function to convert SFE to Seurat yet. For now, because a SFE object is a SingleCellExperiment object, you can use existing packages that convert SCE to Seurat and deal with the spatial part separately. If you need to do DE, you can use scater which uses SCE without converting to Seurat.