/
01B-alevin.Rmd
executable file
·455 lines (377 loc) · 13.5 KB
/
01B-alevin.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
---
title: "Alevin"
---
```{r knitr, include = FALSE}
DOCNAME = "01B-alevin"
NOW <- Sys.time()
# Time chunks during knitting
knitr::knit_hooks$set(timeit = function(before) {
if (before) {
print(paste("Start:", Sys.time()))
NOW <<- Sys.time()
} else {
print(paste("Stop:", Sys.time()))
print(Sys.time() - NOW)
}
})
knitr::opts_chunk$set(
autodep = TRUE,
cache = TRUE,
cache.path = paste0("cache/", DOCNAME, "/"),
cache.comments = FALSE,
echo = TRUE,
error = FALSE,
fig.align = "center",
fig.width = 10,
fig.height = 8,
message = FALSE,
warning = FALSE,
timeit = TRUE
)
```
```{r libaries, cache = FALSE}
# scRNA-seq
library("SingleCellExperiment")
# Tidyverse
library("tidyverse")
```
```{r source, cache = FALSE}
source(here::here("R/load.R"))
source(here::here("R/annotate.R"))
source(here::here("R/output.R"))
```
```{r depends-paths}
sel_path <- here::here("data/processed/01-selected.Rds")
```
```{r bpparam, cache = FALSE}
bpparam <- BiocParallel::MulticoreParam(workers = 10)
```
Introduction
============
The standard way to quanitfy 10x Chromium scRNA-seq data is using the Cell
Ranger platform that performs traditional alignment to a reference genome and
counts the reads overlapping annotated genes. An alternative appraoch is to
estimate expression levels directly against the transcriptome. We have done that
using an approach designed for scRNA-seq data called Alevin available in the
Salmon package. In this document we are going to compare the results of this
approach to what we get from Cell Ranger and our previous processing.
```{r load-sel, cache.extra = tools::md5sum(sel_path)}
if (file.exists(sel_path)) {
selected <- read_rds(sel_path)
} else {
stop("Selected dataset is missing. ",
"Please run '01-preprocessing.Rmd' first.",
call. = FALSE)
}
colData(selected)$BarcodeSample <- paste(
colData(selected)$Barcode,
colData(selected)$Sample,
sep = "-"
)
```
```{r load-alevin, cache.extra = tools::md5sum(sel_path)}
alevin_paths <- c(
here::here("data/alevin/Org1"),
here::here("data/alevin/Org2"),
here::here("data/alevin/Org3")
)
alevin <- readAlevin(alevin_paths, dataset = "Orgs123Alevin")
alevin <- annotateSCE(alevin, calc_qc = TRUE, BPPARAM = bpparam)
colData(alevin)$BarcodeSample <- paste(
colData(alevin)$Barcode,
colData(alevin)$Sample,
sep = "-"
)
```
```{r combine}
cell_data <- full_join(as.data.frame(colData(selected)),
as.data.frame(colData(alevin)),
by = "BarcodeSample",
suffix = c(".Trad", ".Alevin")) %>%
mutate(Sample = Sample.Trad) %>%
mutate(Sample = if_else(is.na(Sample), Sample.Alevin, Sample)) %>%
select(BarcodeSample, Sample, contains("_"),
-contains("control"), -contains("endogenous"), -contains("_MT")) %>%
mutate(SelBy = "Both") %>%
mutate(SelBy = if_else(!is.na(total_counts.Trad) &
is.na(total_counts.Alevin),
"Trad only", SelBy),
SelBy = if_else(is.na(total_counts.Trad) &
!is.na(total_counts.Alevin),
"Alevin only", SelBy)) %>%
mutate(SelBy = factor(SelBy,
levels = c("Both", "Trad only", "Alevin only")))
feat_data <- full_join(as.data.frame(rowData(selected)),
as.data.frame(rowData(alevin)),
by = "ID",
suffix = c(".Trad", ".Alevin")) %>%
mutate(Annot = "Both") %>%
mutate(Annot = if_else(!is.na(total_counts.Trad) &
is.na(total_counts.Alevin),
"Trad only", Annot),
Annot = if_else(is.na(total_counts.Trad) &
!is.na(total_counts.Alevin),
"Alevin only", Annot)) %>%
mutate(Annot = factor(Annot,
levels = c("Both", "Trad only", "Alevin only")))
```
Cell selection
==============
Alevin has it's own method of selecting cell-containing droplets. Let's see how
that compares to what we have done previously.
```{r cell-selection}
ggplot(cell_data, aes(x = SelBy, fill = Sample)) +
geom_bar() +
theme_minimal() +
theme(axis.title.x = element_blank())
```
Cell counts {.tabset}
===========
Standard
--------
```{r cell-counts}
plot_data <- cell_data %>%
mutate(Traditional = total_counts.Trad,
Alevin = total_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional,
0.9 * min(Traditional, na.rm = TRUE)),
Alevin = replace_na(Alevin, 0.9 * min(Alevin, na.rm = TRUE)))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = SelBy)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, SelBy == "Both"),
method = "lm", colour = "blue") +
ggtitle("total_counts") +
theme_minimal()
```
Logged
------
```{r cell-counts-log}
plot_data <- cell_data %>%
mutate(Traditional = log10_total_counts.Trad,
Alevin = log10_total_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional,
0.9 * min(Traditional, na.rm = TRUE)),
Alevin = replace_na(Alevin, 0.9 * min(Alevin, na.rm = TRUE)))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = SelBy)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, SelBy == "Both"),
method = "lm", colour = "blue") +
ggtitle("log10(total_counts)") +
theme_minimal()
```
Cell features {.tabset}
=============
Standard
--------
```{r cell-features}
plot_data <- cell_data %>%
mutate(Traditional = total_features_by_counts.Trad,
Alevin = total_features_by_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional,
0.9 * min(Traditional, na.rm = TRUE)),
Alevin = replace_na(Alevin, 0.9 * min(Alevin, na.rm = TRUE)))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = SelBy)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, SelBy == "Both"),
method = "lm", colour = "blue") +
ggtitle("total_features_by_counts") +
theme_minimal()
```
Logged
------
```{r cell-features-log}
plot_data <- cell_data %>%
mutate(Traditional = log10_total_features_by_counts.Trad,
Alevin = log10_total_features_by_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional,
0.9 * min(Traditional, na.rm = TRUE)),
Alevin = replace_na(Alevin, 0.9 * min(Alevin, na.rm = TRUE)))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = SelBy)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, SelBy == "Both"),
method = "lm", colour = "blue") +
ggtitle("log10(total_features_by_counts)") +
theme_minimal()
```
Top 100 {.tabset}
=======
Percent counts in top 100 most expressed features.
```{r top-100}
plot_data <- cell_data %>%
mutate(Traditional = pct_counts_in_top_100_features.Trad,
Alevin = pct_counts_in_top_100_features.Alevin) %>%
mutate(Traditional = replace_na(Traditional,
0.9 * min(Traditional, na.rm = TRUE)),
Alevin = replace_na(Alevin, 0.9 * min(Alevin, na.rm = TRUE)))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = SelBy)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, SelBy == "Both"),
method = "lm", colour = "blue") +
ggtitle("pct_counts_in_top_100_features") +
theme_minimal()
```
Gene counts {.tabset}
===========
Standard
--------
```{r gene-counts}
plot_data <- feat_data %>%
mutate(Traditional = total_counts.Trad,
Alevin = total_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional, -1e5),
Alevin = replace_na(Alevin, -1e5))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = Annot)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, Annot == "Both"),
method = "lm", colour = "blue") +
ggtitle("total_counts") +
theme_minimal()
```
Logged
------
```{r gene-counts-log}
plot_data <- feat_data %>%
mutate(Traditional = log10_total_counts.Trad,
Alevin = log10_total_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional, -1),
Alevin = replace_na(Alevin, -1))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = Annot)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, Annot == "Both"),
method = "lm", colour = "blue") +
ggtitle("log10(total_counts)") +
theme_minimal()
```
Gene cells {.tabset}
==========
```{r gene-cells}
plot_data <- feat_data %>%
mutate(Traditional = n_cells_by_counts.Trad,
Alevin = n_cells_by_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional, -500),
Alevin = replace_na(Alevin, -500))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = Annot)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, Annot == "Both"),
method = "lm", colour = "blue") +
ggtitle("n_cells_by_counts") +
theme_minimal()
```
Logged
------
```{r gene-cells-log}
plot_data <- feat_data %>%
mutate(Traditional = log10_total_counts.Trad,
Alevin = log10_total_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional, -1),
Alevin = replace_na(Alevin, -1))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = Annot)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, Annot == "Both"),
method = "lm", colour = "blue") +
ggtitle("log10(total_counts)") +
theme_minimal()
```
Gene means {.tabset}
==========
Standard
--------
```{r gene-means}
plot_data <- feat_data %>%
mutate(Traditional = mean_counts.Trad,
Alevin = mean_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional, -5),
Alevin = replace_na(Alevin, -5))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = Annot)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, Annot == "Both"),
method = "lm", colour = "blue") +
ggtitle("mean_counts") +
theme_minimal()
```
Logged
------
```{r gene-means-log}
plot_data <- feat_data %>%
mutate(Traditional = log10_mean_counts.Trad,
Alevin = log10_mean_counts.Alevin) %>%
mutate(Traditional = replace_na(Traditional, -0.1),
Alevin = replace_na(Alevin, -0.1))
ggplot(plot_data, aes(x = Traditional, y = Alevin, colour = Annot)) +
geom_point(alpha = 0.3) +
geom_abline(intercept = 0, slope = 1, colour = "red") +
geom_smooth(data = filter(plot_data, Annot == "Both"),
method = "lm", colour = "blue") +
ggtitle("log10(mean_counts)") +
theme_minimal()
```
Counts-cells
============
```{r counts-zeros}
counts_data <- feat_data %>%
filter(Annot == "Both") %>%
select(ID, starts_with("log10_total_counts")) %>%
gather(key = "Method", value = "log10_total_counts", -ID) %>%
mutate(Method = str_split(Method, "\\.", simplify = TRUE)[, 2])
zeros_data <- feat_data %>%
filter(Annot == "Both") %>%
select(ID, starts_with("n_cells_by_counts")) %>%
gather(key = "Method", value = "n_cells_by_counts", -ID) %>%
mutate(Method = str_split(Method, "\\.", simplify = TRUE)[, 2])
plot_data <- left_join(counts_data, zeros_data, by = c("ID", "Method"))
ggplot(plot_data,
aes(x = log10_total_counts, y = n_cells_by_counts, colour = Method)) +
geom_point() +
geom_smooth(aes(group = Method), colour = "blue") +
facet_wrap(~ Method) +
theme_minimal()
```
Summary
=======
Overall the two approaches seem to produce similar results. There are
differences between them but it is difficult to tell if one approach is
inaccurate. For the rest of this analysis we will stick with the traditional
approach as it is more familiar.
Parameters
----------
This table describes parameters used and set in this document.
```{r parameters}
params <- list(
)
params <- jsonlite::toJSON(params, pretty = TRUE)
knitr::kable(jsonlite::fromJSON(params))
```
Output files
------------
This table describes the output files produced by this document. Right click
and _Save Link As..._ to download the results.
```{r save}
write_rds(alevin, here::here("data/processed/01B-alevin.Rds"))
```
```{r output}
dir.create(here::here("output", DOCNAME), showWarnings = FALSE)
readr::write_lines(params, here::here("output", DOCNAME, "parameters.json"))
knitr::kable(data.frame(
File = c(
getDownloadLink("parameters.json", DOCNAME)
),
Description = c(
"Parameters set and used in this analysis"
)
))
```
Session information
-------------------
```{r session-info, cache = FALSE}
devtools::session_info()
```