irGSEA基因集評分-繪圖-代碼

irGSEA:基于秩次的單細(xì)胞基因集富集分析整合框架(修訂版) - 簡書 (jianshu.com)
GitHub - chuiqin/irGSEA: The integration of single cell rank-based gene set enrichment analysis

計算時間,這個很關(guān)鍵

image.png

數(shù)據(jù)評分

library(Seurat)
obj<- readRDS(file = 'after_annotation.rds')
library(irGSEA)
library(RcppML)

obj<-JoinLayers(obj)
Idents(obj)<-'customclassif'
head(Idents(obj))

obj <- CreateSeuratObject(counts = CreateAssay5Object(GetAssayData(obj, assay = "RNA", slot = "counts")),
                                    meta.data = obj[[]])
obj <- NormalizeData(obj)
obj <- irGSEA.score(object = obj,assay = "RNA", 
                              slot = "data", seeds = 123, ncores = 1,
                              min.cells = 3, min.feature = 0,
                              custom = F, geneset = NULL, msigdb = T, 
                              species = "Mus musculus", category = "C2",  
                              subcategory = "CP:KEGG", geneid = "symbol",
                              method = c("AUCell","UCell","singscore","AddModuleScore"),
                              aucell.MaxRank = NULL, ucell.MaxRank = NULL, 
                              kcdf = 'Gaussian')
VlnPlot(obj, features = "nCount_AddModuleScore", split.by = "group",
        group.by = 'customclassif')

obj$celltype.stim <- paste(obj$customclassif, obj$group, sep = "_")
Idents(obj) <- "celltype.stim"


# 計算差異基因集,并進(jìn)行RRA
# 如果報錯还蹲,考慮加句代碼options(future.globals.maxSize = 100000 * 1024^5)
result.dge <- irGSEA.integrate(object = obj,
                               group.by = "celltype.stim",
                               method = c("AUCell","UCell","singscore","AddModuleScore"))


result.dge <- irGSEA.integrate(object = obj,
                               group.by = NULL,
                               metadata = obj$celltype.stim,col.name = "ident",
                               method = c("AUCell","UCell","singscore","AddModuleScore"))

可視化

??irGSEA.heatmap()
irGSEA.heatmap.plot <- irGSEA.heatmap(object = result.dge,
                                      method = "RRA",
                                      top = 50,
                                      show.geneset = NULL,
                                      heatmap.width = 30,
                                      heatmap.heigh = 25)

irGSEA.heatmap.plot
ggsave(plot = irGSEA.heatmap.plot,filename = 'irGSEA.heatmap.plot.pdf',width = 15,height = 12)
# 查看RRA識別的在多種打分方法中都普遍認(rèn)可的差異基因集
geneset.show <- result.dge$RRA %>% 
  dplyr::filter(pvalue <= 0.05) %>% 
  dplyr::pull(Name) %>% unique(.)
irGSEA.heatmap.plot1 <- irGSEA.heatmap(object = result.dge, 
                                       method = "RRA",
                                       show.geneset = geneset.show)
irGSEA.heatmap.plot1

irGSEA.bubble.plot <- irGSEA.bubble(object = result.dge,
                                    method = "RRA",
                                    show.geneset = NULL)
irGSEA.bubble.plot
ggsave(plot = irGSEA.bubble.plot,filename = 'irGSEA.bubble.plot.pdf',width = 15,height = 12)
irGSEA.upset.plot <- irGSEA.upset(object = result.dge, upset.width = 30,
                                  upset.height = 15,set.size = 1,
                                  method = "RRA")
irGSEA.upset.plot
ggsave(plot = irGSEA.upset.plot,filename = 'irGSEA.upset.plot.pdf',width = 15,height = 12)
irGSEA.barplot.plot <- irGSEA.barplot(object = result.dge,
                                      method = c("AUCell","UCell","singscore",
                                                 "AddModuleScore","RRA"))
irGSEA.barplot.plot
ggsave(plot = irGSEA.barplot.plot,filename = 'irGSEA.barplot.plot.pdf',width = 15,height = 12)
aaa<-as.data.frame(geneset.show)

KEGG-ECM-RECEPTOR-INTERACTION

halfvlnplot <- irGSEA.halfvlnplot(object = obj,
                                  method = "AddModuleScore",
                                  show.geneset = "KEGG-ECM-RECEPTOR-INTERACTION")
halfvlnplot

vlnplot <- irGSEA.vlnplot(object = obj,
                          method = c("AUCell", "UCell", "singscore", "AddModuleScore"),
                          show.geneset = "KEGG-ECM-RECEPTOR-INTERACTION")
vlnplot
ridgeplot <- irGSEA.ridgeplot(object = obj,
                              method = "UCell",
                              show.geneset = "KEGG-ECM-RECEPTOR-INTERACTION")
ridgeplot
#> Picking joint bandwidth of 0.00533
densityheatmap <- irGSEA.densityheatmap(object = obj,
                                        method = "AUCell",
                                        show.geneset = "KEGG-ECM-RECEPTOR-INTERACTION")
densityheatmap

hub.result <- irGSEA.hub(object = obj, assay = "RNA", slot = "data",
                         method = c("AUCell","UCell","singscore", "AddModuleScore"
                                    ),
                         show.geneset = c("KEGG-ECM-RECEPTOR-INTERACTION",
                                          "KEGG-GLYCEROPHOSPHOLIPID-METABOLISM"),
                         ncores = 4, type = "rank", maxRank = 2000, top = 5,
                         correlation.color = c("#0073c2","white","#efc000"),
                         method.color = NULL)
head(hub.result$hub_result)
head(hub.result$hub_plot$`KEGG-ECM-RECEPTOR-INTERACTION`)
head(hub.result$hub_plot$`KEGG-GLYCEROPHOSPHOLIPID-METABOLISM`)

image.png

R包的安裝


# install packages from CRAN
cran.packages <- c("aplot", "BiocManager", "circlize", "cowplot","data.table", 
                   "devtools", "doParallel", "doRNG", "dplyr", "ggfun", "gghalves", 
                   "ggplot2", "ggplotify", "ggridges", "ggsci", "irlba",
                   "magrittr", "Matrix", "msigdbr", "pagoda2", "plyr", "pointr", 
                   "purrr", "RcppML", "readr", "reshape2", "reticulate", 
                   "rlang", "RMTstat", "RobustRankAggreg", "roxygen2", 
                   "Seurat", "SeuratObject", "stringr", "tibble", "tidyr", 
                   "tidyselect", "tidytree", "VAM")

for (i in cran.packages) {
  if (!requireNamespace(i, quietly = TRUE)) {
    install.packages(i, ask = F, update = F)
  }
}

# install packages from Bioconductor
bioconductor.packages <- c("AUCell", "BiocParallel", "ComplexHeatmap", 
                           "decoupleR", "fgsea", "ggtree", "GSEABase", 
                           "GSVA", "Nebulosa", "scde", "singscore",
                           "SummarizedExperiment", "UCell",
                           "viper","sparseMatrixStats")

for (i in bioconductor.packages) {
  if (!requireNamespace(i, quietly = TRUE)) {
    BiocManager::install(i, ask = F, update = F)
  }
}

# install packages from Github
if (!requireNamespace("irGSEA", quietly = TRUE)) { 
    devtools::install_github("chuiqin/irGSEA", force =T)
}

#### install packages from Github
# VISION
if (!requireNamespace("VISION", quietly = TRUE)) { 
    devtools::install_github("YosefLab/VISION", force =T)
}

# mdt need ranger
if (!requireNamespace("ranger", quietly = TRUE)) { 
  devtools::install_github("imbs-hl/ranger", force =T)
}

# gficf need RcppML (version > 0.3.7) package
if (!utils::packageVersion("RcppML") > "0.3.7") {
  message("The version of RcppML should greater than 0.3.7 and install RcppML package from Github")
  devtools::install_github("zdebruine/RcppML", force =T)
}

# please first `library(RcppML)` if you want to perform gficf
if (!requireNamespace("gficf", quietly = TRUE)) { 
    devtools::install_github("gambalab/gficf", force =T)
}

# GSVApy and ssGSEApy need SeuratDisk package
if (!requireNamespace("SeuratDisk", quietly = TRUE)) { 
    devtools::install_github("mojaveazure/seurat-disk", force =T)
}

# sargent
if (!requireNamespace("sargent", quietly = TRUE)) { 
    devtools::install_github("Sanofi-Public/PMCB-Sargent", force =T)
}

# pagoda2 need scde package
if (!requireNamespace("scde", quietly = TRUE)) { 
  devtools::install_github("hms-dbmi/scde", force =T)
}

# if error1 (functio 'sexp_as_cholmod_sparse' not provided by package 'Matrix')
# or error2 (functio 'as_cholmod_sparse' not provided by package 'Matrix') occurs
# when you perform pagoda2, please check the version of irlba and Matrix
# It's ok when I test as follow:
# R 4.2.2 irlba(v 2.3.5.1) Matrix(1.5-3)
# R 4.3.1 irlba(v 2.3.5.1) Matrix(1.6-1.1)
# R 4.3.2 irlba(v 2.3.5.1) Matrix(1.6-3)


#### create conda env
# If error (Unable to find conda binary. Is Anaconda installed) occurs, 
# please perform `reticulate::install_miniconda()`
if (! "irGSEA" %in% reticulate::conda_list()$name) {
      reticulate::conda_create("irGSEA")
}

# if python package exist
python.package <- reticulate::py_list_packages(envname = "irGSEA")$package
require.package <- c("anndata", "scanpy", "argparse", "gseapy", "decoupler")
for (i in seq_along(require.package)) {
  if (i %in% python.package) {
    reticulate::conda_install(envname = "irGSEA", packages = i, pip = T)
  }
}

部分用戶可以通過鏡像加速安裝

options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor/")
options("repos" = c(CRAN="http://mirrors.cloud.tencent.com/CRAN/"))

# install packages from CRAN
cran.packages <- c("aplot", "BiocManager", "circlize", "cowplot", "data.table",
                   "devtools", "doParallel", "doRNG", "dplyr", "ggfun", "gghalves", 
                   "ggplot2", "ggplotify", "ggridges", "ggsci", "irlba",
                   "magrittr", "Matrix", "msigdbr", "pagoda2", "plyr", "pointr", 
                   "purrr", "RcppML", "readr", "reshape2", "reticulate", 
                   "rlang", "RMTstat", "RobustRankAggreg", "roxygen2", 
                   "Seurat", "SeuratObject", "stringr", "tibble", "tidyr", 
                   "tidyselect", "tidytree", "VAM")

for (i in cran.packages) {
  if (!requireNamespace(i, quietly = TRUE)) {
    install.packages(i, ask = F, update = F)
  }
}

# install packages from Bioconductor
bioconductor.packages <- c("AUCell", "BiocParallel", "ComplexHeatmap", 
                           "decoupleR", "fgsea", "ggtree", "GSEABase", 
                           "GSVA", "Nebulosa", "scde", "singscore",
                           "SummarizedExperiment", "UCell", "viper")

for (i in bioconductor.packages) {
  if (!requireNamespace(i, quietly = TRUE)) {
    BiocManager::install(i, ask = F, update = F)
  }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末瑞驱,一起剝皮案震驚了整個濱河市陨仅,隨后出現(xiàn)的幾起案子随静,更是在濱河造成了極大的恐慌,老刑警劉巖忘分,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件爵川,死亡現(xiàn)場離奇詭異敷鸦,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)雁芙,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進(jìn)店門轧膘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人兔甘,你說我怎么就攤上這事谎碍。” “怎么了洞焙?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵蟆淀,是天一觀的道長。 經(jīng)常有香客問我澡匪,道長熔任,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任唁情,我火速辦了婚禮疑苔,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘甸鸟。我一直安慰自己惦费,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布抢韭。 她就那樣靜靜地躺著薪贫,像睡著了一般。 火紅的嫁衣襯著肌膚如雪刻恭。 梳的紋絲不亂的頭發(fā)上瞧省,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天,我揣著相機(jī)與錄音鳍贾,去河邊找鬼鞍匾。 笑死,一個胖子當(dāng)著我的面吹牛骑科,可吹牛的內(nèi)容都是我干的橡淑。 我是一名探鬼主播,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼纵散,長吁一口氣:“原來是場噩夢啊……” “哼梳码!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起伍掀,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤掰茶,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蜜笤,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體濒蒋,經(jīng)...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年把兔,在試婚紗的時候發(fā)現(xiàn)自己被綠了沪伙。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,137評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡县好,死狀恐怖围橡,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情缕贡,我是刑警寧澤翁授,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布,位于F島的核電站晾咪,受9級特大地震影響收擦,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜谍倦,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一塞赂、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧昼蛀,春花似錦宴猾、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至送淆,卻和暖如春税产,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背偷崩。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工辟拷, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人阐斜。 一個月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓衫冻,卻偏偏與公主長得像,于是被迫代替她去往敵國和親谒出。 傳聞我的和親對象是個殘疾皇子隅俘,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評論 2 345

推薦閱讀更多精彩內(nèi)容