Last active
February 19, 2021 11:11
-
-
Save alexllc/0cf2bd49bf5acd43054a95edb37fb469 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to retreive KEGG pathway names from KEGGREST. For some strange reasons, they won't take a list of queries even though the query size was set at 100. However, when I execute the query one path at a time, I would get an error message saying "Forbidden (HTTP 403)", hence the sys.sleep break. I am guess querying more than 100 within a short period of time would not be allowed too. I'm expecting a KEGGgraph input of graphs with path ID that are like "X00010", but feel free to remove the gsub function if you have already formatted your pathID into the "map00010" form. | |
library(KEGGREST) | |
kegg_all_names <- function(pathID) { | |
repeats <- floor(length(pathID) / 100) | |
final_rep <- length(pathID) %% 100 | |
pathNames <- NULL | |
for (i in 1:repeats) { | |
pathNames <- c(pathNames, unlist(lapply(gsub("X", "map", pathID[(1 + (i * 100) - 100):(i * 100)]), function(x) keggFind("pathway", x)))) | |
Sys.sleep(5) | |
} | |
pathNames <- c(pathNames, unlist(lapply(gsub("X", "map", pathID[(1 + (i * 100)):(i * 100 + final_rep)]), function(x) keggFind("pathway", x)))) | |
return(pathNames) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment