This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGO_analysis.R
64 lines (56 loc) · 1.57 KB
/
GO_analysis.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
# Not working
setwd("~/Documents/IFN_enhancer/R/")
load(file = "Data/deg_matrix_direction.RData")
lab <- which(substring(rownames(deg_matrix_direction), 1, 12) == "MetaEnhancer")
mat <- deg_matrix_direction[-lab, ]
# Convert gene symbol to Entrez ID
library(org.Hs.eg.db)
eg <- as.list(org.Hs.egALIAS2EG)
eg <- eg[!is.na(eg)]
eg_all <- NULL
for (i in 1:length(eg)) {
for (j in eg[[i]]) {
eg_all <- c(eg_all, j)
}
}
eg_all <- unique(eg_all)
rm_list <- NULL
eg_list <- NULL
for (i in 1:nrow(mat)) {
tp <- which(names(eg) == rownames(mat)[i])
if (length(tp) == 1) {
eg_list <- c(eg_list, eg[[tp]][1])
}
else {
rm_list <- c(rm_list, i)
}
}
mat <- mat[-rm_list, ]
## Create table
tp <- mat[, 5]
tp[tp != 1] <- 0
tp <- as.factor(tp)
names(tp) <- eg_list
up <- tp[tp == 1]
names(up) <- eg_list[tp == 1]
g <- rep(0, length(eg_all))
bg <- factor(bg, levels = c(0, 1))
names(bg) <- eg_all
bg[names(up)] <- 1
sampleGOdata <- new("topGOdata",
description = "Simple session", ontology = "BP",
allGenes = bg, geneSel = up,
nodeSize = 10, # Min. no. of genes annotated to a GO
annot = annFUN.org, mapping = "org.Hs.eg.db"
)
## Run test
resultFisher <- runTest(sampleGOdata, algorithm = "classic", statistic = "fisher")
resultKS <- runTest(sampleGOdata, algorithm = "classic", statistic = "ks")
resultKS.elim <- runTest(sampleGOdata, algorithm = "elim", statistic = "ks")
## Summarize data in table
allRes <- GenTable(sampleGOdata,
classicFisher = resultFisher,
classicKS = resultKS, elimKS = resultKS.elim,
orderBy = "elimKS", ranksOf = "classicFisher", topNodes = 10
)
allRes