-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_AssembleFigures.qmd
executable file
·204 lines (143 loc) · 5.88 KB
/
11_AssembleFigures.qmd
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
---
title: "Create figures for manuscript"
author: Jamie Soul
format:
html:
self-contained: true
theme: litera
toc: true
editor: visual
code-block-bg: true
code-block-border-left: "#31BAE9"
---
# Combined saved figures for publication
## Load libraries
```{r}
#| output: false
library(ggplot2)
library(patchwork)
library(ComplexHeatmap)
library(cowplot)
library(grid)
library(gridExtra)
library(GeomxTools)
library(GeoMxWorkflows)
library(ggsci)
library(tidyverse)
```
## Figure 2
### Load the saved figures
```{r}
pca <- readRDS("results/Fig2A_PCA.RDS")
pca2 <- readRDS("results/Fig2B_PCA.RDS")
#Alter the text labels in the legend
pca <- pca + scale_color_npg(labels = c("CD45" = expression(CD45^"+"),"CD56"=expression(CD56^"+"),"PANCK"=expression(PanCK^"+")))
pca2 <- pca2 + scale_color_npg(labels = c("CD45" = expression(CD45^"+"),"CD56"=expression(CD56^"+"),"PANCK"=expression(PanCK^"+")))
heatmap <- readRDS("results/Fig2B_Heatmap.RDS")
heatmap <- grid.grabExpr(draw(heatmap))
deconv <- readRDS("results/Fig2C_spatialDeconBroadHeatmap.RDS")
deconv <- grid.grabExpr(draw(deconv))
i <- grep("text",names(deconv$children))
for (j in i) {
deconv$children[[j]]$gp$fontsize <- 14
}
```
### Assemble figure 2
```{r}
fig2 <- (pca + pca2)/deconv/ heatmap +
plot_layout(widths = c(1,1,2),heights = c(1,0.9,2)) +
plot_annotation(tag_levels = 'A') &
theme_cowplot() &
theme(plot.tag = element_text(face = 'bold',size = 18))
save_plot(filename ="figures/Fig2.pdf",fig2,base_height = 11,base_width = 8, bg="white")
```
## Figure 3
### Load the saved figures
```{r}
heatmaps <- readRDS("results/Fig3B_Heatmap.RDS")
target_spatialData <- readRDS("results/normalisedSpatialData.RDS")
regions <- unique(pData(target_spatialData)$Region)[1:6]
regions <- gsub("Control ","",regions)
names(regions) <- c("Luminal epithelium",
"Sub-luminal stromal CD45+",
"Sub-luminal stroma",
"Glandular epithelium",
"Functionalis stromal CD56+",
"Functionalis stroma")
heatmaps <- mapply(function(heatmap,title){
heatmap@column_title <- title
heatmap
},heatmaps,names(regions))
names(heatmaps) <- names(regions)
heatmaps <- heatmaps[c("Luminal epithelium",
"Glandular epithelium",
"Sub-luminal stroma",
"Functionalis stroma",
"Sub-luminal stromal CD45+",
"Functionalis stromal CD56+")]
```
```{r}
heatmaps <- lapply(heatmaps,function(x) grid.grabExpr(draw(x)) )
# Arrange the heatmaps in a grid layout
g <- grid.arrange(
arrangeGrob(heatmaps$`Luminal epithelium`, top = textGrob("A", x = unit(0, "npc"), y = unit(1, "npc"), just = c("left", "top"), gp = gpar(fontsize = 30, fontface = "bold"))),
arrangeGrob(heatmaps$`Glandular epithelium`, top = textGrob("B", x = unit(0, "npc"), y = unit(1, "npc"), just = c("left", "top"), gp = gpar(fontsize = 30, fontface = "bold"))),
arrangeGrob(heatmaps$`Sub-luminal stroma`, top = textGrob("C", x = unit(0, "npc"), y = unit(1, "npc"), just = c("left", "top"), gp = gpar(fontsize = 30, fontface = "bold"))),
arrangeGrob(heatmaps$`Functionalis stroma`, top = textGrob("D", x = unit(0, "npc"), y = unit(1, "npc"), just = c("left", "top"), gp = gpar(fontsize = 30, fontface = "bold"))),
arrangeGrob(heatmaps$`Sub-luminal stromal CD45+`, top = textGrob("E", x = unit(0, "npc"), y = unit(1, "npc"), just = c("left", "top"), gp = gpar(fontsize = 30, fontface = "bold"))),
arrangeGrob(heatmaps$`Functionalis stromal CD56+`, top = textGrob("F", x = unit(0, "npc"), y = unit(1, "npc"), just = c("left", "top"), gp = gpar(fontsize = 30, fontface = "bold"))),
ncol = 2
)
save_plot("figures/Fig3.pdf",g,base_height = 16,base_width = 12)
```
### Figure 3 VolcanoPlots
```{r}
volcanoplots <- readRDS("results/diseaseVolcanoPlots.RDS")
volcanoplots <- volcanoplots[c(5,2,6,3,4,1)]
names(volcanoplots) <- c("Luminal epithelium","Glandular epithelium","Sub-luminal stroma","Functionalis stroma","Sub-luminal stromal CD45+","Functionalis stromal CD56+")
volcanoplots <- mapply(function(x,y){
x <- x + ggtitle(y)
x
},volcanoplots,names(volcanoplots),SIMPLIFY = FALSE)
volcanoplots <- volcanoplots %>%
plot_grid(plotlist = . ,ncol = 2,labels = "AUTO",label_size = 20)
save_plot(plot = volcanoplots, filename = "figures/Fig3.pdf",base_height = 16,base_width = 10,bg="white")
```
## Figure 4
### Load the saved figures
```{r}
enrichmentPlots <- readRDS("results/enrichmentPlots.RDS")
goPlot <- enrichmentPlots[[1]] + scale_x_discrete(labels=c("Functionalis stromal CD56+",
"Glandular epithelium",
"Functionalis stroma",
"Sub-luminal stromal CD45+",
"Luminal epithelium",
"Sub-luminal stroma"))
keggPlot <- enrichmentPlots[[2]] + scale_x_discrete(labels=c("Functionalis stromal CD56+",
"Glandular epithelium",
"Functionalis stroma",
"Sub-luminal stromal CD45+",
"Luminal epithelium",
"Sub-luminal stroma"))
```
### Assemble figure 4
```{r}
fig4 <- (goPlot + keggPlot) +
plot_annotation(tag_levels = 'A') &
theme(plot.tag = element_text(face = 'bold',size = 24))
save_plot(filename ="figures/Fig4.pdf",fig4,base_height = 9,base_width = 16, bg="white")
```
### Supplementary Figures
```{r}
file.copy("figures/Normalisation/antibodyValues.pdf","figures/SupplementryFigure1.pdf")
```
### Supplementary tables
```{r}
file.copy("results/diffExpLME4_betweenCells.xlsx","tables/SupplementryTable1.xlsx")
file.copy("results/cellTypeGeneOntology.xlsx","tables/SupplementryTable2.xlsx")
file.copy("results/diffExpLME4_Q3.xlsx","tables/SupplementryTable3.xlsx")
file.copy("results/diseasePathways.xlsx","tables/SupplementryTable5.xlsx")
file.copy("results/diseaseGeneOntology.xlsx","tables/SupplementryTable6.xlsx")
file.copy("results/signatureSearch_Touchstone.xlsx","tables/SupplementryTable7.xlsx")
file.copy("results/drugTargetEnrichment.xlsx","tables/SupplementryTable8.xlsx")
```