Chapter 14 DEG GO Enrichment
library(Seurat)
library(tidyverse)
library(magrittr)
library(ReactomePA)
library(clusterProfiler)
library(enrichplot)
library(org.Mmu.eg.db)
library(DOSE)
14.1 Load DEG
<- readRDS('data/Demo_CombinedSeurat_SCT_Preprocess_FilterLQCells_DEGPerCluster_Minpct03Mindiffpct02.rds') mk
14.2 Get gene names per cluster
<- split(rownames(mk), f = mk$cluster) deg.ls
14.3 Transfer gene symbol into entrez id
<- deg.ls %>% map(~{
geneid.ls
# here for macaque
<- select(org.Mmu.eg.db,
gene.df keys = .x,
columns = c("ENTREZID", "SYMBOL"),
keytype = "SYMBOL")
<- gene.df$ENTREZID
gene <- gene[which(!is.na(gene))]
gene <- unique(gene)
gene
return(gene)
})
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
## 'select()' returned 1:1 mapping between keys and columns
14.4 GO for gene list
<- geneid.ls[c(1, 2, 8)]
gene.ls
# her mcc for macaque
<- compareCluster(geneCluster = gene.ls,
compKEGG fun = "enrichKEGG",
pvalueCutoff = 0.05,
pAdjustMethod = "BH",
organism = "mcc")
<- compareCluster(geneCluster = gene.ls,
compGO fun = "enrichGO",
pvalueCutoff = 0.05,
pAdjustMethod = "BH",
OrgDb = org.Mmu.eg.db,
ont = 'BP')
# compPathway <- compareCluster(geneCluster = gene.ls,
# fun = "enrichPathway",
# pvalueCutoff = 0.05,
# pAdjustMethod = "BH")
## dot plot
<- dotplot(compGO, showCategory = 10, title = "GO Enrichment Analysis")
g1 #g2 <- dotplot(compPathway, showCategory = 10, title = "REACTOME Pathway Enrichment Analysis")
<- dotplot(compKEGG, showCategory = 10, title = "KEGG Pathway Enrichment Analysis") g3
14.5 GO per cluster
## go enrichment per cluster
<- geneid.ls[c(1,2,8)] %>% map(~{
go.ls
<- enrichGO(
eGO gene = .x,
OrgDb = org.Mmu.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
readable = TRUE
)
return(eGO)
})
#pathway.ls <- gene.ls %>% map(~{
# ePathway <- enrichPathway(
# gene = .x,
# pvalueCutoff = 0.05,
# readable = TRUE,
# )
# return(ePathway)
#})
<- gene.ls %>% map(~{
kegg.ls <- enrichKEGG(
eKEGG gene = .x,
pvalueCutoff = 0.05,
organism = 'mcc'
)return(eKEGG)
})
## enrichment visu
<- function(object,
barplotTerm x = "Count",
color = 'p.adjust',
showCategory = 8,
font.size = 12,
title = "") {
## use *height* to satisy barplot generic definition
## actually here is an enrichResult object.
<- color
colorBy
<- fortify(object, showCategory = showCategory, by = x)
df $p.adjust <- -log10(df$p.adjust)
df#df <- df[c(1:3,9:12,15,16),]
if (colorBy %in% colnames(df)) {
<-
p ggplot(df, aes_string(x = x, y = "Description", fill = colorBy)) +
theme_dose(font.size) +
scale_fill_continuous(
low = "red",
high = "blue",
name = color,
guide = guide_colorbar(reverse = TRUE)
)else {
} <- ggplot(df, aes_string(x = x, y = "Description")) +
p theme_dose(font.size) +
theme(legend.position = "none")
}
+ geom_col(fill = color) + ggtitle(title) + xlab('-log10 FDR') + ylab(NULL)
p
}
lapply(1:length(gene.ls), function(x){
<- names(gene.ls)[[x]]
name = barplotTerm(go.ls[[x]], showCategory = 10, title = paste0(name, " GO"), color = 'blue', x = 'p.adjust')
g1 = barplotTerm(kegg.ls[[x]], showCategory = 10, title = paste0(name, " KEGG"), color = 'blue', x = 'p.adjust')
g3 print(g1)
print(g3)
})
## [[1]]
##
## [[2]]
##
## [[3]]