-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComp_Sensitivity.Rmd
executable file
·392 lines (300 loc) · 14.2 KB
/
Comp_Sensitivity.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
---
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>",fig.height = 8,
fig.width = 10)
```
## Purpose:
MAQC Comparison - Sensitivity plots
### 1. Load the following packages:
```{r packages}
library(tidyverse)
library(ggsignif)
library(ggrepel)
library(edgeR)
library(genefilter)
library(grid)
library(gridExtra)
library(ggsci)
library(UpSetR)
library(cowplot)
library(biomaRt)
```
### 2. Load following functions:
```{r functions}
### all necessary custom functions are in the following script
source(paste0(here::here(),"/0_Scripts/custom_functions.R"))
theme_pub <- theme_bw() + theme(
plot.title = element_text(hjust = 0.5, size=18, face="bold"),
axis.text = element_text(colour="black", size=14),
axis.title=element_text(size=16,face="bold"),
legend.text=element_text(size=14),
legend.position="right",
axis.line.x = element_line(colour = "black"),
axis.line.y = element_line(colour = "black"),
strip.background=element_blank(),
strip.text=element_text(size=16))
theme_set(theme_pub)
#prevent scientific notation
options(scipen=999)
fig_path <- paste0(here::here(),"/2_power_simulation/")
```
```{r}
gtype_human <- data.frame( species="human", getbiotype("hsapiens_gene_ensembl",species="human"))
```
## Sensitivity
### 3. Load Data
```{r load_counts}
counts_prime <- readRDS(paste0(fig_path,"prime-seq.dgecounts.rds"))
counts_tru <- readRDS(paste0(fig_path,"SEQC_PE.dgecounts.rds"))
inf <- read.csv(paste0(fig_path,"/sample_info.csv"), header = T, stringsAsFactors = F)
# subset only coding genes
coding_genes_prime<-rownames(counts_prime$umicount$inex$all)[!(rownames(counts_prime$umicount$inex$all)%in%gtype_human$Gencode)]
coding_genes_prime_reads<-rownames(counts_prime$readcount$inex$all)[!(rownames(counts_prime$readcount$inex$all)%in%gtype_human$Gencode)]
coding_genes_tru<-rownames(counts_tru$readcount$inex$all)[!(rownames(counts_tru$readcount$inex$all)%in%gtype_human$Gencode)]
# include mRNA, ERCCs, lncRNAs, mito, rRNA
genes_prime<-rownames(counts_prime$umicount$inex$all)
genes_prime_reads<-rownames(counts_prime$readcount$inex$all)
genes_tru<-rownames(counts_tru$readcount$inex$all)
# coding
inex_ds_df_prime <-collapse_downsampled_counts(zumismat = counts_prime,type="inex",frac.samples = 0.25,genes=coding_genes_prime,umi = T)
inex_ds_df_prime_reads <-collapse_downsampled_counts(zumismat = counts_prime,type="inex",frac.samples = 0.25,genes=coding_genes_prime_reads,umi = F)
inex_ds_df_tru <-collapse_downsampled_counts(zumismat = counts_tru,type="inex",frac.samples = 0.25,genes=coding_genes_tru, umi = F)
# include non-coding
inex_ds_df_nc_prime <-collapse_downsampled_counts(zumismat = counts_prime,type="inex",frac.samples = 0.25,genes=genes_prime,umi = T)
inex_ds_df_nc_prime_reads <-collapse_downsampled_counts(zumismat = counts_prime,type="inex",frac.samples = 0.25,genes=genes_prime_reads,umi = F)
inex_ds_df_nc_tru <-collapse_downsampled_counts(zumismat = counts_tru,type="inex",frac.samples = 0.25,genes=genes_tru, umi = F)
# plot mean gene expression
plot_mean_gene_prime <- mean_gene_exp(data = counts_prime, genes = coding_genes_prime_reads, UMI = F)
plot_mean_gene_prime
plot_mean_gene_tru <- mean_gene_exp(data = counts_tru, genes = coding_genes_tru, UMI = F)
plot_mean_gene_tru
```
### 4. Number of inex umis/reads and genes per sample per downsampling
```{r sensitivity_exon}
# add data column
inex_ds_df_prime$data <- "prime-seq (UMIs)"
inex_ds_df_prime_reads$data <- "prime-seq"
inex_ds_df_tru$data <- "TruSeq"
inex_ds_df_nc_prime$data <- "prime-seq (UMIs)"
inex_ds_df_nc_prime_reads$data <- "prime-seq"
inex_ds_df_nc_tru$data <- "TruSeq"
# add method column
inex_ds_df_prime$method <- "prime-seq"
inex_ds_df_prime_reads$method <- "prime-seq"
inex_ds_df_tru$method <- "TruSeq"
inex_ds_df_nc_prime$method <- "prime-seq"
inex_ds_df_nc_prime_reads$method <- "prime-seq"
inex_ds_df_nc_tru$method <- "TruSeq"
# add UMI column
inex_ds_df_prime$readorumi <- "UMIs"
inex_ds_df_prime_reads$readorumi <- "reads"
inex_ds_df_tru$readorumi <- "reads"
inex_ds_df_nc_prime$readorumi <- "UMIs"
inex_ds_df_nc_prime_reads$readorumi <- "reads"
inex_ds_df_nc_tru$readorumi <- "reads"
# join df
ds_df <- bind_rows(inex_ds_df_prime, inex_ds_df_prime_reads, inex_ds_df_tru)
ds_df_nc <- bind_rows(inex_ds_df_nc_prime, inex_ds_df_nc_prime_reads, inex_ds_df_nc_tru)
# main plot -- only coding
a1 <- ggplot(data = ds_df, aes(x= depth, y = UMIs, color = method, group = data))+
geom_smooth(method = "loess", se = F, aes(linetype=readorumi))+
geom_point()+
xlab("Sequencing Reads (mil.)")+
ylab("Mapped Reads / UMIs (mil.)")+
ylim(0,30000000)+
scale_x_continuous(breaks = c(10000000,20000000,30000000), labels = c(10,20,30))+
scale_y_continuous(breaks = c(10000000,20000000,30000000), labels = c(10,20,30))+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)+
theme(legend.position="none")
b1 <- ggplot(data = ds_df, aes(x= depth, y = Genes, color = method, group = data))+
geom_smooth(method = "gam", se = F, aes(linetype=readorumi))+
geom_point()+
xlab("Sequencing Reads (mil.)")+
ylab("Genes")+
scale_x_continuous(breaks = c(10000000,20000000,30000000), labels = c(10,20,30))+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)+
theme(legend.position="none")
#calculate p values
ds_df_5 <- ds_df[ds_df$depth == 5000000 & ds_df$readorumi == "reads",]
anno_5 <- t.test(ds_df_5[ds_df_5$method == "prime-seq", "Genes"],
ds_df_5[ds_df_5$method == "TruSeq", "Genes"])$p.value
ds_df_10 <- ds_df[ds_df$depth == 10000000 & ds_df$readorumi == "reads",]
anno_10 <- t.test(ds_df_10[ds_df_10$method == "prime-seq", "Genes"],
ds_df_10[ds_df_10$method == "TruSeq", "Genes"])$p.value
ds_df_20 <- ds_df[ds_df$depth == 20000000 & ds_df$readorumi == "reads",]
anno_20 <- t.test(ds_df_20[ds_df_20$method == "prime-seq", "Genes"],
ds_df_20[ds_df_20$method == "TruSeq", "Genes"])$p.value
#subset df for common seq depths
ds_df_common <-ds_df[ds_df$depth %in% c(5000000, 10000000, 20000000) & ds_df$readorumi == "reads",]
ds_df_common$depth[ds_df_common$depth == "5000000"] <- "5"
ds_df_common$depth[ds_df_common$depth == "10000000"] <- "10"
ds_df_common$depth[ds_df_common$depth == "20000000"] <- "20"
ds_df_common$depth <- factor(ds_df_common$depth, levels = c("5", "10", "20"))
annotation_df <- data.frame(depth=c("5", "10", "20"),
start=c("prime-seq", "prime-seq", "prime-seq"),
end=c("TruSeq", "TruSeq","TruSeq"),
label=c("***", "***", "***"),
y=c(22400,24000,25500),stringsAsFactors = T)
c1 <- ggplot(data = ds_df_common, aes(x= method, y = Genes))+
facet_wrap(~depth, strip.position = "bottom")+
geom_boxplot(aes(color = method))+
geom_point(aes(color=method))+
ylab("Genes")+
xlab("Sequencing Reads (mil.)")+
ylim(19800,26000)+
geom_signif(data=annotation_df, aes(xmin=start, xmax=end, annotations=label, y_position=y),textsize = 5, vjust = 0, manual=TRUE)+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)+
theme(legend.position="none",
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank())
sensitivity_legend <- ggplot(data = ds_df, aes(x= depth, y = Genes, color = method, group = data))+
geom_smooth(method = "gam", se = F, aes(linetype=readorumi), color="black")+
geom_point(size =2, aes(shape=method))+
labs(color = "Method", linetype = "Count")+
guides(shape = F)+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)+
theme(legend.position = "bottom")
sensitivity_legend <- cowplot::get_legend(sensitivity_legend)
sensitivity_plots <- cowplot::plot_grid(a1, b1, c1,
ncol = 3,
nrow = 1
)
sensitivity_main <- cowplot::plot_grid(sensitivity_plots, sensitivity_legend,
ncol = 1,
nrow = 2,
rel_heights = c(4,1)
)
sensitivity_main
ggsave(sensitivity_main,
device = "pdf",
path = fig_path,
width = 300,
height=110,
units = "mm",
filename = "Fig3a.pdf"
)
# supp plot -- includes non-coding
sa1 <- ggplot(data = ds_df_nc, aes(x= depth, y = UMIs, color = method, group = data))+
geom_smooth(method = "loess", se = F, aes(linetype=readorumi))+
geom_point(size =2, aes(shape=method))+
xlab("Sequencing Reads (mil.)")+
ylab("Mapped Reads / UMIs (mil.)")+
ylim(0,30000000)+
scale_x_continuous(breaks = c(10000000,20000000,30000000), labels = c(10,20,30))+
scale_y_continuous(breaks = c(10000000,20000000,30000000), labels = c(10,20,30))+
ggtitle("Number of Reads / UMIs")+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)+
theme(legend.position="none")
sb1 <- ggplot(data = ds_df_nc, aes(x= depth, y = Genes, color = method, group = data))+
geom_smooth(method = "gam", se = F, aes(linetype=readorumi))+
geom_point(size =2, aes(shape=method))+
xlab("Sequencing Reads (mil.)")+
ylab("Genes")+
ylim(0,40000)+
scale_x_continuous(breaks = c(10000000,20000000,30000000), labels = c(10,20,30))+
ggtitle("Number of Genes")+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)+
theme(legend.position="none")
supp_sensitivity_legend <- ggplot(data = ds_df_nc, aes(x= depth, y = Genes, color = method, group = data))+
geom_smooth(method = "gam", se = F, aes(linetype=readorumi), color="black")+
geom_point(size =2, aes(shape=method))+
labs(color = "Method", linetype = "Count")+
guides(shape = F)+
theme_pub+
scale_color_manual(values = c("#008080","gray70"),limits= force)
supp_sensitivity_legend <- cowplot::get_legend(supp_sensitivity_legend)
supp_sensitivity <- cowplot::plot_grid(sa1, sb1, supp_sensitivity_legend,
ncol = 3,
nrow = 1,
rel_widths = c(4,4,1)
)
supp_sensitivity
```
## Features
### 5. Load and Process Data
```{r}
#read files
readspercell_prime <- read.table("/data/share/htp/prime-seq_Paper/Fig_maqc_comparison/zUMIs/prime-seq/zUMIs_output/stats/prime-seq.readspercell.txt", header = T)
readspercell_tru <- read.table("/data/share/htp/prime-seq_Paper/Fig_maqc_comparison/zUMIs/SEQC_PE/zUMIs_output/stats/SEQC_PE.readspercell.txt", header = T)
colnames(readspercell_prime)[1] <- "BC"
colnames(readspercell_tru)[1] <- "BC"
#add info
readspercell_prime <- inner_join(readspercell_prime, inf, by = "BC")
readspercell_tru <- inner_join(readspercell_tru, inf, by = "BC")
#combine the tables
readspercell <- bind_rows(readspercell_prime, readspercell_tru)
## barplot
#calculate number of reads per method for type
Assigned <- readspercell %>% dplyr::group_by(Method) %>% dplyr::summarize(Assigned=sum(N)) %>% as.data.frame()
Unmapped <- readspercell %>% dplyr::group_by(Method) %>% filter(type == "Unmapped") %>% dplyr::summarize(Unmapped=sum(N)) %>% as.data.frame()
Ambiguous <- readspercell %>% dplyr::group_by(Method) %>% filter(type == "Ambiguity") %>% dplyr::summarize(Ambiguous=sum(N)) %>% as.data.frame()
Intergenic <- readspercell %>% dplyr::group_by(Method) %>% filter(type == "Intergenic") %>% dplyr::summarize(Intergenic=sum(N)) %>% as.data.frame()
Intronic <- readspercell %>% dplyr::group_by(Method) %>% filter(type == "Intron") %>% dplyr::summarize(Intronic=sum(N)) %>% as.data.frame()
Exonic <- readspercell %>% dplyr::group_by(Method) %>% filter(type == "Exon") %>% dplyr::summarize(Exonic=sum(N)) %>% as.data.frame()
ERCCs <- readspercell %>% dplyr::group_by(Method) %>% filter(type == "User") %>% dplyr::summarize(ERCCs=sum(N)) %>% as.data.frame()
#join data frames
dfs <- list(Assigned, Unmapped, Ambiguous, Intergenic, Intronic, Exonic, ERCCs)
readspermethod <- plyr::join_all(dfs, by = "Method")
#make long
readspermethod_long <- pivot_longer(readspermethod, cols = 3:8)
#change factor levels
readspermethod_long$name<-factor(readspermethod_long$name, levels= rev(c("ERCCs", "Exonic","Intronic", "Intergenic", "Ambiguous","Unmapped")))
## boxplot
readspercell_total <- readspercell %>% dplyr::group_by(BC) %>% dplyr::summarize(Total=sum(N)) %>% as.data.frame()
readspercell <- left_join(readspercell, readspercell_total, by = "BC")
readspercell$fraction <- (readspercell$N / readspercell$Total)*100
readspercell$type[readspercell$type == "Ambiguity"] <- "Ambiguous"
readspercell$type[readspercell$type == "Intron"] <- "Intronic"
readspercell$type[readspercell$type == "Exon"] <- "Exonic"
readspercell$type[readspercell$type == "User"] <- "ERCCs"
readspercell$type<-factor(readspercell$type, levels= c("ERCCs", "Exonic","Intronic", "Intergenic", "Ambiguous","Unmapped"))
```
### 6. Generate Feature Plots
```{r}
#feature bar plot
feat_cols<-c("#F08C4B", "#E5DFCC", "#3A8DB5", "#556f44", "#9dc183", "#4D8C57", "#256EA0","dodgerblue4", "red", "#545454")
names(feat_cols)<-c("Ambiguous","Intergenic","Intronic","Ribosomal","Mitochondrial","lncRNA","Exonic","Intragenic", "ERCCs", "Unmapped")
plot_feat_bar <- ggplot(readspermethod_long, aes(x=Method, y=value, fill=name))+
geom_bar(stat="identity", position = "fill")+
facet_grid(Method~., scales="free") +
ylab("Fraction of Assigned Reads") +
scale_y_continuous(breaks=seq(0,1,0.1)) +
coord_flip() +
scale_fill_manual(values = feat_cols,limits= force)+
guides(fill = guide_legend(nrow =1, reverse=T))+
theme_pub+
theme(legend.title = element_blank(),
legend.position="bottom",
axis.title.y = element_blank(),
axis.text.y = element_blank(),
strip.text.y = element_text(angle = 360),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks.y = element_blank())
plot_feat_bar
ggsave(plot_feat_bar,
device = "pdf",
path = fig_path,
width = 217,
height=82,
units = "mm",
filename = "Fig3_supp_feat.pdf"
)
```
## `R` Session Info
```{r}
sessionInfo()
```