-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 25.9 KB
/
.Rhistory
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
arrange(tumor_with_normal, barcode)
part1 <- tumor_with_normal[1,]
part2 <- normal_samples[1,]
part1_tumor <- tumor_with_normal[1,]
part1_normal <- normal_samples[1,]
rm(part1, part2)
part1_tumor <- data.frame(group = "tumor", value = tumor_with_normal[1,-(1:2)])
part1_normal <- data.frame(group = "normal", value = normal_samples[1,-(1:2)])
part1_data <- rbind(part1_tumor, part_)
part1_data <- rbind(part1_tumor, part1_normal)
ggplot(part1_data, aes(x = group, y = value, fill = group)) + geom_boxplot()
ggplot(part1_data, aes(x = group, y=value, fill = group)) + geom_boxplot()
head(part1_data)
part1_tumor <- data.frame(group = "tumor", value = t(tumor_with_normal[1,-(1:2)]))
head(part1_tumor$value)
head(part1_tumor$X1)
tail(part1_tumor$X1)
part1_normal <- data.frame(group = "normal", value = t(normal_samples[1,-(1:2)]))
tail(part1_normal)
tail(part1_t)
tail(part1_tumor)
part1_data <- rbind(part1_tumor, part1_normal)
ggplot(part1_data, aes(x = group, y=X1, fill = group)) + geom_boxplot()
ggplot(part1_data, aes(x = group, y=X1, fill = group)) + geom_boxplot() + ylim(10000)
ggplot(part1_data, aes(x = group, y=X1, fill = group)) + geom_boxplot() + ylim(0,10000)
ggplot(part1_data, aes(x = group, y=X1, fill = group)) + geom_boxplot() + ylim(0,2500)
ggplot(part1_data, aes(x = group, y=X1, fill = group)) + geom_boxplot()
part1_tumor <- data.frame(group = "tumor", part = 1, value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = 1, value = normal_samples[1,-(1:2)])
part2_tumor <- data.frame(group = "tumor", part = 2, value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = 2, value = normal_samples[2,-(1:2)])
part_data <- rbind(part1_tumor, part1_normal, part2_tumor, part2_normal)
ggplot(part_data, aes(x = group, y=X1, fill = group)) + geom_boxplot()
part1_tumor <- data.frame(group = "tumor", part = 1, value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = 1, value = t(normal_samples[1,-(1:2)]))
part2_tumor <- data.frame(group = "tumor", part = 2, value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = 2, value = t(normal_samples[2,-(1:2)]))
part_data <- rbind(part1_tumor, part1_normal, part2_tumor, part2_normal)
ggplot(part_data, aes(x = group, y=X1, fill = group)) + geom_boxplot()
head(part2_normal)
part2_tumor <- data.frame(group = "tumor", part = 2, value = as.matrix(t(tumor_with_normal[2,-(1:2)])))
head(part2_normal)
Value <- t(tumor_with_normal[2,-(1:2)])
part2_tumor <- data.frame(group = "tumor", part = 2, value = Value)
head(part2_normal)
part1_tumor <- data.frame(group = "tumor", part = 1, value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = 1, value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part2_tumor <- data.frame(group = "tumor", part = 2, value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = 2, value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part1_tumor, part1_normal, part2_tumor, part2_normal)
ggplot(part_data, aes(x = group, y= value, fill = group)) + geom_boxplot()
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
tumor_with_normal <- inner_join(tumor_samples, normal_samples, by="barcode")
part1_tumor <- data.frame(group = "tumor", part = "1_t", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1_n", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part2_tumor <- data.frame(group = "tumor", part = "2_t", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2_n", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part1_tumor, part1_normal, part2_tumor, part2_normal)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part_data <- data.frame()
part1_tumor <- data.frame(group = "tumor", part = "1_t", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1_n", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part2_tumor <- data.frame(group = "tumor", part = "2_t", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2_n", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part1_tumor, part1_normal, part2_tumor, part2_normal)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "1_tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "1_normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[2] <- "value"
colnames(part1_tumor)[2] <- "value"
part2_tumor <- data.frame(group = "2_tumor", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "2_normal",value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[2] <- "value"
colnames(part2_tumor)[2] <- "value"
part_data <- rbind(part1_tumor, part1_normal, part2_tumor, part2_normal)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
ggplot(part_data, aes(x = group, y= value, fill = group)) + geom_boxplot()
head(part_data)
tail(part_data)
sum(is.na(part2_tumor))
sum(is.na(part2_normal))
ggplot(part_data, aes(x = group, y= value)) + geom_boxplot()
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "1_tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "1_normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[2] <- "value"
colnames(part1_tumor)[2] <- "value"
part_data <- rbind(part1_tumor, part1_normal) #part2_tumor, part2_normal)
ggplot(part_data, aes(x = group, y= value)) + geom_boxplot()
part1_tumor <- data.frame(group = "tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[2] <- "value"
colnames(part1_tumor)[2] <- "value"
head(part1_normal)
head(part1_tumor)
part1_data <- rbind(part1_normal, part1_tumor)
part2_tumor <- data.frame(group = "tumor", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal",value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[2] <- "value"
colnames(part2_tumor)[2] <- "value"
part2_data <- rbind(part2_normal, part2_tumor)
head(part2_data)
tail(part2_data)
ggplot(data = part1_data, aes(x = group, y = value)) + geom_boxplot()
prdx_tumor <- read.table("BRCA_tumor_PrediXcan-expression.txt", header = TRUE, stringsAsFactors = FALSE)
tumor_samples <- read.table("BRCA_tumor_TCGA-RNAseq-expression.txt", header = TRUE, stringsAsFactors = FALSE)
prdx_normal <- read.table("BRCA_normal_PrediXcan-expression.txt", header = TRUE, stringsAsFactors = FALSE)
normal_samples <- read.table("BRCA_normal_TCGA-RNAseq-expression.txt", header = TRUE, stringsAsFactors = FALSE)
tumor_with_normal <- inner_join(tumor_samples, normal_samples, by="barcode")
tumor_with_normal <- semi_join(tumor_samples, normal_samples, by="barcode")
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[2] <- "value"
colnames(part1_tumor)[2] <- "value"
part1_data <- rbind(part1_normal, part1_tumor)
ggplot(part_data, aes(x = group, y= value)) + geom_boxplot()
ggplot(part1_data, aes(x = group, y= value)) + geom_boxplot()
part1_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
#colnames(part1_normal)[2] <- "value"
#colnames(part1_tumor)[2] <- "value"
part1_data <- rbind(part1_normal, part1_tumor)
ggplot(data = part1_data, aes(x = part, y = value)) + geom_boxplot()
head(part1_data)
part1_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[2] <- "value"
colnames(part1_tumor)[2] <- "value"
part1_data <- rbind(part1_normal, part1_tumor)
ggplot(part_data1, aes(x = part, y= value, fill = group)) + geom_boxplot()
ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
head(part1_data)
part1_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part1_data <- rbind(part1_normal, part1_tumor)
ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
#ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part2_tumor <- data.frame(group = "tumor", part = "2-tumor", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2-normal", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
#ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part2_tumor <- data.frame(group = "tumor", part = "2-tumor", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2-normal", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part2_normal, part2_tumor)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
#ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part2_tumor <- data.frame(group = "tumor", part = "2-tumor", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2-normal", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part_data, part2_normal, part2_tumor)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1-tumor", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1-normal", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
#ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part2_tumor <- data.frame(group = "tumor", part = "2-tumor", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2-normal", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part_data, part2_normal, part2_tumor)
part3_tumor <- data.frame(group = "tumor", part = "3-tumor", value = t(tumor_with_normal[3,-(1:2)]))
part3_normal <- data.frame(group = "normal", part = "3-normal", value = t(normal_samples[3,-(1:2)]))
colnames(part3_normal)[3] <- "value"
colnames(part3_tumor)[3] <- "value"
part_data <- rbind(part_data, part3_normal, part3_tumor)
ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
bp <- ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
bp + ylim(0, 2500)
bp + ylim(-10, 2500)
bp + ylim(0, 10000)
bp + facet_grid(part ~ .)
bp + facet_grid(part)
bp + facet_grid(part ~ .)
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "1", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "1", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
#ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part2_tumor <- data.frame(group = "tumor", part = "2", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "2", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part_data, part2_normal, part2_tumor)
part3_tumor <- data.frame(group = "tumor", part = "3", value = t(tumor_with_normal[3,-(1:2)]))
part3_normal <- data.frame(group = "normal", part = "3", value = t(normal_samples[3,-(1:2)]))
colnames(part3_normal)[3] <- "value"
colnames(part3_tumor)[3] <- "value"
part_data <- rbind(part_data, part3_normal, part3_tumor)
bp <- ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
bp
bp + facet_grid(part ~ .)
bp + facet_wrap(part ~ .)
bp + facet_wrap(group)
bp + facet_wrap(~ part)
part_data <- data.frame(stringsAsFactors = FALSE)
part1_tumor <- data.frame(group = "tumor", part = "participant1", value = t(tumor_with_normal[1,-(1:2)]))
part1_normal <- data.frame(group = "normal", part = "participant1", value = t(normal_samples[1,-(1:2)]))
colnames(part1_normal)[3] <- "value"
colnames(part1_tumor)[3] <- "value"
part_data <- rbind(part1_normal, part1_tumor)
#ggplot(part1_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
part2_tumor <- data.frame(group = "tumor", part = "participant2", value = t(tumor_with_normal[2,-(1:2)]))
part2_normal <- data.frame(group = "normal", part = "participant2", value = t(normal_samples[2,-(1:2)]))
colnames(part2_normal)[3] <- "value"
colnames(part2_tumor)[3] <- "value"
part_data <- rbind(part_data, part2_normal, part2_tumor)
part3_tumor <- data.frame(group = "tumor", part = "participant3", value = t(tumor_with_normal[3,-(1:2)]))
part3_normal <- data.frame(group = "normal", part = "participant3", value = t(normal_samples[3,-(1:2)]))
colnames(part3_normal)[3] <- "value"
colnames(part3_tumor)[3] <- "value"
part_data <- rbind(part_data, part3_normal, part3_tumor)
bp <- ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
bp
bp + facet_wrap(~ part)
bp
bp + ylim (0, 10000)
bp + ylim (0, 100000)
bp + ylim (0, 25000)
bp + ylim (0, 2500)
bp + ylim (0, 2500) + xlab(NULL)
part4_tumor <- data.frame(group = "tumor", part = "participant4", value = t(tumor_with_normal[4,-(1:2)]))
part4_normal <- data.frame(group = "normal", part = "participant4", value = t(normal_samples[4,-(1:2)]))
colnames(part4_normal)[3] <- "value"
colnames(part4_tumor)[3] <- "value"
part_data <- rbind(part_data, part4_normal, part4_tumor)
bp <- ggplot(part_data, aes(x = part, y= value, fill = group)) + geom_boxplot()
bp + ylim(0, 2500) + xlab(NULL)
tail(part4_tumor)
tail(part4_normal)
bp <- ggplot(plot.data, aes(x=group, y=value, fill=group)) + geom_boxplot()
bp
fit
x < c(0,1,2),c(1:3),
x <- c(0,1,2),c(1:3),
x <- c(0,1,2)
prdx_tumor <- arrange(prdx_tumor, barcode)
tumor_samples <- arrange(tumor_samples, barcode)
##comment out for tumor or normal
prdx_expression <- prdx_tumor[,-(1:2)]
#prdx_expression <- prdx_normal[,-(1:2)]
tumor_expression <- tumor_samples[,-(1:2)]
#tumor_expression <- normal_samples[,-(1:2)]
## Remove columns where std dev == 0
prdx_expression <- prdx_expression[, sapply(prdx_expression,function(x) { sd(x) != 0} )]
tumor_expression <- tumor_expression[, sapply(tumor_expression, function(x) { sd(x) != 0} )]
genes_in_prdx <- colnames(prdx_expression)
genes_in_RNAseq <- colnames(tumor_expression)
TCGA_pca <- prcomp(tumor_expression, center = TRUE, scale. = TRUE)
lm.beta <- function (MOD) {
b <- summary(MOD)$coef[-1, 1]
sx <- sd(as.matrix(MOD$model[-1]))
sy <- sd(as.matrix(MOD$model[1]))
beta <- b * sx/sy
return(beta)
}
fit <- lm(tumor_expression$CFH ~ prdx_expression$CFH)
summary(fit)$coef
summary(fit)$coef[-1,1]
fit2 <- lm(tumor_expression$CFH ~ prdx_expression$CFH + TCGA_pca$x[,1])
summary(fit)$coef
summary(fit2)$coef[-1,1]
summary(fit2)$coef
summary(fit2)$coef[2,1]
summary(fit)$coef[-1,1]
summary(fit2)$coef[-1,1]
fit$model
fit$model[-1]
fit2$model[-1]
fit2$model[1]
fit2$model[-1]
fit2$model
summary(fit2)$coef
summary(fit2)$coef[-1,1]
summary(fit)$coef[-1,1]
summary(fit)$coef
summary(fit2)$coef
summary(fit2)$coef[2,1]
summary(fit)$coef[2,1]
head(fit$model[2])
head(fit$model[-1])
head(fit2$model[-1])
head(fit2$model[2])
head(fit2$model[1])
head(fit$model[1])
lm.beta <- function (MOD) {
b <- summary(MOD)$coef[2, 1]
sx <- sd(MOD$model[2])
sy <- sd(MOD$model[1])
beta <- b * sx/sy
return(beta)
}
lm.beta(fit)
lm.beta <- function (MOD) {
b <- summary(MOD)$coef[2, 1]
sx <- sd(as.matrix(MOD$model[2]))
sy <- sd(as.matrix(MOD$model[1]))
beta <- b * sx/sy
return(beta)
}
lm.beta(fit)
lm.beta(fit2)
fit2 <- lm(tumor_expression$CFH ~ prdx_expression$CFH + TCGA_pca$x[,1] + TCGA_pca$x[,2] + TCGA_pca$x[,3])
fit3 <- lm(tumor_expression$CFH ~ prdx_expression$CFH + TCGA_pca$x[,1] + TCGA_pca$x[,2] + TCGA_pca$x[,3])
lm.beta(fit3)
summary(fit3)$coef
summary(fit3)$coef[2,3]
summary(fit3)$coef[2,1]
fit3$model[2]
head(fit3$model[2])
head(fit3$model[1])
c(1:150)
##comment out for tumor or normal
prdx_expression <- prdx_tumor[,-(1:2)]
#prdx_expression <- prdx_normal[,-(1:2)]
tumor_expression <- tumor_samples[,-(1:2)]
#tumor_expression <- normal_samples[,-(1:2)]
## Remove columns where std dev == 0
prdx_expression <- prdx_expression[, sapply(prdx_expression,function(x) { sd(x) != 0} )]
tumor_expression <- tumor_expression[, sapply(tumor_expression, function(x) { sd(x) != 0} )]
genes_in_prdx <- colnames(prdx_expression)
genes_in_RNAseq <- colnames(tumor_expression)
TCGA_pca <- prcomp(tumor_expression, center = TRUE, scale. = TRUE)
lm.beta <- function (MOD) {
b <- summary(MOD)$coef[2, 1]
sx <- sd(as.matrix(MOD$model[2]))
sy <- sd(as.matrix(MOD$model[1]))
beta <- b * sx/sy
return(beta)
}
all_pc_list <- list()
for (i in c(1:150)){
assign(paste0("PC",i), TCGA_pca$x[,i])
all_pc_list <- c(all_pc_list, paste0("PC",i))
}
lm_fits <- data.frame()
## First time no PCs
for (gene in genes_in_prdx){
if (gene %in% genes_in_RNAseq){
fit <- lm(as.formula(paste0("tumor_expression[[gene]] ~ prdx_expression[[gene]] + ",all_pc_list)))
beta <- lm.beta(fit)
pvalue <- summary(fit)$coefficients[2,4]
Rsquared <- summary(fit)$r.squared
lm_fits <- rbind(lm_fits, data.frame(gene, beta, Rsquared, pvalue))
}
}
adj_pvalue <- p.adjust(lm_fits$pvalue, method = "BH")
lm_fits <- cbind(lm_fits, adj_pvalue)
write.table(lm_fits, file = "BRCA_Tumor_linearModel_150PC_03142016.txt", col.names = TRUE, row.names = FALSE, quote = FALSE)
beep(3)
estimate <- coef(summary(fit3))
estimate
coef(summary(fit3))
coef(summary(fit3))[2,1]
library(beepr)
lm_fits <- data.frame()
## First time no PCs
for (gene in genes_in_prdx){
if (gene %in% genes_in_RNAseq){
fit <- lm(as.formula(paste0("tumor_expression[[gene]] ~ prdx_expression[[gene]] + ",all_pc_list)))
estimate <- coef(summary(fit))[2,1]
pvalue <- summary(fit)$coefficients[2,4]
Rsquared <- summary(fit)$r.squared
lm_fits <- rbind(lm_fits, data.frame(gene, estimate, Rsquared, pvalue))
}
}
adj_pvalue <- p.adjust(lm_fits$pvalue, method = "BH")
lm_fits <- cbind(lm_fits, adj_pvalue)
write.table(lm_fits, file = "BRCA_Tumor_linearModel_150PC_03142016.txt", col.names = TRUE, row.names = FALSE, quote = FALSE)
beep(3)
##comment out for tumor or normal
#prdx_expression <- prdx_tumor[,-(1:2)]
prdx_expression <- prdx_normal[,-(1:2)]
#tumor_expression <- tumor_samples[,-(1:2)]
tumor_expression <- normal_samples[,-(1:2)]
## Remove columns where std dev == 0
prdx_expression <- prdx_expression[, sapply(prdx_expression,function(x) { sd(x) != 0} )]
tumor_expression <- tumor_expression[, sapply(tumor_expression, function(x) { sd(x) != 0} )]
genes_in_prdx <- colnames(prdx_expression)
genes_in_RNAseq <- colnames(tumor_expression)
TCGA_pca <- prcomp(tumor_expression, center = TRUE, scale. = TRUE)
all_pc_list <- list()
for (i in c(1:8)){
assign(paste0("PC",i), TCGA_pca$x[,i])
all_pc_list <- c(all_pc_list, paste0("PC",i))
}
lm_fits <- data.frame()
## First time no PCs
for (gene in genes_in_prdx){
if (gene %in% genes_in_RNAseq){
fit <- lm(as.formula(paste0("tumor_expression[[gene]] ~ prdx_expression[[gene]] + ",all_pc_list)))
estimate <- coef(summary(fit))[2,1]
pvalue <- summary(fit)$coefficients[2,4]
Rsquared <- summary(fit)$r.squared
lm_fits <- rbind(lm_fits, data.frame(gene, estimate, Rsquared, pvalue))
}
}
adj_pvalue <- p.adjust(lm_fits$pvalue, method = "BH")
lm_fits <- cbind(lm_fits, adj_pvalue)
write.table(lm_fits, file = "BRCA_Normal_linearModel_8C_03142016.txt", col.names = TRUE, row.names = FALSE, quote = FALSE)
beep(3)
normal_pc <- read.table("BRCA_Normal_linearModel_8C_03142016.txt", header = TRUE, stringsAsFactors = FALSE)
head(normal_pc)
normal_pc <- read.table("BRCA_Normal_linearModel_8C_03142016.txt", header = TRUE, stringsAsFactors = FALSE)
norm_sigP <- filter(normal_pc, estimated < 0.05)
tumor_pc <- read.table("BRCA_Tumor_linearModel_150PC_03142016.txt", header = TRUE, stringsAsFactors = FALSE)
tum_sigP <- filter(tumor_pc, estimate < 0.05)
norm_sigP <- filter(normal_pc, estimate < 0.05)
tum_sigP <- filter(tumor_pc, estimate < 0.05)
norm_sigP <- filter(normal_pc, adj_pvalue < 0.05)
tum_sigP <- filter(tumor_pc, adj_pvalue < 0.05)
# Make individual data frames
norm_est <- data.frame(group = "normal", value = norm_sigP$estimate)
tum_est <- data.frame(group = "tumor", value = tum_sigP$estimate)
# Combine into one long data frame
plot.data <- rbind(norm_est, tum_est)
bp <- ggplot(plot.data, aes(x=group, y=value, fill=group)) + geom_boxplot()
bp
bp + ylim(-10,200)
# Make individual data frames
norm_est <- data.frame(group = "normal", estimate = norm_sigP$estimate)
tum_est <- data.frame(group = "tumor", estimate = tum_sigP$estimate)
# Combine into one long data frame
plot.data <- rbind(norm_est, tum_est)
bp <- ggplot(plot.data, aes(x=group, y=estimate, fill=group)) + geom_boxplot()
bp + ylim(-10,200)
wilcox.test(norm_est$estimate, tum_est$estimate, paired=FALSE)
bp
bp + y lim(-100, 500)
bp + ylim(-100, 500)
bp + ylim(-100, 1000)
bp + ylim(-200, 1000)
mean(norm_sigP$estimate)
mean(tum_sigP$estimate)
all_pc_list
setwd("~/ECEV-final-project-master")
source("All_timepts_vehremoved.R")
together_timepoints("Data.csv")
together_timepoints("Data.csv", "Template_1V4.csv", "Title", "new.txt")
source("All_timepts_vehremoved.R")
together_timepoints("Data.csv", "Template_1V4.csv", "Title", "new.txt")
together_timepoints("Data.csv", "Template_1V4.csv", "Title", "new")
setwd("~/GitHub/Final-project-coding")
together_timepoints("Data.csv", "Template.csv", "Title", "new")
print(graph)
together_timepoints("Data.csv", "Template.csv", "Title", "new")
source("All_timepts_vehremoved.R")
together_timepoints("Data.csv", "Template.csv", "Title", "new")
setwd("~/")
setwd("~/Huang Lab/TCGA PrediXcan/PrediXcan-TCGA_Results")
source('~/Huang Lab/TCGA PrediXcan/PrediXcan-TCGA_Results/R_scripts/plot_onePC_result.R')
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "estimate")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "estimate")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_8PC_03142016.txt","LinearModel_results/BRCA_Tumor_linearModel_150PC_03142016.txt","estimate")
source('~/Huang Lab/TCGA PrediXcan/PrediXcan-TCGA_Results/R_scripts/plot_onePC_result.R')
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_8PC_03142016.txt","LinearModel_results/BRCA_Tumor_linearModel_150PC_03142016.txt","estimate")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "estimate")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "Rsquared")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_8PC_03142016.txt","LinearModel_results/BRCA_Tumor_linearModel_150PC_03142016.txt","Rsquared")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "Rsquared")
source('~/Huang Lab/TCGA PrediXcan/PrediXcan-TCGA_Results/R_scripts/plot_onePC_result.R')
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "Rsquared")
source('~/Huang Lab/TCGA PrediXcan/PrediXcan-TCGA_Results/R_scripts/plot_onePC_result.R')
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_noPCs_03172016.txt", "LinearModel_results/BRCA_Tumor_linearModel_noPCs_03172016.txt", "Rsquared")
plot_lm_results("LinearModel_results/BRCA_Normal_linearModel_8PC_03142016.txt","LinearModel_results/BRCA_Tumor_linearModel_150PC_03142016.txt","Rsquared")