Closed ixxmu closed 2 years ago
10x visium空间转录组2019年底开始在国内开展商业服务,迄今已有近3年的时间了。据我所知,第一批吃螃蟹的人大多没有收获很多新技术的红利,因为早期可以借鉴的文章寥寥无几,分析工具也乏善可陈。大部分人是把空转数据作为单细胞分析结果的补充与辅助证据,也有少数人尝试把空转数据作为主体开展分析,但是很难把文章发到顶级期刊。去年以来,空转的文章和生信工具逐渐丰富起来,FFPE空转、高分辨率空转、大检测面积空转等新产品已经或即将面世,空转价格也下降了不少。空间转录组数据挖掘的黄金时期已经拉开帷幕,我将陆续写一些空转分析和文献解读的推文,不足之处请大家批评指正,欢迎大家扫文末二维码交流探讨。
Louvain聚类算法没有考虑空间位置信息,聚类结果的精确性略显不足;
基于锚点的单细胞+空转数据整合去卷积分析,经常会忽略一些细胞亚型的存在;
Markvariogram和moransi找到的空间变异基因(SVGs),没有提供工具把它们按空间区域或共表达模式分组,需要人工逐个检查SVGs的特异性表达区域。
数据预处理
创建空转分析对象
library(Seurat)
library(tidyverse)
library(patchwork)
rm(list = ls())
setwd("~/project2022/2022weixin/空转分析工具篇1_Seurat")
dir.create("QC")
dir.create("Data")
dir.create("Cluster")
dir.create("SVG")
dir.create("Deconvolution")
### 读取数据
brain <- Load10X_Spatial(data.dir = "InputData/mouse_brain_sagittal_a1/", # 存放cellranger结果的目录
filename = "filtered_feature_bc_matrix.h5", # h5格式的表达矩阵名称
assay = "Spatial", # seurat对象中存放表达矩阵的assay名称
slice = "slice1" # seurat对象中设置的空转样本ID,多样本合并分析时有用
)
### 数据质控
# 计算SPOT的线粒体基因比例
brain[["percent.mt"]] <- PercentageFeatureSet(brain, pattern = "^mt-")
# 计算SPOT的核糖体基因比例
brain[["percent.rb"]] <- PercentageFeatureSet(brain, pattern = "^Rp[ls]")
## 质控前指标展示
# 分子数
p1 <- VlnPlot(brain, features = "nCount_Spatial") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "nCount_Spatial") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/nCount_Spatial_before.pdf", p, width = 10, height = 6)
# 基因数
p1 <- VlnPlot(brain, features = "nFeature_Spatial") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "nFeature_Spatial") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/nFeature_Spatial_before.pdf", p, width = 10, height = 6)
# 线粒体
p1 <- VlnPlot(brain, features = "percent.mt") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "percent.mt") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/percent_mt_before.pdf", p, width = 10, height = 6)
# 核糖体
p1 <- VlnPlot(brain, features = "percent.rb") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "percent.rb") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/percent_rb_before.pdf", p, width = 10, height = 6)
## 质控
minCount = 1500
minFeature = 500
maxMT = 25
brain <- subset(brain, nCount_Spatial>minCount&nFeature_Spatial>minFeature&percent.mt<maxMT)
## 质控后指标展示
# 分子数
p1 <- VlnPlot(brain, features = "nCount_Spatial") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "nCount_Spatial") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/nCount_Spatial_after.pdf", p, width = 10, height = 6)
# 基因数
p1 <- VlnPlot(brain, features = "nFeature_Spatial") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "nFeature_Spatial") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/nFeature_Spatial_after.pdf", p, width = 10, height = 6)
# 线粒体
p1 <- VlnPlot(brain, features = "percent.mt") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "percent.mt") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/percent_mt_after.pdf", p, width = 10, height = 6)
# 核糖体
p1 <- VlnPlot(brain, features = "percent.rb") + NoLegend() + theme(axis.text.x = element_blank())
p2 <- SpatialFeaturePlot(brain, features = "percent.rb") + theme(legend.position = "right")
p <- p1|p2
ggsave("QC/percent_rb_after.pdf", p, width = 10, height = 6)
brain <- SCTransform(brain, assay = "Spatial") # 注意assay要指定为Spatial
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)
p <- p1 + p2
ggsave("Cluster/cluster_louvain.pdf", p, width = 15, height = 7)
p <- SpatialDimPlot(brain, facet.highlight = TRUE, ncol = 5,
cells.highlight = CellsByIdentities(brain))
ggsave("Cluster/cluster_louvain_facet.pdf", p, width = 15, height = 9)
markers <- c('Gja1', 'Flt1', 'Slc17a7', 'Gad2', 'C1qa', 'Bmp4', 'Aspa', 'Pdgfra')
p <- SpatialFeaturePlot(brain, features = markers, ncol = 4)
ggsave("Cluster/cluster_celltype_marker.pdf", p, width = 15, height = 9)
# 调整图形中spot尺寸和透明度
p1 <- SpatialFeaturePlot(brain, features = 'Slc17a7', pt.size.factor = 1)
p2 <- SpatialFeaturePlot(brain, features = 'Slc17a7', alpha = c(0.1, 1))
p <- p1 + p2
ggsave("Cluster/gene_expression_demo.pdf", p, width = 10, height = 6)
从细胞类型marker基因可以看出,兴奋神经元与抑制神经元各自存在不同的区域,星形胶质细胞、内皮细胞、小胶质细胞和OPC则在整个组织内基本均匀分布。
识别空间变异基因
差异分析法
## 差异分析法
de_markers <- FindMarkers(brain, ident.1 = 3, ident.2 = 0)
de_markers <- de_markers[order(de_markers$avg_log2FC),]
top_markers <- c(rownames(head(de_markers,3)), rownames(tail(de_markers,3)))
p <- SpatialFeaturePlot(object = brain, features =top_markers, alpha = c(0.1, 1), ncol = 3)
ggsave("SVG/cluster_top_marker.pdf", p, width = 12, height = 8)
## 标记变异函数法(运行时间较长,请耐心等待)
brain <- FindSpatiallyVariableFeatures(brain, assay = "SCT",
features = VariableFeatures(brain),
selection.method = "markvariogram")
## 莫兰指数法
brain <- FindSpatiallyVariableFeatures(brain, assay = "SCT",
features = VariableFeatures(brain),
selection.method = "moransi")
## SVGs展示
top.features <- head(SpatiallyVariableFeatures(brain, selection.method = "markvariogram"), 6)
p <- SpatialFeaturePlot(brain, features = top.features, ncol = 3, alpha = c(0.1, 1))
ggsave("SVG/markvariogram_top_marker.pdf", p, width = 12, height = 8)
top.features <- head(SpatiallyVariableFeatures(brain, selection.method = "moransi"), 6)
p <- SpatialFeaturePlot(brain, features = top.features, ncol = 3, alpha = c(0.1, 1))
ggsave("SVG/moransi_top_marker.pdf", p, width = 12, height = 8)
SPOTs去卷积分析
# 单细胞数据
allen_reference <- readRDS("InputData/allen_cortex.rds")
allen_reference <- SCTransform(allen_reference, ncells = 3000, verbose = FALSE) %>%
RunPCA(verbose = FALSE) %>% RunUMAP(dims = 1:30)
p <- DimPlot(allen_reference, group.by = "subclass", label = TRUE)
ggsave("Deconvolution/allen_reference_celltype.pdf", p, width = 8, height = 6)
# 锚点转换
anchors <- FindTransferAnchors(reference = allen_reference, query = brain,
normalization.method = "SCT")
predictions.assay <- TransferData(anchorset = anchors,
refdata = allen_reference$subclass,
prediction.assay = TRUE,
weight.reduction = brain[["pca"]],
dims = 1:30)
brain[["predictions"]] <- predictions.assay
# 结果展示
DefaultAssay(brain) <- "predictions"
cts <- c("L2/3 IT", "L4", "L5 PT", "L5 IT", "L6 CT", "L6b", "Oligo", "Astro", "Macrophage")
p <- SpatialFeaturePlot(brain, features = cts,
pt.size.factor = 1.6, ncol = 3, crop = TRUE)
ggsave("Deconvolution/celltype_prediction.pdf", p, width = 12, height = 12)
预测的细胞亚型分布
https://mp.weixin.qq.com/s/A7-hfLyYV6fZIB42ovujpg