| link_ko {GCModeller} | R Documentation |
link_ko takes a vector of KEGG gene identifiers (e.g. "taes:803091") and retrieves their associated KEGG Orthology (KO) identifiers by calling the KEGG REST API link/ko endpoint. Results are cached locally in text files to avoid repeated downloads.
link_ko(kegg.id,
cache = './tmp',
batch.size = 100);
The function first scans cache for existing result files, reads them, and extracts already queried KEGG IDs. Those IDs are excluded from the current API requests to avoid redundant downloads. For each batch of remaining KEGG IDs, a URL of the form \preformatted{https://rest.kegg.jp/link/ko/<id1>+<id2>+...+<idn>} is constructed. The KEGG API returns a tab‑delimited text file, which is written to a file named <md5(url)>.txt under cache. A 1‑second pause is inserted between requests to reduce load on the KEGG server. This implementation assumes that the HTTP request returns plain text content; the exact syntax of requests.get(), plain_text, and sleep() depends on your runtime environment and is shown here as pseudo‑code.
#\dontrun{
# Basic usage with default cache directory
link_ko(c("hsa:10458", "mmu:12345"))
# Custom cache directory and batch size
link_ko(
kegg_id = c("taes:803091", "taes:803092"),
cache = "./kegg_cache",
batch_size = 50
)
# Read back the cached results
cache_dir <- "./kegg_cache"
files <- list.files(cache_dir, pattern = "\\.txt$", full.names = TRUE)
ko_table <- do.call(rbind, lapply(files, read.table,
header = FALSE, row.names = NULL, sep = "\t"
))
head(ko_table)
#}