GO,KEGG,DO 富集分析


what is Gene Ontology(GO)

基因“本体论” 对事物的分类描述,对基因的分类描述
对基因的描述

1、cellular component,CC(基因存在于细胞质还是细胞核,是线粒体还是其他细胞器)细胞组成
2、Biological process,BP(能够参与哪一个生物学过程,参与rna加工,复制等)生物学过程
3、Molecular function,MF(分子功能上,催化什么反应,什么样的酶)分子功能
基于以上三类,对基因进行分类
so,we will have a gene annotation information

一、RNA-Seq ctrl, treatment

ctrl gene expression distribution, 在1种条件下的基因表达谱
treatment gene expression distribution,在其他条件下的基因表达谱
ctrl v.s. treatment ->DEG 差异表达基因
DEG:differential expression genes (cuffdiff,比较两者差异基因)
cufflink 计算基因表达量

二、DEFG ->GO annotation(找到GO注释)

1、cellular component,CC(基因存在于细胞质还是细胞核)
2、Biological process,BP(能够参与哪一个生物学过程)
3、Molecular function,MF(分子功能上)

how to test if the GO is enriched? 如何去检测GO的富集
GO enrichment analysis(GO富集分析)
什么是GO注释?(为了给基因分配 go term)
如何拿到GO注释

model orgnism -> annotated databass(模式生物已经分配好了GO term)
non-model orgnism ->search database(非模式生物,需要自己去找,如果没有需要用blast办法?)
无参的生物(A)没有 reference ,找相近的有 reference 的生物(B)
用 A blast B ,A 里面的 gene1 比对到 B 的 gene2 ,然后找 gene2 的 term 或者 annotation 当作 A 的。(使用的软件 blast2GO 还有其他的 )

KEGG enrichment analysis?(代谢通路富集分析)
DO (disease)enrichment analysis? (疾病富集分析)[一般是临床使用]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
###########################################################
# 2020/3/8  
# test GO analysis and KEGG pathway analysis
############################################################
rm(list = ls())

# 1、 RNAseq  fastq -> BAM (tophat2, hiast ,star)
# 2、 cufflink BAM
# 3、 cuffdiff BAM GTF

# 1. load cuffdiff result
cuffdiff_result = read.table(file="../Desktop/test_data/rnaseq_test_date/diff_out1/gene_exp.diff",header = T,sep = "\t")
cuffdiff_result$sample_1 = "ctrl"
cuffdiff_result$sample_2 = "treat"

#test_id 或者 gene_id 称为 gene samble = samble

# 2. select DEG
# Ⅰ. FPKM1 or FPKM2 >1
# Ⅱ. log2(fold change) >1 or < -1
# Ⅲ.  p_value <0.05
select_vector = (cuffdiff_result$value_1 > 1 | cuffdiff_result$value_2 > 1 ) & abs(cuffdiff_result$log2.fold_change.) >= 1 &  (cuffdiff_result$p_value < 0.05)
cuffdiff_result.sign = cuffdiff_result[select_vector,]


output.gene_id = data.frame(gene_id = cuffdiff_result.sign$gene_id)
write.table(output.gene_id , file = "../Desktop/test_data/GO,kegg(live7)/sign_gene_id_text",col.names = F ,row.names = F,sep = "\t",quote = F)

##################################
# 在R上做
# setup R package
###################################
library(clusterProfiler)
# 用来做富集分析
library(topGO)
# GO看图用
library(Rgraphviz)
# 调用上面两个包
library(pathview)
# 看 KEGG pathway
library(org.Hs.eg.db)
# 人的注释文件,去 bioconductor 可以搜其他的注释文件(模式生物都有)

###################################
# GO 分析
###################################
DEG.gene_symbol = as.character(output.gene_id$gene_id)
columns(org.Hs.eg.db) #查看常用类型,用于下面 keyType 填写

DEG.entrez_id = mapIds(x = org.Hs.eg.db,
                      keys = DEG.gene_symbol,
                      keytype = "SYMBOL",
                      column = "ENTREZID") # 转化ID,一般用 ENTREZID ,其中会有转换不成功的NA
DEG.entrez_id = na.omit(DEG.entrez_id)  #剔除NA


######## GO.BP
enrich.go.bp = enrichGO(gene = DEG.entrez_id,
                        OrgDb = org.Hs.eg.db,
                        keyType = "ENTREZID",
                        ont = "BP",
                        pvalueCutoff = 0.01,
                        qvalueCutoff = 0.05,
                        readable = T) #pvaluecutoff 是 pvalue 的阈值,富集的统计显著性要小于0.01, q 是 p 的修正值

######### GO.CC
enrich.go.cc = enrichGO(gene = DEG.entrez_id,
                        OrgDb = org.Hs.eg.db,
                        keyType = "ENTREZID",
                        ont = "CC",
                        pvalueCutoff = 0.01,
                        qvalueCutoff = 0.05,
                        readable = T)

########## GO.MF
enrich.go.mf = enrichGO(gene = DEG.entrez_id,
                        OrgDb = org.Hs.eg.db,
                        keyType = "ENTREZID",
                        ont = "mf",
                        pvalueCutoff = 0.01,
                        qvalueCutoff = 0.05,
                        readable = T)


########## barblot, dotplot
barplot(enrich.go.bp)
barplot(enrich.go.cc)
barplot(enrich.go.mf)

dotplot(enrich.go.bp)

########## plotGOgraph (树形图)
pdf(file = "../Desktop/test_data/GO,kegg(live7)/enrich.go.bp.tree.pdf",width = 10,height = 15)  #直接保存成pdf文件
plotGOgraph(enrich.go.bp)
dev.off() # 关闭画图,与pdf一套



#########################
# KEGG pathway analysis
#########################
kegg.out = enrichKEGG(gene = DEG.entrez_id,
                      organism = "hsa",
                      keyType = "kegg",
                      pvalueCutoff = 0.05,
                      pAdjustMethod = "BH",
                      qvalueCutoff = 0.1)
barplot(kegg.out)




#############################
# 如果是非模式生物,但是有参考基因组
# 以番茄为例子
source("https://bioconductor.org/biocLite.R")
BiocManager::install("AnnotationHub")
BiocManager::install("biomaRt")

# 载入包
library(AnnotationHub)
library(biomaRt)

# 制作 OrgDb
hub <- AnnotationHub::AnnotationHub()

#使用query在我们制作的OrgDB --> hub里面找到番茄相关的database即org.Solanum_lycopersicum.eg.sqlite 注:Solanum_lycopersicum是番茄的拉丁名和它对应的编号AH59087

query(hub, "Solanum")  # Solanum番茄的拉丁名

# 下载下来
Solanum.OrgDb <- hub[["AH59087"]]
#此时,番茄的database就会赋值到变量Solanum.OrgDb