/
18-plot-acute-ph.Rmd
356 lines (309 loc) · 8.8 KB
/
18-plot-acute-ph.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
---
title: "Acute PH (SFig. 2.4)"
output:
workflowr::wflow_html:
code_folding: hide
editor_options:
chunk_output_type: console
---
```{r chunk-setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
autodep = TRUE,
cache = TRUE,
message = FALSE,
warning = FALSE
)
```
```{r wall-time-start, cache=FALSE, include=FALSE}
# Track time spent on performing this analysis
start_time <- Sys.time()
```
## Introduction
Here we generate publication ready plots of the analysis of the acute PH mouse model.
## Libraries and sources
These libraries and sources are used for this analysis.
```{r libs-and-src, message=FALSE, warning=FALSE, cache=FALSE}
library(tidyverse)
library(tidylog)
library(here)
library(janitor)
library(AachenColorPalette)
library(cowplot)
library(lemon)
library(ggpubr)
library(patchwork)
source(here("code/utils-plots.R"))
```
Definition of global variables that are used throughout this analysis.
```{r analysis-specific-params, cache=FALSE}
# i/o
data_path <- "data/mouse-acute-ph"
output_path <- "output/mouse-acute-ph"
# graphical parameters
# fontsize
fz <- 7
# keys to annotate contrasts
key_mm <- readRDS(here("data/meta-chronic-vs-acute/contrast_annotation.rds"))
```
## Design
```{r design}
design <- ggdraw() +
draw_image(here(data_path, "exp-design.pdf"))
```
## Histology
```{r histology, include=FALSE}
histology <- ggdraw() +
draw_image(here(data_path, "histology.png"))
```
### Proliferation
```{r proliferation}
prolif_df <- read_delim(here(data_path, "prolif.txt"), delim = "\t") %>%
clean_names() %>%
rename(y = prolif, time = time_days) %>%
mutate(time = ordered(time))
prolif_summary <- prolif_df %>%
group_by(time) %>%
summarise(mean_se(y)) %>%
ungroup()
prolif <- prolif_df %>%
ggplot(aes(x = time, y = y)) +
geom_boxplot() +
# geom_errorbar(aes(ymin = ymin, ymax = ymax), width = 0.5) +
# geom_col() +
labs(x = "Time in days", y = "Proliferation in %\n(24h period)") +
my_theme(grid = "y", fsize = fz) +
stat_compare_means(
data = prolif_df, label = "p.signif",
ref.group = "0", hide.ns = T
)
prolif
```
### Lobular area
```{r lobular-area}
lob_df <- read_delim(here(data_path, "lobarea.txt"), delim = "\t") %>%
clean_names() %>%
rename(y = lobarea, time = time_days) %>%
mutate(time = ordered(time))
lob_summary <- lob_df %>%
group_by(time) %>%
summarise(mean_se(y)) %>%
ungroup()
lob <- lob_df %>%
ggplot(aes(x = time, y = y)) +
geom_boxplot() +
# geom_errorbar(aes(ymin = ymin, ymax = ymax), width = 0.5) +
# geom_col() +
labs(x = "Time in days", y = expression(paste("Lobule area in ", mm^2))) +
my_theme(grid = "y", fsize = fz) +
stat_compare_means(
data = lob_df, label = "p.signif",
ref.group = "0", hide.ns = TRUE
)
lob
```
## PCA
```{r pca}
pca_result <- readRDS(here(output_path, "pca_result.rds"))
keys <- key_mm %>%
filter(treatment == "Partial Hepatectomy" & class == "Acute") %>%
distinct(time = value, label = time_label2) %>%
drop_na() %>%
add_row(time = 0, label = "Control") %>%
mutate(
time = ordered(time),
label = fct_reorder(label, as.numeric(time))
)
pca_plot <- pca_result$coords %>%
mutate(time = ordered(round(as.numeric(as.character(time)) * 24, 0))) %>%
inner_join(keys, by = "time") %>%
ggplot(aes(x = PC1, y = PC2, color = label, label = label)) +
geom_point() +
labs(
x = paste0("PC1", " (", pca_result$var[1], "%)"),
y = paste0("PC2", " (", pca_result$var[2], "%)"),
color = "Time"
) +
my_theme(fsize = fz) +
theme(
legend.position = "top",
legend.box.margin = margin(0, 0, 0, 0)
) +
scale_color_manual(values = aachen_color(c(
"blue", "purple", "violet",
"bordeaux", "red", "orange",
"maygreen", "green", "turquoise",
"petrol", "magenta", "black"
))) +
guides(color = guide_legend(nrow = 2))
pca_plot
```
## Volcano plot
```{r volcano-plot}
df <- readRDS(here(output_path, "limma_result.rds")) %>%
filter(contrast_reference == "hepatec") %>%
inner_join(key_mm, by = "contrast") %>%
select(-contrast) %>%
rename(contrast = time_label2) %>%
mutate(contrast = fct_drop(contrast)) %>%
mutate(regulation = fct_recode(regulation,
Up = "up", Down = "down",
n.s. = "ns"
))
deg_count <- df %>%
add_count(contrast, regulation) %>%
filter(regulation != "n.s.") %>%
mutate(regulation = fct_drop(regulation)) %>%
mutate(
logFC = case_when(
regulation == "Up" ~ 0.75 * max(logFC),
regulation == "Down" ~ 0.75 * min(logFC)
),
pval = 0.4
) %>%
distinct(n, contrast, logFC, pval, regulation, value) %>%
complete(contrast, nesting(regulation, logFC, pval), fill = list(n = 0))
main_time = c(12,24,48)
# for main panel
volcano_main <- df %>%
filter(value %in% main_time) %>%
plot_volcano(nrow = 1) +
geom_text(
data = filter(deg_count, value %in% main_time),
aes(y = pval, label = n), size = fz / (14 / 5),
hjust = "inward", vjust = "inward",
show.legend = F
) +
theme(
legend.position = "top",
legend.box.margin = margin(-10, 0, -10, 0)
) +
labs(color = "Regulation") +
my_theme(grid = "y", fsize = fz)
# for supp panel
volcano_supp <- df %>%
filter(!value %in% main_time) %>%
plot_volcano(ncol = 1) +
geom_text(
data = filter(deg_count, !value %in% main_time),
aes(y = pval, label = n), size = fz / (14 / 5),
show.legend = F
) +
theme(
legend.position = "top",
legend.box.margin = margin(-10, 0, -10, 0)
) +
labs(color = "Regulation") +
my_theme(grid = "y", fsize = fz)
volcano_main
volcano_supp
```
## Top DEGs
```{r top-degs}
df <- readRDS(here(output_path, "limma_result.rds")) %>%
filter(contrast_reference == "hepatec") %>%
inner_join(key_mm) %>%
select(-class) %>%
rename(class = time_label2)
top_genes_df <- df %>%
group_by(class, sign(logFC)) %>%
slice_max(order_by = abs(statistic), n = 10, with_ties = F) %>%
ungroup() %>%
nest(data = -c(class, value))
plots <- top_genes_df %>%
mutate(p = pmap(., .f = plot_top_genes, fontsize = fz))
main_time = c(12,24,48)
# for main panel
top_genes_main <- plots %>%
filter(value %in% main_time) %>%
pull(p) %>%
wrap_plots() +
plot_layout(nrow = 1)
# for supp panel
top_genes_supp <- plots %>%
filter(!value %in% main_time) %>%
pull(p) %>%
wrap_plots() +
plot_layout(ncol = 1)
top_genes_main
top_genes_supp
```
## Time series cluster
```{r ts-cluster}
stem_res <- readRDS(here(output_path, "stem_result.rds")) %>%
filter(key == "hepatec") %>%
filter(p <= 0.05) %>%
mutate(profile = fct_reorder(str_c(
"STEM ID: ",
as.character(profile)
), p)) %>%
filter(!time %in% c(168, 336, 672, 2016))
# extract meta data of profiles
profile_anno <- stem_res %>%
group_by(key, profile, p) %>%
mutate(y = 1.2 * abs(max(value))) %>%
ungroup() %>%
mutate(max_time = max(time)) %>%
distinct(key, profile, p, size, y, max_time) %>%
mutate(label = str_c(size, " ", "genes"))
ts_cluster <- stem_res %>%
plot_stem_profiles(model_profile = F, nrow = 1) +
labs(x = "Time in Hours") +
geom_text(
data = profile_anno, aes(x = 0, y = y, label = label),
inherit.aes = F, size = fz / (14 / 5), hjust = "inward"
) +
my_theme(grid = "no", fsize = fz) +
scale_x_continuous(
breaks = unique(stem_res$time),
labels = c("", 1,"", "",24,"","", 96)
)
ts_cluster
```
## Collage
### Supplementary Figure 2.4
```{r s-fig-2-2, fig.width=7.87, fig.height=11.69}
sfig2_4 <- (design + histology) /
(((prolif / lob) | pca_plot) + plot_layout(widths = c(1, 3))) /
(volcano_main / top_genes_main) /
ts_cluster +
plot_layout(height = c(1.5, 2, 1.75, 0.75)) +
plot_annotation(tag_levels = list(c(
"A", "B", "C","","D", "E", "F", "", "", "", "", "", "G"
))) &
theme(
plot.tag = element_text(size = fz + 3, face = "bold"),
legend.key.height = unit(11.5, "pt"),
legend.key.width = unit(12.5, "pt")
)
sfig2_4
ggsave(here("figures/Supplementary Figure 2.4.pdf"), sfig2_4,
width = 21, height = 29.7, units = c("cm")
)
ggsave(here("figures/Supplementary Figure 2.4.png"), sfig2_4,
width = 21, height = 29.7, units = c("cm")
)
```
### Supplementary Figure 2.5
```{r s-fig-2-3, fig.width=7.87, fig.height=11.69}
sfig2_5 <- (volcano_supp | top_genes_supp) +
plot_annotation(tag_levels = list(c("A", "B"))) &
theme(
plot.tag = element_text(size = fz + 3, face = "bold"),
legend.key.height = unit(11.5, "pt"),
legend.key.width = unit(12.5, "pt")
)
sfig2_5
ggsave(here("figures/Supplementary Figure 2.5.pdf"), sfig2_5,
width = 21, height = 29.7, units = c("cm")
)
ggsave(here("figures/Supplementary Figure 2.5.png"), sfig2_5,
width = 21, height = 29.7, units = c("cm")
)
```
```{r wall-time-end, cache=FALSE, include=FALSE}
duration <- abs(as.numeric(difftime(Sys.time(), start_time, units = "secs")))
t = print(sprintf("%02d:%02d", duration %% 3600 %/% 60, duration %% 60 %/% 1))
```
Time spend to execute this analysis: `r t` minutes.