knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The package can be loaded with the command:
file = system.file("extdata", "CRC3.rds", package = "SC.MEB") CRC = readRDS(file)
SC-MEB requires minimal data pre-processing, but we provide a helper function to automate it.
spatialPreprocess() log-normalizes the count matrix and performs PCA on the top n.HVGs highly variable genes, keeping the top n.PCs principal components. Additionally, the spatial sequencing platform is added as metadata in the SingleCellExperiment for downstream analyses. If you do not wish to rerun PCA, running spatialPreprocess() with the flag skip.PCA=TRUE will only add the metadata SC-MEB requires.
set.seed(114) library(scuttle) library(scran) library(scater) library(BiocSingular) CRC <- spatialPreprocess(CRC, platform="Visium")
Here, we set the basic paramters for our function
platform = "Visium" beta_grid = seq(0,4,0.2) K_set= 2:10 parallel=TRUE num_core = 3 PX = TRUE maxIter_ICM = 10 maxIter = 50
library(SingleCellExperiment) Adj_sp <- find_neighbors2(CRC, platform = "Visium") Adj_sp[1:10,1:10]
y = reducedDim(CRC, "PCA")[,1:15] fit = SC.MEB(y, Adj_sp, beta_grid = beta_grid, K_set= K_set, parallel=parallel, num_core = num_core, PX = PX, maxIter_ICM=maxIter_ICM, maxIter=maxIter) str(fit[,1])
selectKPlot(fit, K_set = K_set, criterion = "BIC")
Here we briefly explain how to choose the parameter c in the modified BIC. In general, For the ST or Visium dataset, it often ranges from 0.4 to 1 while for the MERFISH dataset with large number of cells, it often becomes larger, for example 10,20. Most importantly, SC-MEB is fast, scaling well in terms of sample size, which allow the user to tune the c based on their prior knowledge about the tissues or cells.
selectKPlot(fit, K_set = K_set, criterion = "MBIC")
We can plot the cluster assignments over the spatial locations of the spots with ClusterPlot().
out = selectK(fit, K_set = K_set, criterion = "BIC") pos = matrix(cbind(colData(CRC)[,c(4)],20000-colData(CRC)[,c(3)]), 2988, 2) ClusterPlot(out, pos, size = 3, shape = 16)
out = selectK(fit, K_set = K_set, criterion = "MBIC") pos = matrix(cbind(colData(CRC)[,c(4)],20000-colData(CRC)[,c(3)]), 2988, 2) ClusterPlot(out, pos, size = 3, shape = 16)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.