R_Code:GO and Functional GO

GO analysis:

library(AnnotationDbi)
library(org.Hs.eg.db) #基因注释包
library(clusterProfiler) #富集包

# 读取CSV文件
file_path <- "~/worksubmit/code/01-GO_analysis/Input File Format/UP_genes_ENSEMBL_ENTREZID.csv"
gene_data <- read.csv(file_path, header = TRUE, stringsAsFactors = FALSE)

# 提取第二列 ENTREZID
gene <- gene_data[, 2]

# GO富集分析
# GO富集的三个部分:CC、BP、MF 这里的P值和Q值都没有限定,因为后续想手动筛选
ego_CC <- enrichGO(gene = gene,
OrgDb=org.Hs.eg.db,
keyType = "ENTREZID",
ont = "CC",
pAdjustMethod = "BH",
minGSSize = 1,
pvalueCutoff = 1,
qvalueCutoff = 1,
readable = TRUE)

ego_BP <- enrichGO(gene = gene,
OrgDb=org.Hs.eg.db,
keyType = "ENTREZID",
ont = "BP",
pAdjustMethod = "BH",
minGSSize = 1,
pvalueCutoff = 1,
qvalueCutoff = 1,
readable = TRUE)

ego_MF <- enrichGO(gene = gene,
OrgDb=org.Hs.eg.db,
keyType = "ENTREZID",
ont = "MF",
pAdjustMethod = "BH",
minGSSize = 1,
pvalueCutoff = 1,
qvalueCutoff = 1,
readable = TRUE)

# 把得到的四个结果转换成数据框格式
ego_result_BP <- as.data.frame(ego_BP)
ego_result_CC <- as.data.frame(ego_CC)
ego_result_MF <- as.data.frame(ego_MF)

# 把GO富集分析得到的完整列表以及相关信息导出
write.csv(ego_result_BP,file = "ego_result_BP.csv",row.names = T)
write.csv(ego_result_CC,file = "ego_result_CC.csv",row.names = T)
write.csv(ego_result_MF,file = "ego_result_MF.csv",row.names = T)

GO for Figure:

#### 加载所需包 ####
library(devtools)
install_github('ievaKer/aPEAR')
library(aPEAR)
library(ggplot2)
library(cols4all)
#### 设置工作目录并读取富集结果 ####
result <- read.csv("Input Format_UP_ego_result_BP.csv", header = TRUE)

#### 绘制富集网络图(不清洗数据)####
set.seed(1234) # 固定节点布局
p <- enrichmentNetwork(result,
colorBy = "pvalue", # 显著性作为颜色映射
colorType = "pval", # 自动转换为 -log10(pvalue)
nodeSize = "Count", # 通路中基因数量作为节点大小
fontSize = 2, # 节点标签字体大小
pCutoff = -10, # 控制颜色渐变下限
drawEllipses = TRUE, # 是否绘制聚类边界
verbose = TRUE) +
guides(size = guide_legend(order = 1)) + # 图例顺序
labs(color = "-log10(p-value)") + # 图例标题
theme(legend.key = element_blank()) + # 去除图例背景框
scale_color_continuous_c4a_seq("yl_gn_bu") # 使用好看的连续配色

#### 保存网络图为 PDF ####
ggsave(filename = "03_Net_GO_UP_from_csv.pdf",
plot = p,
width = 8, height = 8, dpi = 300)

print("图像保存为:03_Net_GO_UP_from_csv.pdf")

 

 

本站原创,如若转载,请注明出处:https://www.ouq.net/3770.html

(0)
打赏 微信打赏,为服务器增加50M流量 微信打赏,为服务器增加50M流量 支付宝打赏,为服务器增加50M流量 支付宝打赏,为服务器增加50M流量
上一篇 5天前
下一篇 5天前

相关推荐

  • Rstudio/Rstudio Server enable Copilot-Rstudio Server打开Copilot

    Rstudio Server 默认是关闭Copilot Copilot is turned off by default. Copilot is turned off with copilot-enabled=0 in /etc/rstud…

    R 3天前
    35
  • R_Code: KEGG analysis

    library(clusterProfiler) library(org.Hs.eg.db) # 读取输入数据文件 file_path <- “C:/Users/Lamarck/Desktop/UP_genes_ENSEMBL_ENT…

    R 5天前
    55
  • R_Code:WGCNA and WGCNA_Get_Gene_Length

    library(WGCNA) library(DESeq2) # enableWGCNAThreads(nThreads = 10) # 在处理数据框(data.frame)时,不会自动给将String类型转换成factor类型 optio…

    R 5天前
    56
  • R_Code:RNAseq_GSEA_analysis

    library(clusterProfiler) # GSEA 和富集分析主力包 library(org.Hs.eg.db) # 人类注释数据库(ENTREZID 与 SYMBOL 等 ID 转换) library(enrichplot) …

    R 5天前
    60
  • R_Code:RNAseq_Gene_Type_Convert_ENSEMBL_to_ENTREZ

    1.Ensembl_to_Entrez: library(AnnotationDbi) library(org.Hs.eg.db) library(clusterProfiler) library(dplyr) diff <- rea…

    R 5天前
    53