# 选取背景基因,即关键基因或差异基因(试情况而定)
key_gene = setdiff(key_gene_low_salinity,key_gene_normal) %>% intersect(wgcna_key_gene)
# 准备eggnog注释文件
library(readr)
Penaeus_chinensis_annotations <- read_delim("~/Program/pan_genome/data/annotation/Penaeus_chinensis_annotations.tsv",
delim = "\t", escape_double = FALSE,
comment = "#", trim_ws = TRUE)
# GO富集
## 准备GO注释内容
# 获取go term 编号对应的名称
library(GO.db)
goterms <- Term(GOTERM)
GOlist=as.data.frame(goterms)
go2name <- rownames_to_column(GOlist,var = 'GO_id') %>%
mutate(GO_id = str_sub(GO_id,4,10) )
# 获取每个基因对应的GO注释编号
GO_gene = Penaeus_chinensis_annotations %>%
dplyr::select(1,10) %>%
filter(GOs != "-") %>%
separate_rows(GOs,sep = ",",convert = F) %>%
mutate(GOs = substr(GOs,4,10)) %>%
unique()
GO_gene = GO_gene %>% dplyr::select(2,1)
library(clusterProfiler)
GO_result <- enricher(key_gene,
TERM2GENE = GO_gene,
TERM2NAME = go2name,
pvalueCutoff = 0.05,
qvalueCutoff = 0.2)
GO_result_data <- as.data.frame(GO_result) %>% filter(Description != "NA")
# 添加MF、BP、CC分类
go_ont <- go2ont(str_c("GO:",GO_result_data$ID,sep = "")) %>%
mutate(go_id = str_sub(go_id,4,10))
# 排序
go_df <- left_join(GO_result_data,go_ont,by=c("ID" = "go_id")) %>%
arrange(qvalue) %>%
arrange(Ontology)
# 转化为因子
go_df <- mutate(go_df,Description = factor(Description,levels = Description))
# 绘制条形图
library(ggsci)
ggplot(data = go_df,aes(x = Description,y=-log10(qvalue)))+
geom_col(aes(fill = Ontology),width = 0.6)+
scale_fill_npg()+
theme_light() +
theme(axis.text = element_text(hjust = 1,
angle = 70))+labs(x = "GO term")
非模式生物GO富集分析(结合eggnog mapper注释)
最新推荐文章于 2025-02-15 10:58:59 发布