目的:比较单细胞亚群的得分差异性水平
单细胞Seurat自带函数AddModuleScore可以计算单细胞基因集得分,代码如下
data("pbmc_small")
cd_features <- list(c(
'CD79B',
'CD79A',
'CD19',
'CD180',
'CD200',
'CD3D',
'CD2',
'CD3E',
'CD7',
'CD8A',
'CD14',
'CD1C',
'CD68',
'CD9',
'CD247'
))
pbmc_small <- AddModuleScore(
object = pbmc_small,
features = cd_features,
ctrl = 5,
name = 'CD_Features'
)
那么我们如何比较不同细胞亚型的得分差异性呢?
可以使用 ggpubr这个R包的 stat_compare_means() 函数
stat_compare_means()
This function extends ggplot2 for adding mean comparison p-values to a ggplot, such as box blots, dot plots, bar plots and line plots.
The simplified format is as follow:
stat_compare_means(mapping = NULL, comparisons = NULL hide.ns = FALSE,
label = NULL, label.x = NULL, label.y = NULL, ...)
示例数据
library(tidyverse)
library(Seurat)
#> Attaching SeuratObject
library(SeuratObject)
library(ggsignif)
library(ggpubr)
#data(package = "Seurat")
#data(package = "SeuratObject")
data(pbmc_small)
scData <- pbmc_small
cd_features <- list(c(
'CD79B',
'CD79A',
'CD19',
'CD180',
'CD200',
'CD3D',
'CD2',
'CD3E',
'CD7',
'CD8A',
'CD14',
'CD1C',
'CD68',
'CD9',
'CD247'
))
AddModuleScore(object = scData, features = cd_features, name = "cd_features",
seed = 1, search = FALSE, assay = NULL,
nbin = 21, ctrl = 5, pool = NULL)
#> An object of class Seurat
#> 230 features across 80 samples within 1 assay
#> Active assay: RNA (230 features, 20 variable features)
#> 2 dimensional reductions calculated: pca, tsne
my_comparisons <- list( c("0", "1"), c("1", "2"), c("0", "2"))
# VlnPlot(scData, features = "PC_1", pt.size = 0) +
# NoLegend() +
# theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
# stat_compare_means()
VlnPlot(scData, features = "PC_1", pt.size = 0) +
NoLegend() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
stat_compare_means(comparisons = my_comparisons) +
ylim(-2, 15)
这样我们就得到了3个亚簇的差异性P值