参考文献:
SpotSweeper: spatially aware quality control for spatial transcriptomics
使用手册:
Getting started with 'SpotSweeper' • SpotSweeper
简介
SpotSweeper是一个为空间感知质量控制(QC)方法开发的软件包,用于检测、可视化和去除基于点的空间转录组学数据中的局部异常值和区域工件。

安装
if (!require("devtools")) install.packages("devtools")
remotes::install_github("MicTott/SpotSweeper")
# BiocManager::install("SpotSweeper")
spot水平的局部离群点检测
加载数据
library(SpotSweeper)
spe <- STexampleData::Visium_humanDLPFC() ## 使用来自STexampleData包的Visium_humanDLPFC数据集,SpatialExperiment对象
colnames(colData(spe)) ## 局部离群值将保存在SpatialExperiment对象的colData中
## [1] "barcode_id" "sample_id" "in_tissue" "array_row" "array_col"
## [6] "ground_truth" "reference" "cell_count"
# drop out-of-tissue spots
spe <- spe[, spe$in_tissue == 1]
使用 scuttle 计算QC指标
修改gene name;添加线粒体基因比例;
# change from gene id to gene names
rownames(spe) <- rowData(spe)$gene_name
# identifying the mitochondrial transcripts
is.mito <- rownames(spe)[grepl("^MT-", rownames(spe))]
# calculating QC metrics for each spot using scuttle
spe <- scuttle::addPerCellQCMetrics(spe, subsets = list(Mito = is.mito))
colnames(colData(spe))
## [1] "barcode_id" "sample_id" "in_tissue"
## [4] "array_row" "array_col" "ground_truth"
## [7] "reference" "cell_count" "sum"
## [10] "detected" "subsets_Mito_sum" "subsets_Mito_detected"
## [13] "subsets_Mito_percent" "total"
鉴定局部离群值
使用localOutliers函数根据唯一检测到的基因、总文库大小和线粒体总读取量的百分比来检测局部异常值。(正态分布)使用计数、检测到的基因的对数变换,(原始)线粒体百分比。
# library size
spe <- localOutliers(spe,
metric = "sum",
direction = "lower",
log = TRUE
)
# unique genes
spe <- localOutliers(spe,
metric = "detected",
direction = "lower",
log = TRUE
)
# mitochondrial percent
spe <- localOutliers(spe,
metric = "subsets_Mito_percent",
direction = "higher",
log = FALSE
)
localOutlier 函数自动输出结果到 colData 中,以 X_outliers 命名,其中X是输入colData 的名称。可以在SpatialExperiment对象的colData中将所有离群值合并到一个名为local_outliers的列中。
# combine all outliers into "local_outliers" column
spe$local_outliers <- as.logical(spe$sum_outliers) |
as.logical(spe$detected_outliers) |
as.logical(spe$subsets_Mito_percent_outliers)
可视化离群值
使用plotQCmetrics函数可视化局部离群值。此函数创建指定度量的散点图,并使用escheR包突出显示红色的局部异常值。可视化库大小的局部异常值、独特的基因、线粒体百分比,和所有的局部异常值。还可使用ggpubr::arrange在网格中排列这些图。
library(escheR)
# all local outliers
plotQCmetrics(spe, metric = "sum_log", outliers = "local_outliers", point_size = 1.1,
stroke = 0.75) +
ggtitle("All Local Outliers")

删除技术误差
加载数据
# load in DLPFC sample with hangnail artifact
data(DLPFC_artifact)
spe <- DLPFC_artifact
# inspect colData before artifact detection
colnames(colData(spe))
可视化技术误差
技术工件通常可以通过标准QC度量来可视化,包括文库大小、独特基因或线粒体百分比。我们可以首先使用plotQCmetrics函数可视化技术工件。在这个样本中,我们可以清楚地看到线粒体比例图中组织切片右侧的挂钉伪影。
plotQCmetrics(spe,
metric = "expr_chrM_ratio",
outliers = NULL, point_size = 1.1
) +
ggtitle("Mitochondrial Percent")

鉴定
可以使用finartifacts函数来识别空间转录组学数据中的工件。该函数基于指定的QC度量(mito_percent)在许多邻域大小(n_order=5)上的局部方差的第一个主要成分来标识技术工件。目前,kmeans 聚类用于聚类技术工件与高质量的 Visium 点。与 localOutliers 类似,findarfacts 函数随后将结果输出到 colData。
# find artifacts using SpotSweeper
spe <- findArtifacts(spe,
mito_percent = "expr_chrM_ratio",
mito_sum = "expr_chrM",
n_order = 5,
name = "artifact"
)
# check that "artifact" is now in colData
colnames(colData(spe))
可视化
plotQCmetrics(spe,
metric = "expr_chrM_ratio",
outliers = "artifact", point_size = 1.1
) +
ggtitle("Hangnail artifact")
