edward130603 / BayesSpace

Bayesian model for clustering and enhancing the resolution of spatial gene expression experiments.
http://edward130603.github.io/BayesSpace
Other
96 stars 20 forks source link

Subsetting cells based on expression-level conditions #98

Closed jessielam415 closed 1 year ago

jessielam415 commented 1 year ago

Hello! Thank you for creating this amazing package. I was wondering whether BayesSpace provides a way to subset cells in enhanced SCE based on expression-level conditions of multiple genes/features. In seurat, this can be done using their subset function. Eg. subset(x = pbmc, subset = MS4A1 > 3 & PC1 > 5) If this cannot be done using BayesSpace, would you have an idea on how I would be able to create a seurat object from enhanced SCE such that I can use the subset function in seurat? I tried using the following code below from #29 , but am encountering the error "Error: No cells found" when I use the subset function on the created Seurat object.

  seurat <- Seurat::CreateSeuratObject(counts=logcounts(sce),
                                       assay='Spatial',
                                       meta.data=as.data.frame(colData(sce)))
  seurat <- Seurat::SetIdent(seurat, value = "spatial.cluster")

Thank you!

edward130603 commented 1 year ago

Try this:

MS4A1 = logcounts(sce)["MS4A1",] #if this doesn't work, check the rownames of your data
PC1 = logcounts(sce)["PC1",]
sce.subsetted = sce[, MS4A1 > 3 & PC1 > 5]
jessielam415 commented 1 year ago

It works! Thank you so much! Would you know if there is a simple way to visualize the location of these subsetted spots using a plot?

edward130603 commented 1 year ago

BayesSpace has its own plotting functions in clusterPlot and featurePlot. It will need your colData to have the columns row, col, imagerow, and imagecol which are in the tissue_positions_list.csv file from SpaceRanger output. These are the grid and image coordinates of each spot. You may also need to add in some metadata using the spatialPreprocess function with skip.PCA = TRUE and log.normalize = FALSE if you just need the metadata and not the preprocessing.

Otherwise, Seurat or SpatialExperiment have alternative ways to make spatial plots.

jessielam415 commented 1 year ago

Thank you!