-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnsemblID2Entrez.R
More file actions
79 lines (75 loc) · 2.43 KB
/
EnsemblID2Entrez.R
File metadata and controls
79 lines (75 loc) · 2.43 KB
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
EnsemblID2Entrez <- function(EnsemblID,
Output = "Name+Description") {
suppressPackageStartupMessages(library("rentrez"))
suppressPackageStartupMessages(library("retry"))
if (identical(EnsemblID, NA) || identical(EnsemblID, "") || (length(EnsemblID) == 0)) {
return("")
}
if (length(EnsemblID) > 1) {
return(BatchConvert2Entrez(EnsemblID, Output = Output))
}
retry({
ConsoleOutput <- capture.output({
EntrezSearchResult <- entrez_search(db = "gene", term = EnsemblID)
});
if (length(ConsoleOutput) != 0) {
stop("Error")
}
}, when = ".*", silent = TRUE)
if (is.null(unlist(EntrezSearchResult$ids))) {
return("")
}
else {
if (Output == "Accession") {
return(paste("LOC", EntrezSearchResult$ids, sep = ""))
}
if (Output == "ID") {
return(EntrezSearchResult$ids)
}
if (Output == "Description") {
Result <- c()
for (ID in EntrezSearchResult$ids) {
retry({
ConsoleOutput <- capture.output({
GeneSummary <- entrez_summary(db = "gene", id = ID)
});
if (length(ConsoleOutput) != 0) {
stop("Error")
}
}, when = ".*", silent = TRUE)
Result <- c(Result, GeneSummary$description)
}
return(paste(unique(Result), collapse = "; "))
}
if (Output == "Name+Description") {
Result <- c()
for (ID in EntrezSearchResult$ids) {
retry({
ConsoleOutput <- capture.output({
GeneSummary <- entrez_summary(db = "gene", id = ID)
});
if (length(ConsoleOutput) != 0) {
stop("Error")
}
}, when = ".*", silent = TRUE)
Result <- c(Result, paste0(GeneSummary$name, ": ", GeneSummary$description))
}
return(paste(unique(Result), collapse = "; "))
}
if (Output == "Name") {
Result <- c()
for (ID in EntrezSearchResult$ids) {
retry({
ConsoleOutput <- capture.output({
GeneSummary <- entrez_summary(db = "gene", id = ID)
});
if (length(ConsoleOutput) != 0) {
stop("Error")
}
}, when = ".*", silent = TRUE)
Result <- c(Result, GeneSummary$name)
}
return(paste(unique(Result), collapse = "; "))
}
}
}