fgsea做GSEA

时间:2022-07-22
本文章向大家介绍fgsea做GSEA,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
library(fgsea)

1.导入测试数据,fgesa的examplePathways,exampleRanks测试数据分别是通路的list和经过fold change排序的基因。

data(examplePathways)
data(exampleRanks)

2.运行 fgsea

The resulting table contains enrichment scores and p-values:

fgseaRes <- fgsea(pathways = examplePathways, 
                  stats = exampleRanks,
                  minSize=15,
                  maxSize=500,
                  nperm=10000)
head(fgseaRes[order(pval), ])

3.计算padj<0.01的个数

sum(fgseaRes[, padj < 0.01])

4.画特定的通路

plotEnrichment(examplePathways[["5991130_Programmed_Cell_Death"]],
               exampleRanks) + labs(title="Programmed Cell Death")

5.选择上调下调的top10的pathtway

topPathwaysUp <- fgseaRes[ES > 0][head(order(pval), n=10), pathway]
topPathwaysDown <- fgseaRes[ES < 0][head(order(pval), n=10), pathway]
topPathways <- c(topPathwaysUp, rev(topPathwaysDown))
plotGseaTable(examplePathways[topPathways], exampleRanks, fgseaRes, 
              gseaParam = 0.5)

From the plot above one can see that there are very similar pathways in the table (for example 5991502_Mitotic_Metaphase_and_Anaphase and 5991600_Mitotic_Anaphase). To select only independent pathways one can use collapsePathways function:

collapsedPathways <- collapsePathways(fgseaRes[order(pval)][padj < 0.01], 
                                      examplePathways, exampleRanks)
mainPathways <- fgseaRes[pathway %in% collapsedPathways$mainPathways][
                         order(-NES), pathway]
plotGseaTable(examplePathways[mainPathways], exampleRanks, fgseaRes, 
              gseaParam = 0.5)

最后保存结果。

library(data.table)
fwrite(fgseaRes, file="fgseaRes.txt", sep="t", sep2=c("", " ", ""))