-
Notifications
You must be signed in to change notification settings - Fork 0
/
fig3_supp.fig.4.Rmd
185 lines (172 loc) · 8.74 KB
/
fig3_supp.fig.4.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
178
179
180
181
182
183
184
185
---
title: "Generation of main Fig. 3 and Supp. Fig. 4"
subtitle: "Data of Zhu et al. https://doi.org/10.7150%2Fthno.48206 & Li et al. https://doi.org/10.1093/nar/gkx891"
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(forcats)
library(dplyr)
library(WGCNA)
library(cowplot)
library(ggplot2)
library(RColorBrewer)
library(tibble)
library(ggrepel)
library(tidyr)
library(stringr)
library(cowplot)
```
# Module presevation calculation (cfRNA modules => exoRNA data)
## warning - resource intensive!
***
```{r cfmp, warning=F, message=F}
enableWGCNAThreads(nThreads=snakemake@threads)
load("./cfrna/results/wgcna_main/cfwgcna.RData")
load("./exorna/results/wgcna_main/exowgcna.RData")
setLabels <- c("cfRNA", "exoRNA")
multiExpr <- list(cfRNA = list(data = cfrna_wgcna_input), exoRNA = list(data = exorna_wgcna_input))
multiColor <- list(cfRNA = cfmergedcolors)
mp_cf_exo <- modulePreservation(multiExpr, multiColor, referenceNetworks = 1, nPermutations = 100, randomSeed = 1, quickCor = 0, maxModuleSize=5000, maxGoldModuleSize=5000, parallelCalculation=T)
```
# Generation of Figure 3
***
```{r cfmp_plot, warning=F, message=F, fig.width= 8, fig.height=5, fig.align='center'}
#load("./cfrna/results/mp_cf_exo/mp_cf_exo.RData")
#get module size and Zsum connectivity statistics
ref <- 1
test <- 2
modColors <- rownames(mp_cf_exo$preservation$observed[[ref]][[test]])
moduleSizes <- mp_cf_exo$preservation$Z[[ref]][[test]][, 1]
plotData <- cbind(mp_cf_exo$preservation$observed[[ref]][[test]][, 2], mp_cf_exo$preservation$Z[[ref]][[test]][, 2])
df<-as.data.frame(plotData)
df$mod<-modColors
df<-df[ , 2:3]
df$size<-moduleSizes
# leave grey and gold modules out
df_input<-df %>%
filter(!mod %in% c("gold", "grey")) %>% mutate(col=str_remove(mod, "cf-"))
rects <- data.frame(xstart = c(0, 2, 10), xend = c(2, 10, 100), col = letters[1:3])
mp1<-ggplot() +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend, ymin = 0, ymax = 8000, fill=col), alpha = 0.15,) +
scale_fill_manual(values=c("darkgrey", "lightblue", "blue")) +
geom_point(data=df_input, aes(x=V2, y=size, colour=col), size=8, alpha=0.5) +
geom_vline(xintercept = 2, colour="red") +
geom_vline(xintercept = 10, colour="green") +
theme_classic(base_size = 8) +
scale_colour_identity() +
geom_label_repel(data = df_input,
aes(x=V2, y=size, label=mod),
box.padding = 0.5,
point.padding = 0.5,
segment.color = 'black',
max.overlaps = Inf,
size=2,
segment.size=0.5,force=50) +
scale_x_continuous(trans='pseudo_log', expand = c(0, 0), breaks=c(0, 2, 10, 30, 70)) +
scale_y_continuous(trans='pseudo_log', expand = c(0, 0), breaks = c(0, 100, 300, 1000, 3000), limits = c(0, 8000)) +
labs(x = "Module preservation (Zsum)", y = "Module size", title="Module preservation vs. module size", subtitle = "cell-free RNA modules in exosomal RNA dataset") +
theme(text=element_text(family="Arial"), plot.title = element_text(color="black", size=9, face="bold", hjust = 0.5), plot.subtitle = element_text(color="black", size=8, face="bold", hjust = 0.5), legend.position="none")
#get Zconnectiviy and Zdensity preservation statistics
mp_data<-data.frame(density=mp_cf_exo$preservation$Z$ref.cfRNA$inColumnsAlsoPresentIn.exoRNA$Zdensity.pres, connectivity=mp_cf_exo$preservation$Z$ref.cfRNA$inColumnsAlsoPresentIn.exoRNA$Zconnectivity.pres, modules= rownames(mp_cf_exo$preservation$observed[[ref]][[test]])) %>%
filter(., !(modules %in% c("grey", "gold")) ) %>%
mutate(col=str_remove(modules, "cf-"))
rects <- data.frame(xstart = c(-1, 2, 10, -1, -1, -1), xend = c(2, 10, 90, 90, 90, 90), ystart=c(0, 0, 0, 0, 2, 10) , yend=c(130, 130, 130, 2, 10, 130) , col = letters[1:6])
mp2<-ggplot() +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend, ymin = ystart, ymax = yend, fill=col), alpha = 0.15,) +
scale_fill_manual(values=c("darkgrey", "lightblue", "blue", "grey", "lightblue", "blue")) +
geom_point(data=mp_data, aes(x=density, y=connectivity, colour=col), size=8, alpha=0.5) +
geom_vline(xintercept = 2, colour="red") + geom_vline(xintercept = 10, colour="green") +
geom_hline(yintercept = 2, colour="red") + geom_hline(yintercept = 10, colour="green") +
theme_classic(base_size = 8) + scale_colour_identity() +scale_x_continuous(trans='pseudo_log', limits = c(-1,90), expand = c(0, 0), breaks=c(-1, 0, 2, 10, 30, 75)) +
scale_y_continuous(trans='pseudo_log', limits = c(0,130), expand = c(0, 0), breaks = c(0, 2, 10, 30, 75)) +
geom_label_repel(data = mp_data,
aes(x=density, y=connectivity, label=modules),
box.padding = 0.5,
point.padding = 0.5,
segment.color = 'black',
max.overlaps = Inf,
size=2,
segment.size=0.5,force=50) +
labs(x = "Module density preservation", y = "Module connectivity preservation", title="Module density vs. connectivity preservation", subtitle = "cell-free RNA modules in exosomal RNA dataset") +
theme(text=element_text(family="Arial"), plot.title = element_text(color="black", size=9, face="bold", hjust = 0.5), plot.subtitle = element_text(color="black", size=8, face="bold", hjust = 0.5), legend.position="none")
#combine
fig3<-ggdraw(ylim=c(0.5, 1), clip = "on") +
draw_plot(mp1, x = 0, y = 0.5, height=.5, width=.5) +
draw_plot(mp2, x = .5, y = 0.5, height=.5, width = .5) +
draw_plot_label(label = c("A", "B"), size = 12,
x = c(0, 0.5), y = c(1, 1), family = "Arial")
fig3
ggsave(plot=fig3, "./figures/main_figures/fig3.png", scale=1, units = "mm", width=180, height=70)
```
# Module presevation calculation (exoRNA modules => cfRNA data)
## warning resource intensive!
***
```{r exomp, warning=F, message=F}
enableWGCNAThreads(nThreads=snakemake@threads)
setLabels <- c("exoRNA", "cfRNA")
multiExpr <- list(exoRNA = list(data = exorna_wgcna_input), cfRNA = list(data = cfrna_wgcna_input) )
multiColor <- list(exoRNA = exomergedcolors)
mp_exo_cf <- modulePreservation(multiExpr, multiColor, referenceNetworks = 1, nPermutations = 100, randomSeed = 1, quickCor = 0, maxModuleSize=5500, maxGoldModuleSize=5500, parallelCalculation=T)
```
# Generation of Supp. Figure 4
***
```{r exomp_plot, message=F, warning=F, fig.width= 8, fig.height=5, fig.align='center'}
#get module size and Zsum connectivity statistics
ref <- 1
test <- 2
modColors <- rownames(mp_exo_cf$preservation$observed[[ref]][[test]])
moduleSizes <- mp_exo_cf$preservation$Z[[ref]][[test]][, 1]
plotData <- cbind(mp_exo_cf$preservation$observed[[ref]][[test]][, 2], mp_exo_cf$preservation$Z[[ref]][[test]][, 2])
df<-as.data.frame(plotData)
df$mod<-modColors
df<-df[ , 2:3]
df$size<-moduleSizes
# leave grey and gold modules out
df_input<- df %>%
filter(!mod %in% c("gold", "grey")) %>%
mutate(col=str_remove(mod, "exo-"))
rects <- data.frame(xstart = c(0, 2, 10), xend = c(2, 10, 100), col = letters[1:3])
supp_fig4<-ggplot() +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend, ymin = 0, ymax = 8000, fill=col), alpha = 0.15,) +
scale_fill_manual(values=c("darkgrey", "lightblue", "blue")) +
geom_point(data=df_input, aes(x=V2, y=size, colour=col), size=8, alpha=0.5) +
geom_vline(xintercept = 2, colour="red") +
geom_vline(xintercept = 10, colour="green") +
theme_classic(base_size = 8) +
scale_colour_identity() +
geom_label_repel(data = df_input,
aes(x=V2, y=size, label=mod),
box.padding = 0.5,
point.padding = 0.5,
segment.color = 'black',
max.overlaps = Inf,
size=2,
segment.size=0.5,force=50) +
scale_x_continuous(trans='pseudo_log', expand = c(0, 0), breaks=c(0, 2, 10, 30, 70)) +
scale_y_continuous(trans='pseudo_log', expand = c(0, 0), breaks = c(0, 100, 300, 1000, 3000), limits = c(0, 8000)) +
labs(x = "Module preservation (Zsum)", y = "Module size", title="Module preservation vs. module size", subtitle = "exosome RNA modules in cell-free RNA dataset") +
theme(text=element_text(family="Arial"), plot.title = element_text(color="black", size=9, face="bold", hjust = 0.5), plot.subtitle = element_text(color="black", size=8, face="bold", hjust = 0.5), legend.position="none")
supp_fig4
ggsave(plot=supp_fig4, "./figures/supp_figures/supp_fig4.png", scale=1, units = "mm", width=180, height=100)
```
```{r}
sessionInfo()
```