This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_RNAseqVis_Scatter.Rmd
executable file
·362 lines (304 loc) · 12.2 KB
/
5_RNAseqVis_Scatter.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
357
358
359
360
361
362
---
title: "Visualisation of DESeq2 results with scatter plots"
description: "DEG analysis based on DESeq2 and GSEA"
principal investigator: "Joaquín de Navascués"
researcher: "Joaquín de Navascués"
output:
html_document:
toc: true
toc_float: true
code_folding: 'hide'
theme: readable
df_print: paged
---
```{r set-publication-theme, echo=FALSE, cache=FALSE}
ggplot2::theme_set(ggpubr::theme_pubr(base_size=10))
```
```{r setup, echo = FALSE, cache = FALSE}
knitr::opts_chunk$set(dev = 'png',
fig.align = 'center', fig.height = 5, fig.width = 8.5,
pdf.options(encoding = "ISOLatin9.enc"),
fig.path='scatter/figures/', warning=FALSE, message=FALSE)
```
**Libraries & external code:**
```{r load_libraries, warning=FALSE, echo=FALSE}
if (!require("librarian")) install.packages("librarian")
# data
librarian::shelf(
# data manip.
readxl, writexl, dplyr, tidyr, purrr, stringr, santoku, calibrate,
# plotting
cetcolor, ggplots2, ggpubr, ggthemes, ggtext, ggrepel,
# convenience
here)
setwd(here::here()) # to distinguish from dplyr::here()
if(!exists("extract_regulated_sets2", mode="function")) source("utils.R")
```
**Path to definitive images (outside repo):**
```{r define_dir2figs}
figdir <- paste0(c(head(str_split(getwd(),'/')[[1]],-1),
paste0(tail(str_split(getwd(),'/')[[1]],1), '_figures')),
collapse='/')
dir.create(figdir, showWarnings = FALSE)
```
# RNAseq results visualisation with scatter plots
## 1 Getting ready
### 1.1 Load the DGE data
This gets us the DGE data from `DESeq2`, identified by FlyBase/Ensembl ID and gene symbol:
```{r load_DEG_data}
# experimental design and labels
targets <- readRDS('output/targets.RDS')
# DEG data
DaKD_deg <- readRDS('output/Control_vs_DaKD.RDS')
DaOE_deg <- readRDS('output/Control_vs_DaOE.RDS')
DaDaOE_deg <- readRDS('output/Control_vs_DaDaOE.RDS')
ScOE_deg <- readRDS('output/Control_vs_ScOE.RDS')
head(ScOE_deg, 1)
```
As discussed previously, we do not really need TPM values here, as the `baseMean` from the `DESeq2` normalisation does the work just as well and is more 'internally consistent'.
Now make a data frame with the status of each gene (up/down/non-regulated) for each condition:
```{r extract_regulated_sets2, warning=FALSE}
# classify genes as up-, down- or non-regulated by padj and fold change threshold
list_of_degs <- list('kd'=DaKD_deg, 'da'=DaOE_deg,
'dada'=DaDaOE_deg, 'sc'=ScOE_deg)
names_degs <- list('DaKD','DaOE','DaDaOE','ScOE')
cols.oi <- c('log2FoldChange', 'padj', 'baseMean',
'gene_symbol', 'ensemblGeneID')
fc_thresh <- 1.5
regs <- extract_regulated_sets2(list_of_degs, names_degs, fc_thresh=fc_thresh, cols=cols.oi)
# attach the results to the DEG data frame for each condition
DaKD_deg$reg <- regs$DaKD
DaOE_deg$reg <- regs$DaOE
DaDaOE_deg$reg <- regs$DaDaOE
ScOE_deg$reg <- regs$ScOE
```
### 1.2 Select genes of interest
To create a list of genes of interest to track their individual expression in the different conditions, I am going to use a list of `genes_of_interest`, manually curated by JdN from the literature (including the Fly Cell Atlas paper) for a simplified cell type classification (ISC, EB, EE, EC, focused on the posterior midgut) and the markers defined by the Fly Cell Atlas consortium. Then I will remove redundancy and simplify the cell type classification.
- First make our list.
```{r load_GOI, message=FALSE}
genes_of_interest <- read_excel('resources/genes_of_interest.xlsx', sheet='core') %>%
dplyr::select(gene_symbol, bonafide_celltype) %>%
filter(bonafide_celltype != 'NA') %>%
rename(celltype = bonafide_celltype) %>%
group_by(celltype) %>%
summarise(gene_symbol=paste(gene_symbol, collapse=', '))
```
- Then the FCA markers.
```{r loadFCA, message=FALSE}
markers <- read_xlsx(file.path(getwd(), 'resources', 'science.abk2432_table s2.xlsx')) %>%
# get only the gut epithelium/muscle cell types
filter(Tissue=='gut' | `Annotation...1`=='enteroendocrine cell') %>%
# remove a hybrid/transitional cell type
filter(!str_detect(`Annotation...1`, 'differentiating')) %>%
# remove muscle/artefact cells
filter(!str_detect(`Broad annotation`, 'muscle|artefact')) %>%
# get just the columns with marker names
dplyr::select(contains(c('Annotation...1', 'Marker'))) %>%
# join all markers in a new column
unite(gene_symbol, contains('Markers'), sep = ', ')
names(markers)[[1]] <- 'celltype'
```
- An merge the two:
```{r merge_markers, message=FALSE}
missd.spelld <- c(`wntD, `='', `LManIV, `='', `CG31269, `='', `CG43208, `='', `orcokinin B, `='',
AstB='Mip', poxn='Poxn')
markers <- rbind(genes_of_interest, markers) %>%
# merge same cell type markers
group_by(celltype) %>%
summarise(gene_symbol=paste(gene_symbol, collapse=', ')) %>%
# correct difference in synonym/capitalisation with DEG data...
# ... while all gene symbols are in one string
mutate(gene_symbol = str_replace_all(gene_symbol, missd.spelld)) %>%
# make each gene name an independent string
rowwise() %>% mutate(markers = list(unique(str_split(gene_symbol, ', ')[[1]])))
head(markers)
```
- Filter out the genes that do not have unique mapping to a cell type.
```{r filter_markers, message=FALSE}
# filter by exclusivity, but keeping what is common to all enterocytes
## first identify all EC markers
ECmarkers <- markers %>%
filter(str_detect(celltype, 'enterocyte')) %>%
dplyr::select(markers) %>%
unlist(use.names = FALSE) %>%
unique() %>% as.list()
## then non-EC cell markers, with all their repetitions!!
nonECmarkers <- markers %>%
filter(!str_detect(celltype, 'enterocyte')) %>%
dplyr::select(markers) %>%
unlist(use.names = FALSE) %>% as.list()
## get all markers with one occurrence (≠unique!)
repmarkers <- unlist(c(ECmarkers, nonECmarkers))
reps <- rle(sort(repmarkers))
xmarkers <- reps$values[reps$lengths==1]
## apply criterion of exclusivity
exclude <- function(x) x[x %in% xmarkers]
markers <- markers %>%
mutate(exclusive = list(exclude(markers)))
pmgcelltypes <- c('intestinal stem cell', 'enteroblast', 'enteroendocrine cell', 'enterocyte of posterior adult midgut epithelium')
pmg.markers <- markers %>%
filter(celltype %in% pmgcelltypes) %>%
dplyr::select(c(1,4)) %>%
rename(xmarkers = exclusive)
```
- Add cell type colours HEX codes
```{r colour_markers}
write_xlsx(unnest_longer(pmg.markers, xmarkers) %>%
rename(gene_symbol = xmarkers),
path = 'output/preliminary_Table S4.xlsx')
cellcolours <- c('EB'='#56B2E9', 'EC'='#009E73', 'EE'='#CC79A7', 'ISC'='#D55E00')
pmg.markers$cellcolour <- cellcolours
```
## 2 MA plots using `ggpubr::ggmaplot` wrappers
MA plot for *daughterless* knockdown:
```{r ggmaplot2_da_knockdown}
repulsion <- list(box.padding = 0.1,
point.padding = 0.8,
nudge_x = 3,
nudge_y = 2,
force = 1,
force_pull = 0,
seed.up = 42,
seed.dn = 50,
xlims.up = c(14, NA),
ylims.up = c(5, NA),
xlims.dn = c(18, NA),
ylims.dn = c(NA, -1))
ggmaplot2(deg = DaKD_deg,
fc_thresh = fc_thresh,
markers = pmg.markers,
md_label = '*esg > da^RNAi^*',
repulsion = repulsion)
```
Now with cell type-specific colours:
```{r ggmaplot3_da_kd}
repulsion <- list(box.padding = 0.08,
point.padding = 0.1,
nudge_x = 0,
nudge_y = 0,
force = 1,
force_pull = -0.004,
seed.up = 42,
seed.dn = 5,
xlims.up = c(12, NA),
ylims.up = c(5.5, NA),
xlims.dn = c(16, NA),
ylims.dn = c(NA, -1))
ggmaplot3(deg = DaKD_deg,
fc_thresh = fc_thresh,
markers = pmg.markers,
md_label = '*esg > da^RNAi^*',
repulsion = repulsion)
suppressMessages(ggsave('MA_daKD.pdf', plot = last_plot(), device = 'pdf',
path = figdir, dpi = 300))
```
```{r ggmaplot3_da_overexpression}
repulsion <- list(box.padding = 0.1,
point.padding = 0.1,
force = 1.5,
force_pull = -0.003,
nudge_x.up = 0,
nudge_y.up = 0,
nudge_x.dn = 0,
nudge_y.dn = 0,
seed.up = 42,
seed.dn = 5,
xlims.up = c(12, NA),
ylims.up = c(5, NA),
xlims.dn = c(16, NA),
ylims.dn = c(NA, -1))
ggmaplot3(deg = DaOE_deg,
fc_thresh = fc_thresh,
markers = pmg.markers,
md_label = '*esg > da*',
repulsion = repulsion)
suppressMessages(ggsave('MA_daOE.pdf', plot = last_plot(), device = 'pdf',
path = figdir, dpi = 300))
```
To the Daughterless homodimer overexpression:
```{r ggmaplot2_da:da_overexpression}
repulsion <- list(box.padding = 0.01,
point.padding = 0.1,
nudge_x = 0,
nudge_y = 0,
force = 1,
force_pull = -0.004,
seed.up = 42,
seed.dn = 5,
xlims.up = c(16, NA),
ylims.up = c(3, NA),
xlims.dn = c(16, NA),
ylims.dn = c(NA, -2))
ggmaplot3(deg = DaDaOE_deg,
fc_thresh = fc_thresh,
markers = pmg.markers,
md_label = '*esg > da:da*',
repulsion = repulsion)
suppressMessages(ggsave('MA_dadaOE.pdf', plot = last_plot(), device = 'pdf',
path = figdir, dpi = 300))
```
And, finally, to the *scute* overexpression:
```{r ggmaplot2_sc_overexpression}
repulsion <- list(box.padding = 0.01,
point.padding = 0.1,
nudge_x = 0,
nudge_y = 0,
force = 0.7,
force_pull = -0.003,
seed.up = 42,
seed.dn = 5,
xlims.up = c(8, NA),
ylims.up = c(7, NA),
xlims.dn = c(8, NA),
ylims.dn = c(NA, -6))
ggmaplot3(deg = ScOE_deg,
fc_thresh = 2,
markers = pmg.markers,
md_label = '*esg > scute*',
repulsion = repulsion)
suppressMessages(ggsave('MA_ScOE.pdf', plot = last_plot(), device = 'pdf',
path = figdir, dpi = 300))
```
## 3 Heatmap of individual genes
```{r}
tidy.markers <- pmg.markers %>% unnest_longer(xmarkers) %>%
rename(gene_symbol = xmarkers)
DaKD_deg$condition <- '*da^RNAi^*'
DaOE_deg$condition <- '*da*'
DaDaOE_deg$condition <- '*da:da*'
ScOE_deg$condition <- '*scute*'
genehm.df <- bind_rows(ScOE_deg, DaDaOE_deg, DaOE_deg, DaKD_deg) %>%
dplyr::select(ensemblGeneID, gene_symbol, log2FoldChange, padj, condition) %>%
rename(p.adjust = padj) %>%
filter(gene_symbol %in% tidy.markers$gene_symbol) %>%
merge(., tidy.markers, by = 'gene_symbol') %>%
mutate(condition = factor(condition, levels=c("*scute*", "*da:da*", "*da*", "*da^RNAi^*")))
```
```{r, fig.width=20}
p <- layer.heatmaph(genehm.df, arr='celltype')
p + geom_hline(aes(yintercept=3.5), linewidth = 0.5) +
theme(plot.margin = margin(r = 25))
```
```{r, fig.width=20}
p <- layer.heatmaph(genehm.df, cluster=TRUE)
p + geom_hline(aes(yintercept=3.5), linewidth = 0.5) +
theme(plot.margin = margin(r = 25))
```
```{r, fig.height = 20}
p <- layer.heatmapv(genehm.df, cluster=TRUE)
p + geom_vline(aes(xintercept=3.5), linewidth = 0.5)
suppressMessages(ggsave('marker_heatmap.pdf', plot = last_plot(), device = 'pdf',
path = figdir, dpi = 300))
```
```{r}
Espl.df <- bind_rows(ScOE_deg, DaDaOE_deg, DaOE_deg, DaKD_deg) %>%
dplyr::select(ensemblGeneID, gene_symbol, log2FoldChange, padj, condition) %>%
rename(p.adjust = padj) %>%
filter(grepl("^E\\(spl\\)", gene_symbol)) %>%
mutate(condition = factor(condition, levels=c("*scute*", "*da:da*", "*da*", "*da^RNAi^*"))) %>%
mutate(cellcolour = "#000000")
p <- layer.heatmapv(Espl.df, cluster=TRUE)
p + geom_vline(aes(xintercept=3.5), linewidth = 0.5)
suppressMessages(ggsave('Esplit_heatmap.pdf', plot = last_plot(), device = 'pdf',
path = figdir, dpi = 300))
```