-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForebrainDorsal_E150-analysis.qmd
337 lines (228 loc) · 8.01 KB
/
ForebrainDorsal_E150-analysis.qmd
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
---
title: "Forebrain Dorsal E15.0 Data-set Anaysis"
---
```{r}
library(ggplot2)
library(tibble)
library(zeallot)
library(COTAN)
options(parallelly.fork.enable = TRUE)
outDir <- "Data/MouseCortexFromLoom/"
setLoggingLevel(1)
setLoggingFile(file.path(outDir, "ForebrainDorsal_E150-analysis.log"))
```
## Cleaning
Read the already created COTAN object
```{r}
fb150Obj <- readRDS("Data/MouseCortexFromLoom/SourceData/e15.0_ForebrainDorsal.cotan.RDS")
sampleCondition <- getMetadataElement(fb150Obj, datasetTags()[["cond"]])
sampleCondition
```
Inspect cells' sizes
```{r}
cellSizePlot(fb150Obj, splitPattern = ":", numCol = 1)
```
Drop cells with too many ritz reads as they are probably duplets
```{r}
cellsSizeThr <- 10000
fb150Obj <- addElementToMetaDataset(fb150Obj, "Cells size threshold", cellsSizeThr)
cells_to_rem <- getCells(fb150Obj)[getCellsSize(fb150Obj) > cellsSizeThr]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
cellSizePlot(fb150Obj, splitPattern = ":", numCol = 1)
```
Inspect the number of expressed genes per cell
```{r}
genesSizePlot(fb150Obj, splitPattern = ":", numCol = 1)
```
Drop cells with too low genes expession as they are probably dead
```{r}
genesSizeLowThr <- 700
fb150Obj <- addElementToMetaDataset(fb150Obj, "Num genes low threshold", genesSizeLowThr)
numExprGenes <- getNumExpressedGenes(fb150Obj)
cells_to_rem <- names(numExprGenes)[numExprGenes < genesSizeLowThr]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
genesSizePlot(fb150Obj, splitPattern = ":", numCol = 1)
```
Check number of mitocondrial genes expressed in each cell
```{r}
mitGenesPattern <- "^mt."
getGenes(fb150Obj)[grep(mitGenesPattern, getGenes(fb150Obj))]
c(mitPlot, mitSizes) %<-%
mitochondrialPercentagePlot(fb150Obj, genePrefix = mitGenesPattern,
splitPattern = ":", numCol = 1)
plot(mitPlot)
```
Cells with a too high percentage of mitocondrial genes are likely dead (or at the last problematic) cells. So we drop them!
```{r}
mitPercThr <- 1.0
fb150Obj <- addElementToMetaDataset(fb150Obj, "Mitoc. perc. threshold", mitPercThr)
cells_to_rem <- rownames(mitSizes)[mitSizes[["mit.percentage"]] > mitPercThr]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
c(mitPlot, mitSizes) %<-%
mitochondrialPercentagePlot(fb150Obj, genePrefix = mitGenesPattern,
splitPattern = ":", numCol = 1)
plot(mitPlot)
```
Check no further outliers after all the culling
```{r}
cellSizePlot(fb150Obj, splitPattern = ":", numCol = 1)
genesSizePlot(fb150Obj, splitPattern = ":", numCol = 1)
```
### Clean: round 1
```{r}
#| label: Clean round 1
fb150Obj <- clean(fb150Obj)
c(pcaCellsPlot, pcaCellsData, genesPlot, UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(fb150Obj)
plot(pcaCellsPlot)
plot(genesPlot)
fb150Obj <- addElementToMetaDataset(fb150Obj, "Num drop B group", 0)
```
B group contains highly diverse cells: drop them!
```{r}
cells_to_rem <- rownames(pcaCellsData)[pcaCellsData[["groups"]] == "B"]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
```
### Clean: round 2
```{r}
#| label: Clean round 2
fb150Obj <- clean(fb150Obj)
c(pcaCellsPlot, pcaCellsData, genesPlot,
UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(fb150Obj)
plot(pcaCellsPlot)
plot(genesPlot)
fb150Obj <- addElementToMetaDataset(fb150Obj, "Num drop B group", 1)
```
B group contains one cell with high diversity in the higher components
```{r}
plot(pcaCellsData)
cells_to_rem <- rownames(pcaCellsData)[pcaCellsData[["groups"]] == "B"]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
```
### Clean: round 3
```{r}
#| label: Clean round 3
fb150Obj <- clean(fb150Obj)
c(pcaCellsPlot, pcaCellsData, genesPlot,
UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(fb150Obj)
plot(pcaCellsPlot)
plot(genesPlot)
fb150Obj <- addElementToMetaDataset(fb150Obj, "Num drop B group", 2)
```
B group contains one cell with high diversity in the higher components
```{r}
plot(pcaCellsData)
cells_to_rem <- rownames(pcaCellsData)[pcaCellsData[["groups"]] == "B"]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
```
### Clean: round 4
```{r}
#| label: Clean round 4
fb150Obj <- clean(fb150Obj)
c(pcaCellsPlot, pcaCellsData, genesPlot,
UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(fb150Obj)
plot(pcaCellsPlot)
plot(genesPlot)
fb150Obj <- addElementToMetaDataset(fb150Obj, "Num drop B group", 3)
```
B group contains few cell with high diversity
```{r}
plot(pcaCellsData)
cells_to_rem <- rownames(pcaCellsData)[pcaCellsData[["groups"]] == "B"]
fb150Obj <- dropGenesCells(fb150Obj, cells = cells_to_rem)
```
### Clean: round 5
```{r}
#| label: Clean round 5
fb150Obj <- clean(fb150Obj)
c(pcaCellsPlot, pcaCellsData, genesPlot,
UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(fb150Obj)
plot(pcaCellsPlot)
plot(genesPlot)
fb150Obj <- addElementToMetaDataset(fb150Obj, "Num drop B group", 4)
```
Visualize if all is ok:
```{r}
plot(UDEPlot)
plot(nuPlot)
lowUDEThr <- 0.4 # the threshold to remove low UDE cells
nuDf <- data.frame("nu" = sort(getNu(fb150Obj)), "n" = seq_along(getNu(fb150Obj)))
UDEPlot_zoomed <- ggplot(nuDf, aes(x = n, y = nu)) +
geom_point(colour = "#8491B4B2", size = 1.0) +
xlim(0L, 400L) +
ylim(0.0, 1.0) +
geom_hline(yintercept = lowUDEThr, linetype = "dashed",
color = "darkred") +
annotate(geom = "text", x = 200L, y = 0.25,
label = paste0("to remove cells with nu < ", lowUDEThr),
color = "darkred", size = 4.5)
plot(UDEPlot_zoomed)
```
Final cleaning to check all is OK
```{r}
fb150Obj <- clean(fb150Obj)
c(pcaCellsPlot, pcaCellsData, genesPlot, UDEPlot, nuPlot, zoomedNuPlot) %<-% cleanPlots(fb150Obj)
plot(pcaCellsPlot)
plot(genesPlot)
plot(UDEPlot)
plot(nuPlot)
plot(cellSizePlot(fb150Obj, splitPattern = ":", numCol = 1))
plot(genesSizePlot(fb150Obj, splitPattern = ":", numCol = 1))
```
Calculate genes' COEX
```{r, echo=TRUE, eval=FALSE}
Sys.time()
fb150Obj <- proceedToCoex(fb150Obj, calcCoex = TRUE, cores = 12,
saveObj = TRUE, outDir = outDir)
Sys.time()
```
Save the COTAN object
```{r, echo=TRUE, eval=FALSE}
saveRDS(fb150Obj, file = file.path(outDir, paste0(sampleCondition, ".cotan.RDS")))
```
```{r}
fb150Obj <- readRDS(file = file.path(outDir, paste0(sampleCondition, ".cotan.RDS")))
```
## GDI
```{r}
gdiData <- calculateGDI(fb150Obj)
genesToLabel <- head(rownames(gdiData[order(gdiData[["GDI"]],
decreasing = TRUE), ]), n = 10L)
genesToLabel
gdiPlot <- GDIPlot(fb150Obj, GDIIn = gdiData, GDIThreshold = 1.4,
genes = list("Top 10 GDI genes" = genesToLabel))
plot(gdiPlot)
```
```{r, eval=FALSE, echo=TRUE}
splitClusters <- cellsUniformClustering(fb150Obj, GDIThreshold = 1.4, cores = 13,
saveObj = TRUE, outDir = outDir)
c(splitCoexDF, splitPValueDF) %<-% DEAOnClusters(fb150Obj, clusters = splitClusters)
fb150Obj <- addClusterization(fb150Obj, clName = "split",
clusters = splitClusters,
coexDF = splitCoexDF, override = TRUE)
table(splitClusters)
```
```{r, echo=FALSE, eval=FALSE}
saveRDS(fb150Obj, file = file.path(outDir, paste0(sampleCondition, ".cotan.RDS")))
```
## Consistent Transcript Cohorts (clustering)
```{r, eval=FALSE, echo=TRUE}
c(mergedClusters, mergedCoexDF, mergedPValueDF) %<-%
mergeUniformCellsClusters(fb150Obj, clusters = splitClusters,
GDIThreshold = 1.4, cores = 13,
saveObj = TRUE, outDir = outDir)
fb150Obj <- addClusterization(fb150Obj, clName = "merge",
clusters = mergedClusters,
coexDF = mergedCoexDF,
override = TRUE)
table(mergedClusters)
```
```{r, eval=FALSE, echo=FALSE}
saveRDS(fb150Obj, file = file.path(outDir, paste0(sampleCondition, ".cotan.RDS")))
```
------------------------------------------------------------------------
```{r}
Sys.time()
```
```{r}
sessionInfo()
```