/
topic5_02_simplifyEnrichment.Rmd
172 lines (122 loc) · 4.05 KB
/
topic5_02_simplifyEnrichment.Rmd
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---
title: "Topic 5-02: simplifyEnrichment"
author: "Zuguang Gu <z.gu@dkfz.de>"
date: '`r Sys.Date()`'
output:
html_document:
toc: true
toc_float: true
vignette: >
%\VignetteIndexEntry{Topic 5-02: simplifyEnrichment}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
**simplifyEnrichment** is suggested to work on GO enrichment results.
## A vector of GO IDs
```{r, echo = FALSE}
library(simplifyEnrichment)
se_opt$verbose = FALSE
```
```{r, fig.width = 8, fig.height = 4.5}
library(simplifyEnrichment)
set.seed(888)
go_id = random_GO(500)
df = simplifyGO(go_id)
head(df)
```
## Multiple enrichment results
We have some signature genes. They can be clustered into four groups with
their expression profile. We apply GO enrichment on the four gene lists and we have
four enrichment tables.
```{r, echo = FALSE, message = FALSE, fig.width = 8, fig.height = 7}
library(cola)
data(golub_cola)
res = golub_cola["ATC:skmeans"]
get_signatures(res, k = 3)
```
```{r}
lt = readRDS(system.file("extdata", "lt_enrichment_tables.rds", package = "GSEAtraining"))
length(lt)
head(lt[[1]])
```
`simplifyGOFromMultipleLists()` can visualize GO enrichment from multiple results.
```{r, fig.width = 10, fig.height = 6, eval = FALSE}
simplifyGOFromMultipleLists(lt, padj_cutoff = 0.001)
```
<img src="topic5_02_figure_2.png" />
## Word clouds
Let's say, for the following plot, the heatmap is might not be necessary to put into the final report.
```{r, fig.width = 8, fig.height = 4.5, eval = FALSE}
df = lt[[1]]
go_id = df$ID[df$p.adjust < 0.01]
simplifyGO(go_id)
```
<img src="topic5_02_figure_3.png" />
`summarizeGO()` makes an even simpler plot with word cloud and simple statistical graphics.
Two inputs for the function:
- A vector of GO IDs
- A numeric vector of corresponding statistics
```{r, fig.width = 8, fig.height = 5, eval = FALSE}
l = df$p.adjust < 0.01
summarizeGO(df$ID[l], -log10(df$p.adjust)[l], axis_label = "average -log10(p.adjust)")
```
<img src="topic5_02_figure_4.png" />
Or visualize average log2 fold enrichment:
```{r, fig.width = 8, fig.height = 5, eval = FALSE}
l = df$p.adjust < 0.01
summarizeGO(df$ID[l], df$log2_fold_enrichment[l], axis_label = "average log2(fold enrichment)")
```
<img src="topic5_02_figure_5.png" />
`summarizeGO()` also supports multiple enrichment results. In this case, `value` should be
is a list of numeric named vectors which contains significant GO terms in each enrichment table.
```{r, fig.width = 8, fig.height = 7, eval = FALSE}
value = lapply(lt, function(df) {
v = -log10(df$p.adjust)
names(v) = df$ID
v[df$p.adjust < 0.001]
})
summarizeGO(value = value, axis_label = "average -log10(p.adjust)",
legend_title = "-log10(p.adjust)")
```
<img src="topic5_02_figure_6.png" />
Or use log2 fold enrichment:
```{r, fig.width = 8, fig.height = 7, eval = FALSE}
value = lapply(lt, function(df) {
v = df$log2_fold_enrichment
names(v) = df$ID
v[df$p.adjust < 0.001]
})
summarizeGO(value = value, axis_label = "average log2_fold_enrichment",
legend_title = "log2(fold_enrichment)")
```
<img src="topic5_02_figure_7.png" />
## Practice
### {.tabset}
#### Practice 1
Recall in [Topic 2-02: Implement ORA from stratch](topic2_02_implement_ora.html), we compared
the ORA results when setting DE cutoffs to 0.05, 0.01 and 0.001. Now perform a simplify enrichment
analysis on the three ORA tables and compare them.
```{r}
de = readRDS(system.file("extdata", "de.rds", package = "GSEAtraining"))
de = de[, c("symbol", "p_value")]
de = de[!is.na(de$p_value), ]
de_genes_1 = de$symbol[de$p_value < 0.05]
de_genes_2 = de$symbol[de$p_value < 0.01]
de_genes_3 = de$symbol[de$p_value < 0.001]
library(GSEAtraining)
library(org.Hs.eg.db)
gs = get_GO_gene_sets_from_orgdb(org.Hs.eg.db, "BP", gene_id_type = "SYMBOL")
tb1 = ora(de_genes_1, gs)
tb2 = ora(de_genes_2, gs)
tb3 = ora(de_genes_3, gs)
```
#### Solution
```{r, eval = FALSE}
lt = list(
"DE_0.05" = tb1,
"DE_0.01" = tb2,
"DE_0.001" = tb3
)
simplifyGOFromMultipleLists(lt, padj_cutoff = 0.05)
```
<img src="topic5_02_figure_solution.png" />