使用ggpubr给单细胞数据添加P value和显著性水平

目的:比较单细胞亚群的得分差异性水平

单细胞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值

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值