-
Notifications
You must be signed in to change notification settings - Fork 0
/
fig2_supp.fig3.Rmd
177 lines (168 loc) · 10.4 KB
/
fig2_supp.fig3.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
173
174
175
176
177
---
title: "Generation of main Fig. 2 and Supp. Fig. 3"
subtitle: "Data of Zhu et al. https://doi.org/10.7150%2Fthno.48206"
author: "Aram Safrastyan"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
html_document:
toc: TRUE
code_folding: hide
number_sections: TRUE
---
<style type="text/css">
.main-container {
max-width: 1500px;
margin-left: auto;
margin-right: auto;
}
</style>
```{r global_options, echo = F}
knitr::opts_chunk$set(fig.path='markdown_results/')
```
# load libraries
***
```{r libraries, message=F, warning=F}
library(dplyr)
library(cowplot)
library(ggplot2)
library(forcats)
library(scales)
library(ReactomePA)
library(org.Hs.eg.db)
library(magick)
library(clusterProfiler)
library(ragg)
library(AnnotationDbi)
```
# Generation of Fig. 2
***
```{r main, warning=F, message=F, fig.width= 25, fig.height=20, fig.align='center'}
#load cfRNA WGCNA results
load("./cfrna/results/wgcna_main/cfwgcna.RData")
#get gene names and transfer to ENTREZID
module_genes<-data.frame( module = cfmergedcolors, gene = colnames(cfrna_wgcna_input))
module_genes_entrez<-AnnotationDbi::select(org.Hs.eg.db,
keys = module_genes$gene,
keytype = "SYMBOL",
columns = c("SYMBOL","ENTREZID")) %>% dplyr::left_join(module_genes,by=c("SYMBOL"="gene"))
#Reactome pathway enrichment analysis and visualization of module cf-turquoise
turq_genes<-module_genes_entrez %>% dplyr::filter(module=="cf-turquoise") %>% na.omit() %>%
dplyr::select(ENTREZID) %>% unique()
turq_reactome <- enrichPathway(gene= turq_genes$ENTREZID, pvalueCutoff = 0.05)
turq_reactome_df<-fortify(turq_reactome, showCategory = 10)
turq_reactome_df$p.adjust<- -log10(as.numeric(turq_reactome_df$p.adjust))
turq_reactome_plot<-ggplot(turq_reactome_df, aes(x = GeneRatio, y = fct_reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_size_continuous(range = c(6, 10), breaks = pretty_breaks(n=3)) +
scale_colour_gradient(name = "-log10(p.adjust)", low="grey", high="black", breaks=scales::extended_breaks()) +
guides(size = guide_legend(reverse=T)) +
ylab(NULL) +
scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 30)) +
theme_bw(base_size = 26, base_family = "Arial", base_rect_size = 1, base_line_size = 1) +
theme(plot.title = element_text(color="black", size=28, face="bold", hjust = 0.5),
plot.subtitle = element_text(color="black", size=27, face="bold", hjust = 0.5)) +
ggtitle("Reactome pathway enrichment analysis", subtitle = "cfRNA module cf-turquoise")
#Reactome pathway enrichment analysis and visualization of module cf-blue
blue_genes<-module_genes_entrez %>% dplyr::filter(module=="cf-blue") %>% na.omit() %>%
dplyr::select(ENTREZID) %>% unique()
blue_reactome <- enrichPathway(gene= blue_genes$ENTREZID, pvalueCutoff = 0.05)
blue_reactome_df<-fortify(blue_reactome, showCategory = 10)
blue_reactome_df$p.adjust<- -log10(as.numeric(blue_reactome_df$p.adjust))
blue_reactome_plot<-ggplot(blue_reactome_df, aes(x = GeneRatio, y = fct_reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_size_continuous(range = c(6, 10), breaks = pretty_breaks(n=3)) +
scale_colour_gradient(name = "-log10(p.adjust)", low="grey", high="black", breaks=scales::extended_breaks()) +
guides(size = guide_legend(reverse=T)) +
ylab(NULL) +
scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 30)) +
scale_x_continuous(labels =scales::label_number(accuracy = 0.001), breaks = scales::extended_breaks(n=3)) +
theme_bw(base_size = 26, base_family = "Arial", base_rect_size = 1, base_line_size = 1) +
theme(plot.title = element_text(color="black", size=28, face="bold", hjust = 0.5),
plot.subtitle = element_text(color="black", size=27, face="bold", hjust = 0.5)) +
ggtitle("Reactome pathway enrichment analysis", subtitle = "cfRNA module cf-blue")
#load module representations generated by Cytoscape
blue_module_plot<-draw_image("./cytoscape/edges_blue.png", width=.5, height=1, x=0, y=0.25, scale = 1.5)
turq_module_plot<-draw_image("./cytoscape/edges_turquoise.png", width=.5, height=1, x=0.5, y=0.25, scale=1.5)
#combine the plots in one image
fig2<-ggdraw() + blue_module_plot + turq_module_plot + draw_plot(blue_reactome_plot, x=0, y=0, width = .5, height=.5) + draw_plot(turq_reactome_plot, x=0.5, y=0, width = .5, height=.5) + draw_plot_label(label = c("A", "B", "C", "D"), size = 42, x = c(0, 0.5, 0, 0.5), y = c(1, 1, 0.5, 0.5), family = "Arial") + draw_label("Network visualization", size=28, x=0.27, y=0.98, fontface = 'bold', fontfamily = "Arial") + draw_label("cfRNA module cf-blue", size=27, x=0.27, y=0.96, fontface = 'bold', fontfamily = "Arial") + draw_label("Network visualization", size=28, x=0.77, y=0.98, fontface = 'bold', fontfamily = "Arial") + draw_label("cfRNA module cf-turquoise", size=27, x=0.77, y=0.96, fontface = 'bold', fontfamily = "Arial")
plot(fig2)
#save
ggsave(plot=fig2, file="./figures/main_figures/fig2.png", units = "mm", device = ragg::agg_png, height=150, width=180, scaling = 0.3, limitsize = FALSE)
```
# Generation of Supp Fig. 3
***
```{r supp, warning=F, message=F, fig.width= 25, fig.height=20, fig.align='center'}
#for Linux based systems
options(clusterProfiler.download.method = "wget")
#KEGG pathway enrichment analysis and visualization for module cf-turquoise
turq_kegg <- enrichKEGG(gene= turq_genes$ENTREZID, pvalueCutoff = 0.05, organism = 'hsa')
turq_kegg_df<-fortify(turq_kegg, showCategory = 10)
turq_kegg_df$p.adjust<- -log10(as.numeric(turq_kegg_df$p.adjust))
turq_kegg_plot<-ggplot(turq_kegg_df, aes(x = GeneRatio, y = fct_reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_size_continuous(range = c(6, 10), breaks = pretty_breaks(n=3)) +
scale_colour_gradient(name = "-log10(p.adjust)", low="grey", high="black", breaks=scales::extended_breaks()) +
guides(size = guide_legend(reverse=T)) +
ylab(NULL) +
ggtitle(paste0("KEGG pathway enrichment analysis", "\n", "cfRNA module cf-turquoise")) +
scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 30)) +
theme_bw(base_size = 26, base_family = "Arial", base_rect_size = 1, base_line_size = 1) +
theme(plot.title = element_text(color="black", size=28, face="bold", hjust = 0.5))
#WikiPathways pathway enrichment analysis and visualization for module cf-turquoise
turq_wp<-enrichWP(turq_genes$ENTREZID, organism = "Homo sapiens")
turq_wp_df<-fortify(turq_wp, showCategory = 10)
turq_wp_df$p.adjust<- -log10(as.numeric(turq_wp_df$p.adjust))
turq_wp_plot<-ggplot(turq_wp_df, aes(x = GeneRatio, y = fct_reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_size_continuous(range = c(6, 10), breaks = pretty_breaks(n=3)) +
scale_colour_gradient(name = "-log10(p.adjust)", low="grey", high="black", breaks=scales::extended_breaks()) +
guides(size = guide_legend(reverse=T)) +
ylab(NULL) +
scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 30)) +
theme_bw(base_size = 26, base_family = "Arial", base_rect_size = 1, base_line_size = 1) +
theme(plot.title = element_text(color="black", size=28, face="bold", hjust = 0.5),
plot.subtitle = element_text(color="black", size=27, face="bold", hjust = 0.5)) +
ggtitle("WikiPathways pathway enrichment analysis", subtitle = "cfRNA module cf-turquoise")
#KEGG pathway enrichment analysis and visualization for module cf-blue
blue_genes<-module_genes_entrez %>% dplyr::filter(module=="cf-blue") %>% na.omit() %>%
dplyr::select(ENTREZID) %>% unique()
blue_kegg <- enrichKEGG(gene= blue_genes$ENTREZID, pvalueCutoff = 0.05, organism = "hsa")
blue_kegg_df<-fortify(blue_kegg, showCategory = 10)
blue_kegg_df$p.adjust<- -log10(as.numeric(blue_kegg_df$p.adjust))
blue_kegg_plot<-ggplot(blue_kegg_df, aes(x = GeneRatio, y = fct_reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_size_continuous(range = c(6, 10), breaks = pretty_breaks(n=3)) +
scale_colour_gradient(name = "-log10(p.adjust)", low="grey", high="black", breaks=scales::extended_breaks()) +
guides(size = guide_legend(reverse=T)) +
ylab(NULL) +
scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 30)) +
scale_x_continuous(labels =scales::label_number(accuracy = 0.001), breaks = scales::extended_breaks(n=3)) +
theme_bw(base_size = 26, base_family = "Arial", base_rect_size = 1, base_line_size = 1) +
theme(plot.title = element_text(color="black", size=28, face="bold", hjust = 0.5),
plot.subtitle = element_text(color="black", size=27, face="bold", hjust = 0.5)) +
ggtitle("KEGG pathway enrichment analysis", subtitle = "cfRNA module cf-blue")
#WikiPathways pathway enrichment analysis and visualization for module cf-blue
blue_wp<-enrichWP(blue_genes$ENTREZID, organism = "Homo sapiens")
blue_wp_df<-fortify(blue_wp, showCategory = 10)
blue_wp_df$p.adjust<- -log10(as.numeric(blue_wp_df$p.adjust))
blue_wp_plot<-ggplot(blue_wp_df, aes(x = GeneRatio, y = fct_reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_size_continuous(range = c(6, 10), breaks = pretty_breaks(n=3)) +
scale_colour_gradient(name = "-log10(p.adjust)", low="grey", high="black", breaks=scales::extended_breaks()) +
guides(size = guide_legend(reverse=T)) +
ylab(NULL) +
scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 30)) +
theme_bw(base_size = 26, base_family = "Arial", base_rect_size = 1, base_line_size = 1) +
theme(plot.title = element_text(color="black", size=28, face="bold", hjust = 0.5),
plot.subtitle = element_text(color="black", size=27, face="bold", hjust = 0.5)) +
ggtitle("WikiPathways pathway enrichment analysis", subtitle = "cfRNA module cf-blue")
#combine plots
supp_fig3<-ggdraw() + draw_plot(blue_kegg_plot, x=0, y=0.5, width = .5, height=.5) + draw_plot(blue_wp_plot, x=0.5, y=0.5, width = .5, height=.5) + draw_plot(turq_kegg_plot, x=0, y=0, width = .5, height=.5) + draw_plot(turq_wp_plot, x=0.5, y=0, width = .5, height=.5) + draw_plot_label(label = c("A", "B", "C", "D"), size = 42, x = c(0, 0.5, 0, 0.5), y = c(1, 1, 0.5, 0.5), family = "Arial")
plot(supp_fig3)
dir.create("./figures/supp_figures/")
#save
ggsave(plot=supp_fig3, file="./figures/supp_figures/supp_fig3.png", units = "mm", device = ragg::agg_png, height=150, width=180, scaling = 0.3, limitsize = FALSE)
```
```{r}
sessionInfo()
```