-
Notifications
You must be signed in to change notification settings - Fork 1
/
getGO.R
48 lines (43 loc) · 1.31 KB
/
getGO.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
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
if (length(args)==0) {
stop("At least one argument must be supplied (input file).n", call.=FALSE)
}
library("GOstats")
library("annotate")
getMFAnc <- function(interm, goLevel){
for (i in as.list(GOMFANCESTOR)[interm][[1]] ){
numParents <- length(as.list(GOMFANCESTOR)[i][[1]])
if (numParents == goLevel) {
return(i)
}
}
}
getBPAnc <- function(interm, goLevel){
for (i in as.list(GOBPANCESTOR)[interm][[1]] ){
numParents <- length(as.list(GOBPANCESTOR)[i][[1]])
if (numParents == goLevel) {
return(i)
}
}
}
getCCAnc <- function(interm, goLevel){
for (i in as.list(GOCCANCESTOR)[interm][[1]] ){
numParents <- length(as.list(GOCCANCESTOR)[i][[1]])
if (numParents == goLevel) {
return(i)
}
}
}
getAnyAnc <- function(x, goLevel){
mytype <- getGOOntology(x)
myAncestor <- switch(mytype,
MF = getMFAnc(x, goLevel),
BP = getBPAnc(x, goLevel),
CC = getCCAnc(x, goLevel))
myAncName <- as.character(try(getGOTerm(myAncestor), silent = T))
as.vector(c(x, mytype, myAncestor, myAncName))
}
anc <- getAnyAnc(args[1], 3)
anc <- rbind(anc)
write.table(anc,file=paste0("anc_", args[1], ".txt"),row.names=F, sep="\t", quote = F, col.names = F)