-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeTable-to-diff-wrt-null-2.R
360 lines (257 loc) · 9.89 KB
/
makeTable-to-diff-wrt-null-2.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
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
## Create data with the differences w.r.t. null incorporated as
## variables
date()
rm(list = ls())
library(dplyr)
###########################################
##
## Genotype-by-genotype data, over replicate
##
###########################################
df <- readRDS("data_no_any_over_replicate.rds")
data <- df$data
columnsExplained <- df$columnsExplained
## Getting the difference w.r.t null
nullm <- dplyr::filter(df$data, method == "null")
## Note
table(df$data$method)/nrow(nullm)
## 3
## where 3 = 3 size_split
## Recall that in "merge-additional-info.R" we replicated the null for the three
## detections. See around line 156
nullmljs <- nullm[nullm$detect == "large", "js"]
nullmsjs <- nullm[nullm$detect == "small", "js"]
nullmujs <- nullm[nullm$detect == "uniform", "js"]
stopifnot(identical(nullmljs, nullmsjs))
stopifnot(identical(nullmljs, nullmujs))
## detect and size_split make no difference for null model
## recall no value for size_split
stopifnot(is.na(nullm$size_split))
nullm2 <- nullm[nullm$detect == "large",
c("id", "sourceGenotype",
## Next are for checking
"typeLandscape",
"numGenes",
"sourceGenotype_nMut",
## "sourceGenotype_freqInPOM",
"method", ## rename this
## The response to subtract
"js")]
colnames(nullm2)[3:ncol(nullm2)] <- paste0(colnames(nullm2)[3:ncol(nullm2)], "_null")
## rm(nullm)
rm(df)
gc()
data2 <- dplyr::full_join(data, nullm2, by = c("id", "sourceGenotype"))
tmp <- dplyr::left_join(data, nullm2, by = c("id", "sourceGenotype"))
## checks
stopifnot(nrow(data) == nrow(data2))
stopifnot(identical(tmp, data2))
rm(tmp)
gc()
stopifnot(table(data2$method_null) == nrow(data))
stopifnot(nrow(data2) == nrow(data))
stopifnot(identical(data2$typeLandscape, data2$typeLandscape_null))
stopifnot(identical(data2$numGenes, data2$numGenes_null))
stopifnot(identical(data2$sourceGenotype_numMuts, data2$sourceGenotype_numMuts_null))
## silly: these columns not present
## stopifnot(identical(data2$sourceGenotype_freqInPOM, data2$sourceGenotype_freqInPOM_null))
stopifnot(data2$method_null == "null")
data2$js_diff <- data2$js_null - data2$js
## rm duplicated columns just for checking
data2 <- data2[, -c(60:63)]
stopifnot(dplyr::filter(data2, method == "null")$js_diff == 0)
genotype_diff_null <- data2
save(file = "genotype_diff_null.RData", genotype_diff_null,
compress = FALSE)
rm(nullm, df, data, nullm2)
rm(list = ls())
gc()
###############################################
##
## Array data
##
###############################################
rm(list = ls())
dfa <- readRDS("array_statistics_over_replicate.rds")
da <- dfa$data
nullm <- dplyr::filter(da, method == "null")
## Note
table(da$method)/nrow(nullm)
## 3
## where 3 = 3 size_split
## detect makes no difference for js_w_real, but makes a difference
## for js_w_sampl
## recall no value for size_split
stopifnot(is.na(nullm$size_split))
## checks
nullmljs <- nullm[nullm$detect == "large", "js_w_real"]
nullmsjs <- nullm[nullm$detect == "small", "js_w_real"]
nullmujs <- nullm[nullm$detect == "uniform", "js_w_real"]
stopifnot(identical(nullmljs, nullmsjs))
stopifnot(identical(nullmljs, nullmujs))
nullmljs <- nullm[nullm$detect == "large", "js_w_sampl"]
nullmsjs <- nullm[nullm$detect == "small", "js_w_sampl"]
nullmujs <- nullm[nullm$detect == "uniform", "js_w_sampl"]
stopifnot(!identical(nullmljs, nullmsjs))
stopifnot(!identical(nullmljs, nullmujs))
nullm2 <- nullm[,
c("id", "detect",
## Next are for checking
"typeLandscape",
"numGenes",
"method", ## rename this
## The response to subtract
"js_w_real", "js_w_sampl")]
colnames(nullm2)[3:ncol(nullm2)] <-
paste0(colnames(nullm2)[3:ncol(nullm2)], "_null")
dataA <- dplyr::full_join(da, nullm2, by = c("id", "detect"))
tmp <- dplyr::left_join(da, nullm2, by = c("id", "detect"))
## checks
stopifnot(nrow(da) == nrow(dataA))
stopifnot(identical(tmp, dataA))
rm(tmp)
gc()
stopifnot(table(dataA$method_null) == nrow(da))
stopifnot(nrow(dataA) == nrow(da))
stopifnot(identical(dataA$typeLandscape, dataA$typeLandscape_null))
stopifnot(identical(dataA$numGenes, dataA$numGenes_null))
stopifnot(dataA$method_null == "null")
dataA$js_w_real_diff <- dataA$js_w_real_null - dataA$js_w_real
dataA$js_w_sampl_diff <- dataA$js_w_sampl_null - dataA$js_w_sampl
stopifnot(dplyr::filter(dataA, method == "null")$js_w_real_diff == 0)
stopifnot(dplyr::filter(dataA, method == "null")$js_w_sampl_diff == 0)
## rm duplicated columns just for checking
dataA <- dataA[-c(37:39)]
array_diff_null <- dataA
save(file = "array_diff_null.RData", array_diff_null,
compress = FALSE)
## Yes, the "js_null" or "js_sampl_null" column is redundant for those which
## are null. And could be obtained for the rest by diff + js but this it is
## simpler to leave it.
###########################################
##
## Genotype-by-genotype data, not averaged over replicate
##
###########################################
rm(data2, tmp, nullm, nullm2)
rm(list = ls())
df <- readRDS("data_no_any.rds")
data <- df$data
columnsExplained <- df$columnsExplained
## Getting the difference w.r.t null
nullm <- dplyr::filter(df$data, method == "null")
## Note
table(df$data$method)/nrow(nullm)
## 15
## where 3 = 3 size_split* 5 replicates
## Recall that in "merge-additional-info.R" we replicated the null for the three
## detections. See around line 156
## detect and size_split and replicate make no difference for null model
## detect and size_split make no difference for null model
## recall no value for size_split or replicate
stopifnot(is.na(nullm$size_split))
stopifnot(is.na(nullm$replicate))
nullmljs <- nullm[nullm$detect == "large", "js"]
nullmsjs <- nullm[nullm$detect == "small", "js"]
nullmujs <- nullm[nullm$detect == "uniform", "js"]
stopifnot(identical(nullmljs, nullmsjs))
stopifnot(identical(nullmljs, nullmujs))
nullm2 <- nullm[nullm$detect == "large",
c("id", "sourceGenotype",
## Next are for checking
"typeLandscape",
"numGenes",
"sourceGenotype_nMut",
## "sourceGenotype_freqInPOM",
"method", ## rename this
## The response to subtract
"js")]
colnames(nullm2)[3:ncol(nullm2)] <- paste0(colnames(nullm2)[3:ncol(nullm2)], "_null")
## rm(nullm)
rm(df)
gc()
data2 <- dplyr::full_join(data, nullm2, by = c("id", "sourceGenotype"))
tmp <- dplyr::left_join(data, nullm2, by = c("id", "sourceGenotype"))
## checks
stopifnot(nrow(data) == nrow(data2))
stopifnot(identical(tmp, data2))
rm(tmp)
gc()
stopifnot(table(data2$method_null) == nrow(data))
stopifnot(nrow(data2) == nrow(data))
stopifnot(identical(data2$typeLandscape, data2$typeLandscape_null))
stopifnot(identical(data2$numGenes, data2$numGenes_null))
stopifnot(identical(data2$sourceGenotype_numMuts, data2$sourceGenotype_numMuts_null))
## stopifnot(identical(data2$sourceGenotype_freqInPOM, data2$sourceGenotype_freqInPOM_null))
stopifnot(data2$method_null == "null")
data2$js_diff <- data2$js_null - data2$js
## rm duplicated columns just for checking
data2 <- data2[, -c(59:62)]
stopifnot(dplyr::filter(data2, method == "null")$js_diff == 0)
genotype_diff_null_no_average <- data2
save(file = "genotype_diff_null_no_average.RData",
genotype_diff_null_no_average,
compress = FALSE)
rm(nullm, df, data, nullm2)
rm(list = ls())
gc()
###########################################
##
## Number mutations, over replicate
##
###########################################
rm(list = ls())
dfa <- readRDS("num_mut_statistics_over_replicate.rds")
da <- dfa$data
nullm <- dplyr::filter(da, method == "null")
## Note
table(da$method)/nrow(nullm)
## 3
## where 3 = 3 size_split
## detect makes no difference for js_w_real, but makes a difference
## for js_w_sampl
## recall no value for size_split
## checks
stopifnot(is.na(nullm$size_split))
nullmljs <- nullm[nullm$detect == "large", "js_w_real"]
nullmsjs <- nullm[nullm$detect == "small", "js_w_real"]
nullmujs <- nullm[nullm$detect == "uniform", "js_w_real"]
stopifnot(identical(nullmljs, nullmsjs))
stopifnot(identical(nullmljs, nullmujs))
nullmljs <- nullm[nullm$detect == "large", "js_w_sampl"]
nullmsjs <- nullm[nullm$detect == "small", "js_w_sampl"]
nullmujs <- nullm[nullm$detect == "uniform", "js_w_sampl"]
stopifnot(!identical(nullmljs, nullmsjs))
stopifnot(!identical(nullmljs, nullmujs))
nullm2 <- nullm[,
c("id", "sourceGenotype_nMut",
"detect",
## Next are for checking
"typeLandscape",
"numGenes",
"method", ## rename this
## The response to subtract
"js_w_real", "js_w_sampl")]
colnames(nullm2)[4:ncol(nullm2)] <-
paste0(colnames(nullm2)[4:ncol(nullm2)], "_null")
dataA <- dplyr::full_join(da, nullm2, by = c("id", "sourceGenotype_nMut", "detect"))
tmp <- dplyr::left_join(da, nullm2, by = c("id", "sourceGenotype_nMut", "detect"))
## checks
stopifnot(identical(tmp, dataA))
rm(tmp)
gc()
stopifnot(table(dataA$method_null) == nrow(da))
stopifnot(nrow(dataA) == nrow(da))
stopifnot(identical(dataA$typeLandscape, dataA$typeLandscape_null))
stopifnot(identical(dataA$numGenes, dataA$numGenes_null))
stopifnot(dataA$method_null == "null")
dataA$js_w_real_diff <- dataA$js_w_real_null - dataA$js_w_real
dataA$js_w_sampl_diff <- dataA$js_w_sampl_null - dataA$js_w_sampl
stopifnot(dplyr::filter(dataA, method == "null")$js_w_real_diff == 0)
stopifnot(na.omit(dplyr::filter(dataA, method == "null")$js_w_sampl_diff) == 0)
## rm duplicated columns just for checking
dataA <- dataA[-c(38:40)]
num_mut_diff_null <- dataA
save(file = "num_mut_diff_null.RData", num_mut_diff_null,
compress = FALSE)
date()