-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForebrainLaManno2021ClustersGDI.qmd
286 lines (194 loc) · 7.62 KB
/
ForebrainLaManno2021ClustersGDI.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
---
title: "Forebrain La Manno 2021 Clusters GDI"
author: "trinetra75 & seriph78"
date: "`r Sys.Date()`"
output: html_document
---
## Preamble
For the evaluation of GDI sensitivity and also to test type I error and FDR for the differential expressed gene in a cluster we need to have some Coherent Transcript Cell Cluster (cluster formed by cells as similar as possible). So we tested all clusters defined in the original paper for this data set (focusing on E13.5, E15.0, and E17.5).
```{r}
library(rlang)
library(zeallot)
library(data.table)
library(COTAN)
#devtools::load_all("~/dev/COTAN/COTAN/")
options(parallelly.fork.enable = TRUE)
setLoggingLevel(2)
setLoggingFile(file.path(".", "ClusterizationsGDI_AllForebrainDorsal.log"))
```
### Definition of functions to extract data from clustersList
```{r}
getClData <- function(objCOTAN, clList, cl) {
cluster <- names(clList)[[cl]]
cells <- clList[[cl]]
res <- checkClusterUniformity(objCOTAN, cluster = cluster, cells = cells,
GDIThreshold = 1.4, cores = 6, saveObj = FALSE)
res <- c(list("cluster" = cluster, "size" = length(cells)), res)
res <- as.data.frame(res)
rownames(res) <- cluster
colnames(res)
return(res)
}
clDataVal <- list("cluster" = NULL, "size" = NULL, "isUniform" = NULL,
"fractionAbove" = NULL, "1stPercentile" = NULL)
```
## Forebrain Dorsal E13.5
### Load dataset
```{r}
fb135Obj <- readRDS(file = file.path("Data/MouseCortexFromLoom/", "e13.5_ForebrainDorsal.cotan.RDS"))
sampleCondition <- getMetadataElement(fb135Obj, datasetTags()[["cond"]])
logThis(sampleCondition)
allClust <- getClusterizations(fb135Obj)
logThis("")
logThis(paste("Number of cells:", getNumCells(fb135Obj)))
logThis("")
logThis("Available clusterizations:")
logThis(paste0(allClust, collapse = ", "))
clSizes <- vapply(allClust, function(x) { nlevels(getClusters(fb135Obj, x))}, integer(1L))
clSizes
logThis(paste(names(clSizes), clSizes, sep = ": ", collapse = ", "))
```
### Extract original cluster
```{r}
originalFB135 <- getClusters(fb135Obj, clName = "original.clusters")
nlevels(originalFB135)
sort(table(originalFB135), decreasing = TRUE)
# drop too small clusters: those whose size is less than 15
largeClFB135 <- which(table(originalFB135) >= 50)
largeOrigFB135 <- originalFB135[(originalFB135 %in% names(largeClFB135)),
drop = TRUE]
largeOrigFB135 <- toClustersList(largeOrigFB135)
```
### Calculate GDI for each cluster in E13.5
```{r,echo=TRUE,eval=FALSE}
print("Length larger clusters")
vapply(largeOrigFB135, length, integer(1))
resDataFB135 <- lapply(seq_along(largeOrigFB135), FUN = getClData,
objCOTAN = fb135Obj, clList = largeOrigFB135)
```
```{r, echo=TRUE,eval=FALSE}
clDataFB135 <- data.table::rbindlist(resDataFB135)
clDataFB135 <- column_to_rownames(clDataFB135, var = "cluster")
```
```{r, echo=TRUE, eval=FALSE}
saveRDS(clDataFB135,
file = file.path("Data/MouseCortexFromLoom/ClustersGDI/", "e13.5_ForebrainDorsal_GDI_of_original_clusterization.RDS"))
```
```{r}
clDataFB135 <- readRDS("Data/MouseCortexFromLoom/ClustersGDI/e13.5_ForebrainDorsal_GDI_of_original_clusterization.RDS")
clDataFB135[order(clDataFB135$size, decreasing = T),]
```
So we can use the following clusters (at least 100 cells - cell number in the parenthesis - and GDI lower than 1.5):
- cl432 (n.cells 536),
- cl187 (334),
- cl434 (326),
- cl184 (292),
- cl437 (259),
- cl510 (248)
## Forebrain Dorsal E15.0
### Load dataset
```{r}
fb150Obj <- readRDS(file = file.path("Data/MouseCortexFromLoom/", "e15.0_ForebrainDorsal.cotan.RDS"))
sampleCondition <- getMetadataElement(fb150Obj, datasetTags()[["cond"]])
logThis(sampleCondition)
allClust <- getClusterizations(fb150Obj)
logThis("")
logThis(paste("Number of cells:", getNumCells(fb150Obj)))
logThis("")
logThis("Available clusterizations:")
logThis(paste0(allClust, collapse = ", "))
clSizes <- vapply(allClust, function(x) { nlevels(getClusters(fb150Obj, x))}, integer(1L))
clSizes
logThis(paste(names(clSizes), clSizes, sep = ": ", collapse = ", "))
```
### Extract original cluster
```{r}
originalFB150 <- getClusters(fb150Obj, clName = "original.clusters")
nlevels(originalFB150)
sort(table(originalFB150), decreasing = TRUE)
# drop too small clusters: those whose size is less than 15
largeClFB150 <- which(table(originalFB150) >= 50)
largeOrigFB150 <- originalFB150[(originalFB150 %in% names(largeClFB150)),
drop = TRUE]
largeOrigFB150 <- toClustersList(largeOrigFB150)
```
### Calculate GDI for each cluster
```{r,echo=TRUE,eval=FALSE}
print("Length larger clusters")
vapply(largeOrigFB150, length, integer(1))
resDataFB150 <- lapply(seq_along(largeOrigFB150), FUN = getClData,
objCOTAN = fb150Obj, clList = largeOrigFB150)
```
```{r,echo=TRUE,eval=FALSE}
clDataFB150 <- data.table::rbindlist(resDataFB150)
clDataFB150 <- column_to_rownames(clDataFB150, var = "cluster")
```
```{r,echo=TRUE,eval=FALSE}
saveRDS(clDataFB150,
file = file.path("Data/MouseCortexFromLoom/ClustersGDI/", "e15.0_ForebrainDorsal_GDI_of_original_clusterization.RDS"))
```
```{r}
clDataFB150 <- readRDS("Data/MouseCortexFromLoom/ClustersGDI/e15.0_ForebrainDorsal_GDI_of_original_clusterization.RDS")
clDataFB150[order(clDataFB150$size,decreasing = T),]
```
So we can use the following clusters (at least 100 cells - cell number in the parenthesis - and GDI lower than 1.5):
- cl432 (586),
- cl509 (402),
- cl510 (402),
- cl508 (397),
- cl428 (318),
- cl434 (273),
- cl437 (258)
## Forebrain Dorsal E17.5
### Load dataset
```{r}
fb175Obj <- readRDS(file = file.path("Data/MouseCortexFromLoom/", "e17.5_ForebrainDorsal.cotan.RDS"))
sampleCondition <- getMetadataElement(fb175Obj, datasetTags()[["cond"]])
logThis(sampleCondition)
allClust <- getClusterizations(fb175Obj)
logThis("")
logThis(paste("Number of cells:", getNumCells(fb175Obj)))
logThis("")
logThis("Available clusterizations:")
logThis(paste0(allClust, collapse = ", "))
clSizes <- vapply(allClust, function(x) { nlevels(getClusters(fb175Obj, x))}, integer(1L))
clSizes
logThis(paste(names(clSizes), clSizes, sep = ": ", collapse = ", "))
```
### Extract original cluster
```{r}
originalFB175 <- getClusters(fb175Obj, clName = "original.clusters")
nlevels(originalFB175)
sort(table(originalFB175), decreasing = TRUE)
# drop too small clusters: those whose size is less than 15
largeClFB175 <- which(table(originalFB175) >= 50)
largeOrigFB175 <- originalFB175[(originalFB175 %in% names(largeClFB175)),
drop = TRUE]
largeOrigFB175 <- toClustersList(largeOrigFB175)
```
### Calculate GDI for each cluster
```{r, eval=FALSE, echo=TRUE}
print("Length larger clusters")
vapply(largeOrigFB175, length, integer(1))
resDataFB175 <- lapply(seq_along(largeOrigFB175), FUN = getClData,
objCOTAN = fb175Obj, clList = largeOrigFB175)
```
```{r, eval=FALSE, echo=TRUE}
clDataFB175 <- data.table::rbindlist(resDataFB175)
clDataFB175 <- column_to_rownames(clDataFB175, var = "cluster")
```
```{r, eval=FALSE, echo=TRUE}
saveRDS(clDataFB175,
file = file.path("Data/MouseCortexFromLoom/ClustersGDI/", "e17.5_ForebrainDorsal_GDI_of_original_clusterization.RDS"))
```
```{r}
clDataFB175 <- readRDS("Data/MouseCortexFromLoom/ClustersGDI/e17.5_ForebrainDorsal_GDI_of_original_clusterization.RDS")
clDataFB175[order(clDataFB175$size,decreasing = T),]
```
So we can use the following clusters (at least 100 cells - cell number in the parenthesis - and GDI lower than 1.5):
- cl516 (297),
- cl505 (203)
------------------------------------------------------------------------
```{r}
sessionInfo()
```