Diff of /figures/Figure1.Rmd [000000] .. [9905a0]

Switch to unified view

a b/figures/Figure1.Rmd
1
---
2
title: "Figure 1"
3
author: Tobias Roider
4
date: "Last compiled on `r format(Sys.time(), '%d %B, %Y, %X')`"
5
output: 
6
  rmdformats::readthedown: 
7
  
8
editor_options: 
9
  chunk_output_type: console
10
---
11
12
```{r options, include=FALSE, warning = FALSE}
13
14
library(knitr)
15
opts_chunk$set(echo=TRUE, tidy=FALSE, include=TRUE, message=FALSE,
16
               dpi = 100, cache = FALSE, warning = FALSE)
17
opts_knit$set(root.dir = "../")
18
options(bitmapType = "cairo")
19
20
```
21
22
# Read data, functions and packages
23
```{r read data}
24
25
source("R/ReadPackages.R")
26
source("R/Functions.R")
27
source("R/ReadData.R")
28
source("R/ThemesColors.R")
29
source("R/Helpers.R")
30
31
```
32
33
# UMAP plot
34
```{r umap plot}
35
36
# Fine tuning for labels
37
median_umap <- df_comb %>% 
38
  group_by(IdentI) %>% 
39
  summarise(Median1=median(wnnUMAP_1), Median2=median(wnnUMAP_2)) %>% 
40
  mutate(Code=ifelse(IdentI %in% c(15, 18, 11, 6, 4), T, F)) %>% 
41
  mutate(Median2=ifelse(IdentI %in% 6, Median2+0.5, Median2)) %>% 
42
  mutate(Median2=ifelse(IdentI %in% 9, Median2+0.75, Median2)) %>% 
43
  mutate(Median1=ifelse(IdentI %in% 9, Median1-1, Median1)) %>% 
44
  mutate(Median2=ifelse(IdentI %in% 14, Median2+0.6, Median2)) %>% 
45
  mutate(Median1=ifelse(IdentI %in% 14, Median1-1.75, Median1)) %>% 
46
  mutate(IdentI=factor(IdentI, levels = cluster_order)) %>% 
47
  left_join(., data.frame(IdentI=factor(cluster_order), IdentI_label=seq(1:14)))
48
49
# Set origin for 'frameless' umap
50
ori <- c(-8.25,-8.5)
51
l <- 3
52
off <- 1
53
54
plot_umap <- df_comb %>% 
55
  ggplot(aes(x=wnnUMAP_1, y=wnnUMAP_2, fill=as.factor(IdentI)))+
56
  ggrastr::geom_point_rast(size=0.35, stroke=0, shape=21, raster.dpi = 200, alpha=0.75)+
57
  geom_text(data=median_umap, aes(x=Median1, color=Code, y=Median2, label=paste0("C", IdentI_label)), 
58
            size=2.5, fontface="bold")+
59
  scale_color_manual(values = c("black", "grey96"), guide="none")+
60
  scale_fill_manual(values = colors_umap_cl, limits=factor(cluster_order), labels=unlist(labels_cl))+
61
  scale_x_continuous(limits = c(ori[1],10), expand = c(0,0))+
62
  scale_y_continuous(limits = c(ori[2],10), expand = c(0,0))+
63
  annotation_custom(grob = linesGrob(gp=gpar(fill="black", lex=0.25), 
64
                                     arrow = arrow(ends = "last", type="closed", length=unit(0.15, "cm"))), 
65
                    xmin = ori[1]+off, xmax = ori[1]+off+l, ymin=ori[2]+off, ymax=ori[2]+off)+
66
  annotation_custom(grob = linesGrob(gp=gpar(fill="black", lex=0.25), 
67
                                     arrow = arrow(ends = "last", type="closed", length=unit(0.15, "cm"))), 
68
                    ymin = ori[2]+off, ymax = ori[2]+off+l, xmin=ori[1]+off, xmax=ori[1]+off)+
69
  annotation_custom(grob = textGrob(label = "wnnUMAP-1", gp = gpar(cex=0.6)), 
70
                    xmin = ori[1]+off+l/2, xmax = ori[1]+off+l/2, ymin=ori[2]+off/3, ymax=ori[2]+off/3)+
71
  annotation_custom(grob = textGrob(label = "wnnUMAP-2", gp = gpar(cex=0.6), rot = 90), 
72
                    xmin=ori[1]+off/3, xmax=ori[1]+off/3, ymin=ori[2]+off+l/2, ymax=ori[2]+off+l/2)+
73
    
74
  coord_fixed(clip = "off")+
75
  theme_void()+
76
  theme(legend.position = "none")
77
78
plot_umap
79
80
#ggsave(plot_umap, filename = "Figure1_p1.pdf", width = 8.25, height = 7.25, units = "cm")
81
82
```
83
84
# Gene expression
85
## Selected genes 
86
```{r genes}
87
88
genes_selected <- 
89
  c("MKI67",
90
    "CCR7", 
91
    "KLF2",
92
    "TCF7", 
93
    "TOX",
94
    "TOX2", 
95
    "ASCL2",
96
    "FOXP3", 
97
    "IKZF3",
98
    "GZMA", 
99
    "GZMK", 
100
    "CCL5", 
101
    "NKG7")
102
103
```
104
105
## Plot
106
```{r gene expression}
107
108
DefaultAssay(Combined_T) <- "integratedRNA"
109
110
perc_expr <- 
111
  FetchData(Combined_T, slot = "counts", vars = c("IdentI", paste0("rna_", genes_selected))) %>% 
112
  mutate(IdentI=as.factor(IdentI)) %>% 
113
  mutate_if(.predicate = is.numeric, .funs = ~ifelse(isZero(.), 1, 0)) %>% 
114
  pivot_longer(cols = 2:ncol(.), names_to = "Gene") %>% 
115
  group_by(IdentI, Gene) %>% 
116
  count(value) %>% 
117
  mutate(Prop=n/sum(n)) %>% 
118
  filter(value==0) %>% 
119
  select(-value, -n) %>% 
120
  mutate(Gene=substr(Gene, 5, nchar(.)))
121
122
DefaultAssay(Combined_T) <- "integratedRNA"
123
124
plot_genex <- 
125
  FetchData(Combined_T, slot = "data", vars = c("IdentI", paste0(genes_selected))) %>% 
126
  mutate(IdentI=factor(IdentI, levels = rev(cluster_order))) %>% 
127
  group_by(IdentI) %>% 
128
  summarise_all(mean) %>% 
129
  pivot_longer(cols = 2:ncol(.), names_to = "Gene") %>% 
130
  group_by(Gene) %>% 
131
  mutate(value=(value-min(value))/(max(value)-min(value))) %>% 
132
  left_join(., perc_expr) %>% 
133
  ggplot(aes(x=Gene, y=IdentI, size=100*Prop, fill=value))+
134
  geom_point(shape=21, stroke=0.1, color="grey45")+ 
135
  scale_size_continuous(range=c(0, 3), name="% pos. cells", limits=c(0, 100))+
136
  scale_fill_gradientn(name="Expression", colours = brewer.pal(5, "BuGn"), limits=c(0,1))+
137
  scale_y_discrete(limits=factor(rev(cluster_order)), labels=rev(unlist(labels_cl)))+
138
  scale_x_discrete(limits=genes_selected)+
139
  geom_hline(yintercept = c(1.5, 5.5, 9.5, 10.5, 13.5), linetype="solid", size=0.25, alpha=0.1)+
140
  ggtitle("RNA level")+
141
  coord_cartesian(clip = "off")+
142
  theme_bw()+
143
  mytheme_1+
144
  theme(axis.title = element_blank(),
145
        axis.text.x = element_text(angle = 45, hjust = 1, size=7),
146
        axis.text.y = element_blank(),
147
        axis.ticks.y = element_blank(),
148
        plot.margin = unit(c(0.25,0.35,0,2), "cm"))
149
150
lines <- c(1, 5, 9, 10, 13, 14)
151
152
for(i in 1:length(cluster_order)) {
153
  
154
  plot_genex <- plot_genex+
155
   annotation_custom(grob = rectGrob(gp = gpar(fill=colors_umap_cl[as.character(rev(cluster_order)[i])], lex=1, col="white")), 
156
                    ymin = seq(0.5, length(cluster_order)-0.5, 1)[i], 
157
                    ymax = seq(1.5, length(cluster_order)+0.5, 1)[i],
158
                    xmin = 0, xmax = -1.5)+
159
   annotation_custom(grob = textGrob(label = paste0("C", c(14:1)[i]), gp = gpar(cex=0.6, col=ifelse(i %in% c(6,7,11,14), "white", "black"))),
160
                    ymin = seq(0.5, length(cluster_order)-0.5, 1)[i], 
161
                    ymax = seq(1.5, length(cluster_order)+0.5, 1)[i],
162
                    xmin = 0, xmax = -1.5)
163
}
164
165
for(i in 1:length(lines)) {
166
  
167
  plot_genex <- plot_genex+
168
    annotation_custom(grob = textGrob(label = rev(labels_celltypes_expr)[[i]], rot = 0, hjust = 1, gp = gpar(cex=0.6)), 
169
                      ymin = c(0,lines)[i]+0.5,
170
                      ymax = c(lines)[i]+0.5,
171
                      xmin = -1.65, xmax = -1.65)+
172
    annotation_custom(grob = linesGrob(gp = gpar(col="white", lex=3)),
173
                      ymin = c(0,lines)[i]+0.5,
174
                      ymax = c(0,lines)[i]+0.5,
175
                      xmin = -0.01, xmax = -1.5)
176
}
177
178
plot_genex <- plot_genex+labs(tag = "B")+
179
 theme(plot.tag.position = c(-0.25,1))
180
181
```
182
183
# Protein expression
184
## Selected proteins
185
```{r proteins}
186
187
proteins_selected <- 
188
  c("CD4"="CD4", 
189
    "CD8a"="CD8a", 
190
    "CD45RA"="CD45RA", 
191
    "CD45RO"="CD45RO", 
192
    "CD95"="CD95", 
193
    "CD62L"="CD62L", 
194
    "CD127"="CD127", 
195
    "CD69"="CD69", 
196
    "CD38"="CD38", 
197
    "CD25"="CD25", 
198
    "ICOS"="CD278", 
199
    "CXCR5"="CD185", 
200
    "CD31"="CD31", 
201
    "KLRG1"="KLRG1", 
202
    "CD244"="CD244", 
203
    "PD1"="CD279", 
204
    "TIM3"="CD366"
205
    )
206
207
```
208
209
## Plot
210
```{r protein expression}
211
212
plot_protex <- 
213
  left_join(percentageADT, meanADT) %>% 
214
  filter(Epitope %in% proteins_selected) %>% 
215
  ggplot(aes(x=Epitope, y=IdentI, size=100*Prop, fill=Expression))+
216
  geom_point(shape=21, stroke=0.1, color="grey45")+ 
217
  geom_hline(yintercept = c(1.5, 5.5, 9.5, 10.5, 13.5), linetype="solid", size=0.25, alpha=0.1)+
218
  scale_size_continuous(range=c(0, 3), name="% pos. cells", limits=c(0, 100))+
219
  scale_fill_gradientn(name="Expression", colours = brewer.pal(5, "BuGn"), limits=c(0,1))+
220
  scale_y_discrete(limits=factor(rev(cluster_order)), labels=rev(unlist(labels_cl)))+
221
  scale_x_discrete(limits=proteins_selected, labels=names(proteins_selected))+
222
  ggtitle("Protein level")+
223
  coord_cartesian(clip = "off")+
224
  theme_bw()+
225
  mytheme_1+
226
  theme(axis.title = element_blank(),
227
        legend.position = "right",
228
        axis.text.x = element_text(angle = 45, hjust = 1, size=7),
229
        axis.text.y = element_blank(),
230
        axis.ticks.y = element_blank(),
231
        legend.text = element_text(size = 7, color="black"),
232
        legend.title = element_text(size = 7, color="black", vjust = 0.8),
233
        legend.key.height = unit(0.3, "cm"),
234
        legend.key.width = unit(0.3, "cm"),
235
        legend.box.spacing = unit(0.1, "cm"),
236
        plot.margin = unit(c(0.25,0,0,0.15), "cm"),
237
        plot.tag.position = c(-0.025,1))+
238
        labs(tag = "C")
239
240
```
241
242
# Assemble plot
243
```{r assemble plot, fig.height=4}
244
245
plot_genex+plot_protex+plot_layout(widths = c(1, 1.15))
246
247
#ggsave(filename = "Figure1_p2.pdf", width = 15, height = 7.8, units = "cm")
248
249
```
250
251
# TF activity
252
## Selected TFs
253
```{r tfs}
254
255
tfs_selected <- c("TCF7"="tfactivity_TCF7-E",  
256
                  "FOXP3"="tfactivity_FOXP3-E",
257
                  "ASCL2"="tfactivity_ASCL2-E", 
258
                  "KLF2"="tfactivity_KLF2-E")
259
260
```
261
262
## Plot
263
```{r tf activity, fig.height=4}
264
265
df_tfs <- 
266
  FetchData(Combined_T, vars = c("Barcode_full", unname(tfs_selected))) %>% 
267
  left_join(df_comb %>% select(IdentI, Barcode_full, CellType), .) %>% 
268
  pivot_longer(cols =4:ncol(.)) %>% 
269
  mutate(name=gsub(name, pattern = "tfactivity_|-E", replacement = "")) %>% 
270
  mutate(name=factor(name, levels = names(tfs_selected))) %>% 
271
  group_by(name, IdentI) %>% 
272
  summarise(Mean=mean(value, na.rm=T)) %>% 
273
  group_by(name) %>% 
274
  mutate(Mean=2*((Mean-min(Mean))/(max(Mean)-min(Mean)))-1) 
275
276
plot_tfact <- 
277
  ggplot(df_tfs, aes(y=as.character(IdentI), x=name, fill=Mean))+
278
  geom_tile()+ 
279
  scale_fill_gradientn(name="TF activity", colours = colorRampPalette(colors = c("#762a83", "#f7f7f7", "#1b7837"))(100))+
280
  geom_vline(xintercept = seq(1.5, 4.5, 1), color="white", size=0.25)+
281
  geom_hline(yintercept = seq(1.5, 14.5, 1), color="white", size=0.25)+
282
  scale_y_discrete(limits=rev(factor(cluster_order)), expand = c(0,0))+
283
  scale_x_discrete(expand = c(0,0))+
284
  ggtitle("TF activity")+
285
  coord_fixed(clip = "off")+
286
  theme_bw()+
287
  mytheme_1+
288
  theme(axis.title = element_blank(),
289
        axis.text.x = element_text(angle = 45, hjust = 1, size=7),
290
        axis.text.y = element_blank(),
291
        axis.ticks.y = element_blank(),
292
        panel.border = element_rect(size=0.25),
293
        plot.background = element_rect(fill = NA, color=NA),
294
        legend.position = "right",
295
        legend.text = element_text(size = 7, color="black"),
296
        legend.key.height = unit(0.3, "cm"),
297
        legend.key.width = unit(0.3, "cm"),
298
        legend.box.spacing = unit(0.1, "cm"),
299
        plot.margin = unit(c(0.25,0,0,0.65), "cm"),
300
        plot.tag.position = c(-0.2,1))+
301
        labs(tag = "D")
302
303
lines <- c(1, 5, 9, 10, 13, 14)
304
305
for(i in 1:length(cluster_order)) {
306
  
307
  plot_tfact <- plot_tfact+
308
   annotation_custom(grob = rectGrob(gp = gpar(fill=colors_umap_cl[as.character(rev(cluster_order)[i])], lex=1, col="white")), 
309
                    ymin = seq(0.5, length(cluster_order)-0.5, 1)[i], 
310
                    ymax = seq(1.5, length(cluster_order)+0.5, 1)[i],
311
                    xmin = 0, xmax = -1.5)+
312
   annotation_custom(grob = textGrob(label = paste0("C", c(14:1)[i]), gp = gpar(cex=0.6, col=ifelse(i %in% c(6,7,11,14), "white", "black"))),
313
                    ymin = seq(0.5, length(cluster_order)-0.5, 1)[i], 
314
                    ymax = seq(1.5, length(cluster_order)+0.5, 1)[i],
315
                    xmin = 0, xmax = -1.5)
316
}
317
318
for(i in 1:length(lines)) {
319
  
320
  plot_tfact <- plot_tfact+
321
    annotation_custom(grob = linesGrob(gp = gpar(col="white", lex=3)),
322
                      ymin = c(0,lines)[i]+0.5,
323
                      ymax = c(0,lines)[i]+0.5,
324
                      xmin = -0.01, xmax = -1.5)
325
}
326
327
plot_tfact
328
329
#ggsave(plot_tfact, filename = "Figure1_p3.pdf", width = 5, height = 7.35, units = "cm")
330
331
```
332
333
# Dendrogram
334
```{r dendrogram}
335
336
# Dendrogramm CITEseq
337
data <- data.frame(
338
  level1="_Tcells",
339
  level2=c("_'T'[Pr]",
340
           rep("_'T'[H]",3),  
341
           "_'T'[FH]", 
342
           rep("_'T'[REG]",4),  
343
           rep("_'T'[TOX]",4), 
344
           "_'T'[DN]"),
345
  level3=c("_'T'[Pr]", 
346
           "TH_'CD4'^'+'*' Naive'",
347
           "TH_'CM'[1]", 
348
           "TH_'CM'[2]", 
349
           "_'T'[FH]",  
350
           "TREG_'CM'[1]", 
351
           "TREG_'CM'[2]", 
352
           "TREG_'EM'[1]", 
353
           "TREG_'EM'[2]", 
354
           "TTOX_'CD8'^'+'*' Naive'",
355
           "TTOX_'EM'[1]",
356
           "TTOX_'EM'[2]",
357
           "TTOX_'EM'[3]",
358
           "_'T'[DN]")
359
)
360
361
dim <- 0.5
362
363
edges_level1_2 <- data %>% select(level1, level2) %>% unique %>% rename(from=level1, to=level2)
364
edges_level2_3 <- data %>% select(level2, level3) %>% unique %>% rename(from=level2, to=level3)
365
edge_list=rbind(edges_level1_2, edges_level2_3)
366
367
vert <- data.frame(
368
  name=unique(c(data$level1, data$level2, data$level3))) %>% 
369
  mutate(cluster=as.character(c(NA, 14, 'TH', 6, 'TREG', "TTOX", 19, 1, 2, 9, 8, 13, 15, 11, 12, 3, 16, 5))) %>% 
370
  mutate(label=strsplit(name, split = "_") %>% sapply(., "[[", 2)) %>% 
371
  mutate(alpha=c(0,1,1,1,1,1,dim,1,dim,dim,dim,dim,dim,dim,1,dim,dim,1))
372
373
mygraph_cite <- graph_from_data_frame( edge_list ,vertices = vert)
374
375
plot_dendrogramm <- ggraph(mygraph_cite, layout = 'tree', circular = FALSE)+ 
376
  geom_edge_diagonal(strength = 1.4, edge_width=0.25)+
377
  geom_node_label(aes(label=label, color=cluster), 
378
                  parse = T, nudge_y=-0.1, label.padding =  unit(units = "cm", 0.2),
379
                  size=2.75, label.size = 0, label.r = unit(units = "cm", 0))+
380
  scale_color_manual(values = colors_umap_cl)+
381
  theme_void()+
382
  theme(legend.position = "none")
383
384
plot_dendrogramm
385
386
#ggsave(plot_dendrogramm, filename = "Figure1_p4.pdf", device = "pdf", width = 17.5, height = 3.5, units = "cm")
387
388
```
389
390
# Session info
391
```{r session info}
392
393
sessionInfo()
394
395
```