You can install the most recent version of bayesVG
using:
remotes::install_github("jr-leary7/bayesVG")
library(Seurat)
library(bayesVG)
First, we load the 10X Genomics pbmc3k dataset, which is composed of 2,700 peripheral blood mononuclear cells from a single healthy donor.
data("seu_pbmc")
Now we’re able to model gene expression, summarize the posterior
distribution of variance for each gene, and classify the top 3000
most-variable genes as HVGs. The findVariableFeaturesBayes()
function
can take as input either a Seurat
or a SingleCellExperiment
object.
seu_pbmc <- findVariableFeaturesBayes(seu_pbmc,
n.cells.subsample = 500L,
algorithm = "meanfield",
save.model = TRUE) %>%
classifyHVGs(n.HVG = 3000L)
We can extract the summary table (which is sorted by default) and classify the top 3,000 genes as HVGs like so. These genes can then be used as the basis for downstream analyses such as PCA, clustering, UMAP visualization, etc.
summary_hvg <- getBayesianGeneStats(seu_pbmc)
top3k_hvgs <- summary_hvg$gene[1:3000]
First, we load the 10X Genomics anterior mouse brain dataset.
data("seu_brain")
Before running bayesVG
for SVG detection it’s necessary to normalize
the expression data and identify a set of naive HVGs.
seu_brain <- NormalizeData(seu_brain, verbose = FALSE) %>%
FindVariableFeatures(nfeatures = 3000L, verbose = FALSE)
Now we can model gene expression with an approximate multivariate
hierarchical Gaussian process (GP), summarize the spatial component of
variance for each gene, and classify the top 1000 most spatially
variable genes as SVGs. The findSpatiallyVariableFeaturesBayes()
function can take as input either a Seurat
or a SpatialExperiment
object.
seu_brain <- findSpatiallyVariableFeaturesBayes(seu_brain,
naive.hvgs = VariableFeatures(seu_brain),
kernel = "matern",
kernel.smoothness = 1.5,
algorithm = "meanfield",
n.cores = 4L,
save.model = TRUE) %>%
classifySVGs(n.SVG = 1000L)
We can extract the summary table (which, like the HVG summary table is sorted by default) and classify the top 1,000 genes as SVGs like so. These genes can then be used as the basis for downstream analyses such as PCA, clustering, UMAP visualization, etc.
summary_svg <- getBayesianGeneStats(seu_brain)
top1k_svgs <- summary_svg$gene[1:1000]
We can cluster the SVG set (using a Bayesian Gaussian mixture model) into spatial modules as shown below. The clustering function returns a PCA embedding of the SVGs, a table of the soft cluster assignment probabilities, and the log-likelihood and Bayesian information criterion (BIC) of the clustering.
svg_clusters <- clusterSVGsBayes(seu_brain,
svgs = top1k_svgs,
n.clust = 5L)
Lastly, we can score the SVG clusters using UCell
under the hood.
These scores can then be visualized using e.g., violin plots or UMAPs.
seu_brain <- scoreSpatialModules(seu_brain, svg.clusters = svg_clusters)
This package is developed & maintained by Jack R. Leary. Feel free to reach out by opening an issue or by email (j.leary@ufl.edu) if more detailed assistance is needed.