-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-normalizatio_libexerciseCGAP.R
160 lines (112 loc) · 4.32 KB
/
4-normalizatio_libexerciseCGAP.R
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
## ----setup, include=FALSE--------------------------------------------------------------------------------------------
options(htmltools.dir.version = FALSE)
## ----xaringan-themer, include=FALSE----------------------------------------------------------------------------------
library(xaringanthemer)
solarized_dark(
code_font_family = "Fira Code",
code_font_url = "https://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/fira_code.css"
)
## /* From https://github.com/yihui/xaringan/issues/147 */
## .scroll-output {
## height: 80%;
## overflow-y: scroll;
## }
##
## /* https://stackoverflow.com/questions/50919104/horizontally-scrollable-output-on-xaringan-slides */
## pre {
## max-width: 100%;
## overflow-x: scroll;
## }
##
## /* From https://github.com/yihui/xaringan/wiki/Font-Size */
## .tiny{
## font-size: 40%
## }
##
## /* From https://github.com/yihui/xaringan/wiki/Title-slide */
## .title-slide {
## background-image: url(https://raw.githubusercontent.com/Bioconductor/OrchestratingSingleCellAnalysis/master/images/Workflow.png);
## background-size: 33%;
## background-position: 0% 100%
## }
## ----all_code, cache=TRUE--------------------------------------------------------------------------------------------
library('scRNAseq')
sce.zeisel <- ZeiselBrainData(ensembl = TRUE)
# Quality control
library('scater')
is.mito <- which(rowData(sce.zeisel)$featureType == "mito")
stats <- perCellQCMetrics(sce.zeisel, subsets = list(Mt = is.mito))
qc <-
quickPerCellQC(stats,
percent_subsets = c("altexps_ERCC_percent", "subsets_Mt_percent"))
sce.zeisel <- sce.zeisel[, !qc$discard]
## ----all_code2, cache=TRUE, dependson='all_code'---------------------------------------------------------------------
# Library size factors
lib.sf.zeisel <- librarySizeFactors(sce.zeisel)
# Examine distribution of size factors
summary(lib.sf.zeisel)
hist(log10(lib.sf.zeisel), xlab = "Log10[Size factor]", col = "grey80")
ls.zeisel <- colSums(counts(sce.zeisel))
plot(
ls.zeisel,
lib.sf.zeisel,
log = "xy",
xlab = "Library size",
ylab = "Size factor"
)
###Exercise
#These are my answers to 1 and 2
#Question 1: are ls.zeisel and lib.sf.zeisel equal?
identical(ls.zeisel, lib.sf.zeisel)
#R= FALSE
#Question 2: are they proportional?
proportion=lib.sf.zeisel/ls.zeisel
table(proportion)
table(lib.sf.zeisel/ls.zeisel)
table(ls.zeisel/lib.sf.zeisel)
#R. 14589.58. The important point is in the "table" command, this will allow me to see if the factor is common across all samples.
#If I only get one value, then that means that all elements in the vector have the same factor, so I confirm that they are proportional
#I couldnt complete this one but that was the idea which I asked you before ending class, so I copied it from your text
## ----exercise_solution, cache=TRUE, dependson='all_code'-------------------------------------------------------------
## First compute the sums
zeisel_sums <- colSums(counts(sce.zeisel))
identical(zeisel_sums, ls.zeisel)
## Next, make them have unity mean
zeisel_size_factors <- zeisel_sums/mean(zeisel_sums)
identical(zeisel_size_factors, lib.sf.zeisel)
## ----all_code3, cache=TRUE, dependson='all_code2'--------------------------------------------------------------------
# Normalization by convolution
library('scran')
# Pre-clustering
set.seed(100)
clust.zeisel <- quickCluster(sce.zeisel)
# Compute deconvolution size factors
deconv.sf.zeisel <-
calculateSumFactors(sce.zeisel, clusters = clust.zeisel, min.mean = 0.1)
# Examine distribution of size factors
summary(deconv.sf.zeisel)
hist(log10(deconv.sf.zeisel), xlab = "Log10[Size factor]",
col = "grey80")
plot(
ls.zeisel,
deconv.sf.zeisel,
log = "xy",
xlab = "Library size",
ylab = "Size factor"
)
## ----all_code4, cache=TRUE, dependson='all_code3'--------------------------------------------------------------------
# Library size factors vs. convolution size factors
# Colouring points using the supplied cell-types
plot(
lib.sf.zeisel,
deconv.sf.zeisel,
xlab = "Library size factor",
ylab = "Deconvolution size factor",
log = 'xy',
pch = 16,
col = as.integer(factor(sce.zeisel$level1class))
)
abline(a = 0, b = 1, col = "red")
## ----'reproducibility', cache = TRUE, dependson=knitr::all_labels()--------------------------------------------------
options(width = 120)
sessioninfo::session_info()