#Installation
devtools::install_github("satijalab/seurat", ref = "spatial")
加载需要的R包
library(Seurat)
library(SeuratData)
library(ggplot2)
library(cowplot)
library(dplyr)
安装测试的数据集
InstallData("stxBrain")
brain <- LoadData("stxBrain", type = "anterior1")
计算一下所有细胞的counts分布情况,发现counts差距比较大,因此需要normalize
plot1 <- VlnPlot(brain, features = "nCount_Spatial", pt.size = 0.1) + NoLegend()
plot2 <- SpatialFeaturePlot(brain, features = "nCount_Spatial") + theme(legend.position = "right")
plot_grid(plot1, plot2)
![](https://img.haomeiwen.com/i20297934/e9640f311b71e705.png)
常用的LogNormalize会损失不同的位置本身存在的counts差距的信息,因此选用SCTransform
brain <- SCTransform(brain, assay = "Spatial", verbose = FALSE)
SpatialFeaturePlot查看基因的位置表达信息
SpatialFeaturePlot(brain, features = c("Hpca", "Ttr"))
![](https://img.haomeiwen.com/i20297934/6252b61e5349831b.png)
调整点的大小和透明度
p1 <- SpatialFeaturePlot(brain, features = "Ttr", pt.size.factor = 1)
p2 <- SpatialFeaturePlot(brain, features = "Ttr", alpha = c(0.1, 1))
plot_grid(p1, p2)
![](https://img.haomeiwen.com/i20297934/48cb837d1c584c25.png)
下面就是跟单细胞一样的流程:降维聚类
brain <- RunPCA(brain, assay = "SCT", verbose = FALSE)
brain <- FindNeighbors(brain, reduction = "pca", dims = 1:30)
brain <- FindClusters(brain, verbose = FALSE)
brain <- RunUMAP(brain, reduction = "pca", dims = 1:30)
可视化
p1 <- DimPlot(brain, reduction = "umap", label = TRUE)
p2 <- SpatialDimPlot(brain, label = TRUE, label.size = 3)
plot_grid(p1, p2)
![](https://img.haomeiwen.com/i20297934/00bf45772940fe01.png)
交互式展示
# move your mouse
SpatialDimPlot(brain, do.hover = TRUE)
![](https://img.haomeiwen.com/i20297934/9b81b8153b781781.png)
用cells.highlight展示感兴趣的细胞的位置
SpatialDimPlot(brain, cells.highlight = CellsByIdentities(object = brain, idents = c(1, 2, 5, 3, 4, 8)), facet.highlight = TRUE, ncol = 3)
![](https://img.haomeiwen.com/i20297934/fc66a6ec2e3e8718.png)
(未完待续)
原文选自:https://satijalab.org/seurat/v3.1/spatial_vignette.html
网友评论