knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

iSpatail Tutorial


Load package

Install iSpatial package from Github. iSpatial is based on Seurat, you need install Seurat first .

# install iSpatial package
# devtools::install_github("Czh3/iSpatial")

# load
library(iSpatial)

library(Seurat)
library(ggplot2)

Load data

Load scRNA-seq and merFISH of Mouse Nucleus Accumbens. The data are down-sampled from Renchao et al.

# scRNA-seq data
data(NA_scRNA)

# merFISH data
data(NA_merFISH)

Normalize data

The data need be log normalized.

# scRNA-seq data
NA_scRNA = NormalizeData(NA_scRNA, verbose = FALSE)

# merFISH data
NA_merFISH = NormalizeData(NA_merFISH, verbose = FALSE)

infer transcriptome-wide spatial expression

# infer spatial transcriptome
NA_merFISH_iSpatial = iSpatial::infer(NA_merFISH, NA_scRNA)

Example of spatial expression

Gene "Acbd7" is not in the merFISH targeted genes

"Acbd7" %in% rownames(NA_merFISH)

After inferring, we can get the spatial expression of Acbd7

SpatialFeaturePlot(NA_merFISH_iSpatial, features = "Acbd7", stroke=0.1, slot="data") +
  theme(legend.position = "right") +
  scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red"))

Enhance the spatial expression of Tac2

#raw expression
p1 = SpatialFeaturePlot(NA_merFISH, features = "Tac2", stroke=0.1, slot="data") +
  theme(legend.position = "right") + ggtitle("before") +
  scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red"))

# inferred
p2 = SpatialFeaturePlot(NA_merFISH_iSpatial, features = "Tac2", stroke=0.1, slot="data") +
  theme(legend.position = "right") + ggtitle("after") +
  scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red"))

p1 + p2

Find spatial variable genes

# run umap of scRNAseq data
NA_scRNA = FindVariableFeatures(NA_scRNA, verbose = FALSE)
NA_scRNA = ScaleData(NA_scRNA, verbose = FALSE)
NA_scRNA = RunPCA(NA_scRNA, verbose = FALSE)
NA_scRNA = RunUMAP(NA_scRNA, dims = 1:30, verbose = FALSE)

# Find spatial variable genes
SVGs_infer = iSpatial::spatial_variable_genes(spRNA.obj = NA_merFISH_iSpatial,
                                              spRNA.assay = "enhanced",
                                              scRNA.obj = NA_scRNA,
                                              scRNA.assay = "RNA",
                                              n.core = 10)

SVGs_infer_sig = SVGs_infer[SVGs_infer$p.value < .01 & SVGs_infer$spRNA.p.value < .01, ]

ggplot2::ggplot(SVGs_infer1, aes(-log10(scRNA.p.value), -log10(spRNA.p.value),
                                    gene = gene, color = -log10(p.value))) +
  geom_point()+
  theme_classic()

Group the SVGs into clusters based on spatial expression pattern

gene_cluster = iSpatial::cluster_spatial_expr_pattern(NA_merFISH_iSpatial, "enhanced", 
                             feature = SVGs_infer_sig$gene, 
                             n.cluster = 12,
                             ncol.plot = 4, 
                             bin = 20,
                             n.core = 10)

# genes in cluster 7
names(gene_cluster[gene_cluster==7])

# plot
SpatialFeaturePlot(NA_merFISH_iSpatial, features = "Coch", stroke=0.1, slot="data") +
  theme(legend.position = "right") + 
  scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red"))
sessionInfo()


Czh3/iSpatial documentation built on Sept. 15, 2022, 10:32 p.m.