-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 20.4 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
nrow(pca_plsda$data_PLSDA_VIP_filtered_features)
# take out the expression matrix, change the name to the major protein id, for downstream statistics
df_pg_exp <- df_pg_exp_GSEA
pvalues_anova <- matrix_PostHoc(df_pg_exp,meta$Experiment_group)
df_pg_exp_p <- cbind(pvalues_anova, df_pg_exp_GSEA)
df_pg_exp_p_filtered <- df_pg_exp_p[which(!is.na(df_pg_exp_p$p_PostHoc_pairs)),]
datatable(as.matrix(df_pg_exp_p_filtered))
meta$Experiment_group
matrix_fold_change<-function(data,group_info,group_name1,group_name2) {
group1<-which(group_info==group_name1)
group2<-which(group_info==group_name2)
fold_change<-apply(data,1,function(x) sum(x[group1])/sum(x[group2]))
return(fold_change)
}
matrix_fold_change<-function(data,group_info,group_name1,group_name2) {
group1<-which(group_info==group_name1)
group2<-which(group_info==group_name2)
fold_change<-apply(data,1,function(x) sum(x[group1])/sum(x[group2]))
return(fold_change)
}
fold_change_CK_PCK <- matrix_fold_change(log10(df_pg_exp),meta$Experiment_group,"CK","PCK")
p_CK_PCK <- matrix_ttest(df_pg_exp,meta$Experiment_group,"CK","PCK")
p_CK_PCK_adjusted <- p.adjust(p_CK_PCK,method = "fdr")
fold_change_CK_HC <- matrix_fold_change(df_pg_exp,meta$Experiment_group,"CK","HC")
p_CK_HC <- matrix_ttest(log10(df_pg_exp),meta$Experiment_group,"CK","HC")
p_CK_HC_adjusted <- p.adjust(p_CK_HC,method = "fdr")
fold_change_HC_PHC <- matrix_fold_change(df_pg_exp,meta$Experiment_group,"HC","PHC")
p_HC_PHC <- matrix_ttest(log10(df_pg_exp),meta$Experiment_group,"HC","PHC")
p_HC_PHC_adjusted <- p.adjust(p_HC_PHC,method = "fdr")
fold_change_PCK_PHC <- matrix_fold_change(df_pg_exp,meta$Experiment_group,"PCK","PHC")
p_PCK_PHC <- matrix_ttest(log10(df_pg_exp),meta$Experiment_group,"PCK","PHC")
p_PCK_PHC_adjusted <- p.adjust(p_PCK_PHC,method = "fdr")
df_pg_.exp_p_CK_PCK <- cbind(fold_change_CK_PCK,p_CK_PCK_adjusted,df_pg_exp_GSEA)
significant_CK_PCK <- df_pg_exp_p_CK_PCK[p_CK_PCK_adjusted < 0.05 ,]
df_pg_exp_p_CK_PCK <- cbind(fold_change_CK_PCK,p_CK_PCK_adjusted,df_pg_exp_GSEA)
significant_CK_PCK <- df_pg_exp_p_CK_PCK[p_CK_PCK_adjusted < 0.05 ,]
datatable(df_pg_exp_p_CK_PCK)
View(significant_CK_PCK)
p_CK_PCK_adjusted
range(p_CK_PCK_adjusted)
range(p_CK_HC_adjusted)
range(p_HC_PHC_adjusted)
range(p_PCK_PHC_adjusted)
reference_value <- fold_change_CK_PCK # use the fold change of T1/T3
names(reference_value) <- df_pg_exp_GSEA$Proteins
names(reference_value) <- df_pg_ID_exp_GSEA$ID
reference_value
reference_value_ranked <- sort(reference_value, decreasing = TRUE) # for gsea test
reference_value_filtered <- reference_value_ranked[reference_value_ranked >1] #filtered value
# for classical erichment analysis
reference_genes <- names(reference_value_filtered)
length(reference_genes)
reference_genes
reference_genes_all <- df_pg_ID_exp_GSEA$ID
#human: "org.Hs.eg.db" ; mouse:"org.Mm.eg.db"
OrgDb <- "org.Bt.eg.db"
keyType <- "UNIPROT"
OrgDb <- "org.Bt.eg.db"
keyType <- "UNIPROT"
# human: "hsa"; mouse: "mmu"
# https://www.genome.jp/kegg/catalog/org_list.html for full list
OrgDb_kegg <- "bta" # cow
keyType_kegg <-"uniprot"
?enrichPathway
enrichPathway
OrgDb <- "org.Bt.eg.db"
keyType <- "UNIPROT"
# human: "hsa"; mouse: "mmu"
# https://www.genome.jp/kegg/catalog/org_list.html for full list
OrgDb_kegg <- "bta" # cow
keyType_kegg <-"uniprot"
# human: "human", mouse: "mouse"
organism_pathway <- "bovine" # or cow?
p.adjust_cutoff <- 0.01
# GO enichment analysis/ over reprentative analysis
result_enrichGO_CC <- enrichGO(gene = reference_genes,
keyType = keyType,
#universe = names(geneList),
OrgDb = OrgDb,
ont = "CC",
pAdjustMethod = "BH",
pvalueCutoff = p.adjust_cutoff,
qvalueCutoff = 0.05,
readable = TRUE)
# take over the over-reprentation /enrichment result
result_enrichment <- result_enrichGO_CC
# convert the entrezid to gene name for better visualization
result_enrichment <- setReadable(result_enrichment, OrgDb, keyType)
datatable(result_enrichment@result)
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
barplot(result_enrichment)
}
#datatable(pca_plsda$data_PLSDA_VIP_filtered_features)
datatable(df_pg_ID_exp_GSEA[as.numeric(row.names(pca_plsda$data_PLSDA_VIP_filtered_features)),])
#datatable(pca_plsda$data_PLSDA_VIP_filtered_features)
datatable(df_pg[as.numeric(row.names(pca_plsda$data_PLSDA_VIP_filtered_features)),])
pca_plsda$data_PLSDA_VIP_filtered_features
p.adjust_cutoff <- 0.5
result_GO_GSEA_CC <- gseGO(geneList = reference_value_ranked,
OrgDb = OrgDb,
keyType = keyType,
ont = "CC",
nPerm = 1000,
minGSSize = 5,
maxGSSize = 500,
pvalueCutoff = p.adjust_cutoff,
verbose = TRUE)
p.adjust_cutoff
reference_value_ranked
OrgDb
keyType
result_GSEA <- result_GO_GSEA_CC
length(which(p_CK_PCK_adjusted
)
# setup the two groups to compare
groups_VS <- c("CK", "PCK")
# setup the two groups to compare
groups_VS <- c("CK", "PCK")
# setup the two groups to compare
groups_VS <- c("CK", "PCK")
groups_VS
fold_change_VS <- matrix_fold_change(log10(df_pg_exp),meta$Experiment_group,groups_VS[1],groups_VS[2])
p_VS <- matrix_ttest(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p_VS_adjusted <- p.adjust(p_VS,method = "fdr")
df_pg_exp_p_VS <- cbind(fold_change_VS,p_VS_adjusted,df_pg_exp_GSEA)
View(df_pg_exp_p_VS)
significant_VS <- df_pg_exp_p_VS[p_VS_adjusted < 0.05 ,]
datatable(df_pg_exp_p_VS)
reference_value <- fold_change_VS # use the fold change of T1/T3
groups_VS[1]
groups_VS[2]
datatable(significant_VS)
dim(df_pg)
dim(df_pg_exp)
fold_change_VS <- matrix_fold_change(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
meta$Experiment_group
which(meta$Experiment_group==groups_VS[1])
which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2])
c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))
df_pg_exp_p_VS <- cbind(fold_change,p,p_adjusted,df_pg_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
fold_change <- matrix_fold_change(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p <- matrix_ttest(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p_adjusted <- p.adjust(p,method = "fdr")
df_pg_exp_p_VS <- cbind(fold_change,p,p_adjusted,df_pg_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
significant_VS <- df_pg_exp_p_VS[p_VS_adjusted < 0.05 ,]
datatable(significant_VS)
p <- matrix_ttest(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p_adjusted <- p.adjust(p,method = "fdr")
range(p_adjusted)
datatable(df_pg_exp_p_VS)
df_pg_exp_p_VS <- cbind(fold_change,p,p_adjusted,df_pg_ID_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
df_pg_exp_p_VS <- cbind(fold_change,p,p_adjusted,df_pg_ID_exp_GSEA[,c(1,which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
datatable(df_pg_exp_p_VS)
# rank the table based on the p value
t <- df_pg_exp_p_VS[order(df_pg_exp_p_VS$p_adjusted),]
data.table(t)
datatable(t)
df_pg_exp_p_VS <- cbind(fold_change,p,p_adjusted,df_pg_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
rownames(df_pg_exp_p_VS) <- df_pg_ID_exp_GSEA[1,]
dim(df_pg_exp_p_VS)
dim(df_pg_ID_exp_GSEA)
rownames(df_pg_exp_p_VS)
rownames(df_pg_exp_p_VS) <- df_pg_ID_exp_GSEA[,1]
row.names(df_pg_exp_p_VS) <- df_pg_ID_exp_GSEA[,1]
row.names(df_pg_exp_p_VS)
dim(df_pg_exp_p_VS)
df_pg_ID_exp_GSEA[,1]
row.names(df_pg_exp_p_VS) <- as.data.frame(df_pg_ID_exp_GSEA)[,1]
datatable(df_pg_exp_p_VS)
# rank the table based on the p value
t <- df_pg_exp_p_VS[order(df_pg_exp_p_VS$p_adjusted),]
datatable(t)
significant_VS
head(T)
head(t)
View(t)
significant_VS <- df_pg_exp_p_VS[df_pg_exp_p_VS$p_adjusted < 0.05,]
significant_VS
# rank the table based on the p value
df_pg_exp_p_VS <- df_pg_exp_p_VS[order(df_pg_exp_p_VS$p_adjusted),]
significant_VS <- df_pg_exp_p_VS[df_pg_exp_p_VS$p_adjusted < 0.05,]
significant_VS
View(df_pg_exp_p_VS)
range(p_adjusted)
fold_change <- matrix_fold_change(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p <- matrix_ttest(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p_adjusted <- p.adjust(p,method = "fdr")
df_pg_exp_ttest <- cbind(fold_change,p,p_adjusted,df_pg_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
View(df_pg_exp_ttest)
row.names(df_pg_exp_ttest) <- as.data.frame(df_pg_ID_exp_GSEA)[,1]
reference_genes
reference_value <- fold_change # use the fold change of
names(reference_value) <- df_pg_ID_exp_GSEA$ID
reference_value_ranked <- sort(reference_value, decreasing = TRUE) # for gsea test
reference_value_filtered <- reference_value_ranked[reference_value_ranked >1] #filtered value
length(reference_value_filtered)
View(df_pg_exp_ttest_p_001)
df_pg_exp_ttest_p_001 <- df_pg_exp_ttest[df_pg_exp_ttest$p < 0.01,]
View(df_pg_exp_ttest_p_001)
df_pg_exp_ttest_p_05 <- df_pg_exp_ttest[df_pg_exp_ttest$p < 0.05,]
View(df_pg_exp_ttest_p_05)
View(df_pg_exp_ttest_p_05)
df_pg_exp_ttest <- df_pg_exp_ttest[order(df_pg_exp_ttest$p_adjusted),]
df_pg_exp_ttest_p_05 <- df_pg_exp_ttest[df_pg_exp_ttest$p < 0.05,]
datatable(df_pg_exp_ttest_p_05)
# for classical erichment analysis
reference_genes <- names(df_pg_exp_ttest_p_05)
reference_genes
# for classical erichment analysis
reference_genes <- names(df_pg_exp_ttest_p_05)
reference_genes
df_pg_exp_ttest_p_05
# for classical erichment analysis
reference_genes <- row.names(df_pg_exp_ttest_p_05)
reference_genes
p.adjust_cutoff <- 0.5
result_KEGG_module_enrich <- enrichMKEGG(gene = reference_genes,
organism = OrgDb_kegg,
keyType = keyType_kegg,
pvalueCutoff = p.adjust_cutoff,
pAdjustMethod = "BH",
minGSSize = 10,
maxGSSize = 500,
qvalueCutoff = 0.2)
# take over the over-reprentation /enrichment result
result_enrichment <- result_KEGG_module_enrich
# read-in the expression file
df_pg <- read_tsv("Sample20-ProteinGroups(2)(1).txt", col_names = TRUE)
# for consistency,change the name
df_pg_exp_GSEA <- df_pg[,c(-1,-2,-3)]
df_pg_ID_exp_GSEA <- df_pg[,c(-2,-3)]
#setup the metadata
meta <- read.delim("Experiment_group.txt",header = FALSE)
colnames(meta) <- c("sample_Name", "Experiment_group")
# setup the two groups to compare
groups_VS <- c("CK", "HC")
matrix_fold_change<-function(data,group_info,group_name1,group_name2) {
group1<-which(group_info==group_name1)
group2<-which(group_info==group_name2)
fold_change<-apply(data,1,function(x) sum(x[group1])/sum(x[group2]))
return(fold_change)
}
fold_change_CK_PCK <- matrix_fold_change(log10(df_pg_exp),meta$Experiment_group,"CK","PCK")
p_CK_PCK <- matrix_ttest(df_pg_exp,meta$Experiment_group,"CK","PCK")
p_CK_PCK_adjusted <- p.adjust(p_CK_PCK,method = "fdr")
fold_change_CK_HC <- matrix_fold_change(df_pg_exp,meta$Experiment_group,"CK","HC")
p_CK_HC <- matrix_ttest(log10(df_pg_exp),meta$Experiment_group,"CK","HC")
p_CK_HC_adjusted <- p.adjust(p_CK_HC,method = "fdr")
fold_change_HC_PHC <- matrix_fold_change(df_pg_exp,meta$Experiment_group,"HC","PHC")
p_HC_PHC <- matrix_ttest(log10(df_pg_exp),meta$Experiment_group,"HC","PHC")
p_HC_PHC_adjusted <- p.adjust(p_HC_PHC,method = "fdr")
fold_change_PCK_PHC <- matrix_fold_change(df_pg_exp,meta$Experiment_group,"PCK","PHC")
p_PCK_PHC <- matrix_ttest(log10(df_pg_exp),meta$Experiment_group,"PCK","PHC")
p_PCK_PHC_adjusted <- p.adjust(p_PCK_PHC,method = "fdr")
# calculate the statistics
fold_change <- matrix_fold_change(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p <- matrix_ttest(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p_adjusted <- p.adjust(p,method = "fdr")
# combine all p value and selected columns together
df_pg_exp_ttest <- cbind(fold_change,p,p_adjusted,df_pg_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
row.names(df_pg_exp_ttest) <- as.data.frame(df_pg_ID_exp_GSEA)[,1]
# rank the table based on the p value
df_pg_exp_ttest <- df_pg_exp_ttest[order(df_pg_exp_ttest$p_adjusted),]
df_pg_exp_ttest_p_05 <- df_pg_exp_ttest[df_pg_exp_ttest$p < 0.05,]
datatable(df_pg_exp_ttest_p_05)
reference_value <- fold_change # use the fold change of
names(reference_value) <- df_pg_ID_exp_GSEA$ID
reference_value_ranked <- sort(reference_value, decreasing = TRUE) # for gsea test
reference_value_filtered <- reference_value_ranked[reference_value_ranked >1] #filtered value
# for classical erichment analysis
reference_genes <- row.names(df_pg_exp_ttest_p_05)
reference_genes_all <- df_pg_ID_exp_GSEA$ID
length(reference_genes)
reference_genes
p.adjust_cutoff <- 0.5
result_KEGG_module_enrich <- enrichMKEGG(gene = reference_genes,
organism = OrgDb_kegg,
keyType = keyType_kegg,
pvalueCutoff = p.adjust_cutoff,
pAdjustMethod = "BH",
minGSSize = 10,
maxGSSize = 500,
qvalueCutoff = 0.2)
# take over the over-reprentation /enrichment result
result_enrichment <- result_KEGG_module_enrich
result_enrichment
# convert the entrezid to gene name for better visualization
result_enrichment <- setReadable(result_enrichment, OrgDb, keyType)
null(result_enrichment)
is.null(result_enrichment)
if(! is.null(result_enrichment)){
result_enrichment <- setReadable(result_enrichment, OrgDb, keyType)
}
pvalueCutoff: `r result_enrichment@pvalueCutoff`
pAdjustMethod: `r result_enrichment@pAdjustMethod`
qvalueCutoff: `r result_enrichment@qvalueCutoff`
organism: `r result_enrichment@organism`
ontology: `r result_enrichment@ontology`
length(reference_genes)
reference_genes
# take over the over-reprentation /enrichment result
result_enrichment <- result_KEGG_module_enrich
result_enrichment
if(! is.null(result_enrichment)){
result_enrichment <- setReadable(result_enrichment, OrgDb, keyType)
}
if(! is.null(result_enrichment)){
datatable(result_enrichment@result)
}
if(! is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
barplot(result_enrichment)
}
}
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
enrichplot::dotplot(result_enrichment)
}
}
result_enrichment@result
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
cnetplot(result_enrichment,categorySize="pvalue", foldChange=reference_value_ranked)
}
}
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
upsetplot(result_enrichment)
heatplot(result_enrichment,foldChange=reference_value_ranked)
}
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
upsetplot(result_enrichment)
heatplot(result_enrichment,foldChange=reference_value_ranked)
}
}
result_enrichGO_CC_local <- enrichGO(gene = reference_genes,
keyType = keyType,
universe = reference_genes_all,
OrgDb = OrgDb,
ont = "CC",
pAdjustMethod = "BH",
pvalueCutoff = p.adjust_cutoff,
qvalueCutoff = 0.5,
readable = TRUE)
# take over the over-reprentation /enrichment result
result_enrichment <- result_enrichGO_CC_local
# convert the entrezid to gene name for better visualization
result_enrichment <- setReadable(result_enrichment, OrgDb, keyType)
result_enrichment
if(!is.null(result_enrichment)){
datatable(result_enrichment@result)
}
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
barplot(result_enrichment)
}
}
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
barplot(result_enrichment)
}
}
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
barplot(result_enrichment)
}
barplot(result_enrichment)
result_enrichment@result
is.null(result_enrichment)
!is.null(result_enrichment)
any(result_enrichment@result$p.adjust
)
result_enrichment@result$p.adjust
result_enrichment@result$p.adjust < p.adjust_cutoff
p.adjust_cutoff
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
cnetplot(result_enrichment,categorySize="pvalue", foldChange=reference_value_ranked)
}
}
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
upsetplot(result_enrichment)
heatplot(result_enrichment,foldChange=reference_value_ranked)
}
}
groups_VS <- c("PCK", "PHC")
groups_VS <- c("PCK", "PHC")
matrix_fold_change<-function(data,group_info,group_name1,group_name2) {
group1<-which(group_info==group_name1)
group2<-which(group_info==group_name2)
fold_change<-apply(data,1,function(x) sum(x[group1])/sum(x[group2]))
return(fold_change)
}
# calculate the statistics
fold_change <- matrix_fold_change(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p <- matrix_ttest(df_pg_exp,meta$Experiment_group,groups_VS[1],groups_VS[2])
p_adjusted <- p.adjust(p,method = "fdr")
# combine all p value and selected columns together
df_pg_exp_ttest <- cbind(fold_change,p,p_adjusted,df_pg_exp_GSEA[,c(which(meta$Experiment_group==groups_VS[1]), which(meta$Experiment_group==groups_VS[2]))])
row.names(df_pg_exp_ttest) <- as.data.frame(df_pg_ID_exp_GSEA)[,1]
# rank the table based on the p value
df_pg_exp_ttest <- df_pg_exp_ttest[order(df_pg_exp_ttest$p_adjusted),]
df_pg_exp_ttest_p_05 <- df_pg_exp_ttest[df_pg_exp_ttest$p < 0.05,]
reference_value <- fold_change # use the fold change of
names(reference_value) <- df_pg_ID_exp_GSEA$ID
reference_value_ranked <- sort(reference_value, decreasing = TRUE) # for gsea test
reference_value_filtered <- reference_value_ranked[reference_value_ranked >1] #filtered value
# for classical erichment analysis
reference_genes <- row.names(df_pg_exp_ttest_p_05)
reference_genes_all <- df_pg_ID_exp_GSEA$ID
# setup the parameter for the enrichment analysis
#human: "org.Hs.eg.db" ; mouse:"org.Mm.eg.db", bovine/cow "org.Bt.eg.db"
OrgDb <- "org.Bt.eg.db"
keyType <- "UNIPROT"
# human: "hsa"; mouse: "mmu"
# https://www.genome.jp/kegg/catalog/org_list.html for full list
OrgDb_kegg <- "bta" # cow
keyType_kegg <-"uniprot"
# human: "human", mouse: "mouse"
organism_pathway <- "bovine" # or cow?
p.adjust_cutoff <- 0.5
# GO enichment analysis/ over reprentative analysis
result_enrichGO_CC_local <- enrichGO(gene = reference_genes,
keyType = keyType,
universe = reference_genes_all,
OrgDb = OrgDb,
ont = "CC",
pAdjustMethod = "BH",
pvalueCutoff = p.adjust_cutoff,
qvalueCutoff = 0.5,
readable = TRUE)
# take over the over-reprentation /enrichment result
result_enrichment <- result_enrichGO_CC_local
result_enrichment
# convert the entrezid to gene name for better visualization
result_enrichment <- setReadable(result_enrichment, OrgDb, keyType)
result_enrichment
if(!is.null(result_enrichment)){
if(any(result_enrichment@result$p.adjust < p.adjust_cutoff)){
upsetplot(result_enrichment)
heatplot(result_enrichment,foldChange=reference_value_ranked)
}
}
!is.null(result_enrichment
)
result_enrichment@result$p.adjust
p.adjust_cutoff
result_enrichment@result$p.adjust < p.adjust_cutoff
sum(result_enrichment@result$p.adjust < p.adjust_cutoff)
if(!is.null(result_enrichment)){
if(sum(result_enrichment@result$p.adjust < p.adjust_cutoff)>1){
upsetplot(result_enrichment)
heatplot(result_enrichment,foldChange=reference_value_ranked)
}
}
setwd("C:/Users/Figeys Lab/Dropbox/Project_R_packages/metalab")
library(metalab)
library(metalab)
library(metalab)
devtools::build()
devtools::install()
knit_with_parameters('C:/Users/Figeys Lab/Dropbox/Project_R_packages/metalab/inst/rmd/input.Rmd', encoding = 'UTF-8')
library(devtools)
devtools::install_github("hrbrmstr/streamgraph")
library(streamgraph)
library(dplyr)
remove.packages("rlang", lib="C:/Program Files/R/R-3.5.1/library")
library("rlang", lib.loc="~/R/win-library/3.5")
library(rlang)
?invisible
library(metalab)
library(metalab)
rmdtext
rmdtext()
?knit2html
?knit2html
library(knitr)
?find_lipid_combo
devtools::load_all(".")
library(metalab)
library(metalab)
?find_lipid_combo
library(metalab)
library(metalab)
?find_lipid_combo
library(metalab)
library(roxygen2)
?find_lipid_combo
?find_lipid_combo
library(metalab)
library(metalab)
?
?find_lipid_combo
setwd("C:/Users/Figeys Lab/Dropbox/Project_MetaLab/openCPU_apps/markdownapp-master/inst/www")
remove_allNA_rows <- function(df){
if(any(apply(df,1,function(x)all(is.na(x))))){ # if there is any all NA rows
df[-which(apply(df,1,function(x)all(is.na(x)))),]
}else{
df
}
# this function can deal with data.frame and data matrix
# note that NA has to be NA, otherwise, precess the data first
}
remove_allNA_columns <- function(df){
if(any(apply(df,2,function(x)all(is.na(x))))){ # if there is any all NA columns
df[,-which(apply(df,2,function(x)all(is.na(x))))]
}else{
df
}
# this function can deal with data.frame and data matrix
# note that NA has to be NA, otherwise, precess the data first
}