Y叔的clusterProfiler 升级到4版本了,所以试用一下它的内容,其实文章都有写,我就是简单copy一下文章中的代码。
如果直接安装安装不了的话,就使用本地安装吧
clusterProfiler 4.0: A universal enrichment tool for interpreting omics data (cell.com)
一,主要参数
library(clusterProfiler)
data(geneList,package="DOSE")
head(geneList)
de<-names(geneList)[abs(geneList)>2]
ego<-enrichGO(de,OrgDb = "org.Hs.eg.db",ont="BP",readable = TRUE)
ego2 <- simplify(ego, cutoff=0.7, by="p.adjust", select_fun=min)
head(ego)
head(ego2)
kk <- gseKEGG(geneList, organism = "hsa")
## downloaded from https://wikipathways-data.wmcloud.org/current/gmt/
gmt <- 'wikipathways-20210710-gmt-Homo_sapiens.gmt'
wp <- read.gmt.wp(gmt)
ewp <- GSEA(geneList, TERM2GENE=wp[,c("wpid", "gene")], TERM2NAME=wp[,c("wpid", "name")])
library("ChIPseeker")
downloadGSMbedFiles("GSM1295076")
file <- "GSM1295076_CBX6_BF_ChipSeq_mergedReps_peaks.bed.gz"
gr <- readPeakFile(file)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
TxDb <- TxDb.Hsapiens.UCSC.hg19.knownGene
genes <- seq2gene(gr, tssRegion=c(-1000, 1000), flankDistance = 3000, TxDb)
library(clusterProfiler)
g <- bitr(genes, 'ENTREZID', 'SYMBOL', 'org.Hs.eg.db')
data(DE_GSE8057)
xx <- compareCluster(Gene~time+treatment, data=DE_GSE8057, fun = enricher,
TERM2GENE=wp[,c("wpid", "gene")], TERM2NAME=wp[,c("wpid", "name")])
## head or tail to print first or last n rows
head(ego, 2)
ego[1:2, c("ID", "Description", "pvalue", "p.adjust")]
ego[["GO:0140014"]]
dim(ego)
ego2 <- filter(ego, p.adjust < 0.001, Count > 10)
dim(ego2)
ego3 <- mutate(ego, richFactor = Count / as.numeric(sub("/\\d+", "", BgRatio)))
head(ego3)
library(tidyverse)
ewp2 <-arrange(ewp, desc(abs(NES))) %>%
group_by(sign(NES)) %>%
slice(1:5)
library(ggplot2)
library(forcats)
library(DOSE)
ggplot(ego3, showCategory = 10,
aes(richFactor, fct_reorder(Description, richFactor))) +
geom_segment(aes(xend=0, yend = Description)) +
geom_point(aes(color=p.adjust, size = Count)) +
scale_color_gradientn(colours=c("#f7ca64", "#46bac2", "#7e62a3"),
trans = "log10",
guide=guide_colorbar(reverse=TRUE, order=1)) +
scale_size_continuous(range=c(2, 10)) +
theme_dose(12) +
xlab("Rich Factor") +
ylab(NULL) +
ggtitle("Biological Processes")
library(ggplot2)
ggplot(ewp2, showCategory=10,
aes(NES, fct_reorder(Description, NES), fill=qvalues)) +
geom_col() +
scale_fill_gradientn(colours=c('#b3eebe', "#46bac2", '#371ea3'),
guide=guide_colorbar(reverse=TRUE)) +
theme_dose(12) +
xlab("Normalized Enrichment Score") +
ylab(NULL) +
ggtitle("WikiPathways")