link_ko {GCModeller} R Documentation

Batch query KEGG KO annotations for given KEGG gene IDs

Description

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.

Usage

link_ko(kegg.id,
    cache = './tmp',
    batch.size = 100);

Arguments

kegg.id

Character vector of KEGG gene identifiers. Each element should be in the form <org>:<gene>, e.g. "hsa:10458" or "taes:803091".

cache

Character. Path to the directory where cached results are stored. Text files in this directory are assumed to be tab‑separated output from previous KEGG link/ko queries. Default is "./tmp".

batch.size

Integer. Number of KEGG IDs to include in each API request. Larger values reduce the number of requests but increase the risk of timeouts or server‑side limits. Default is 100.

Details

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.

Authors

xieguigang

Value

This function has no value returns.

Examples

#\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)

#}

[Package GCModeller version 1.1.0-beta Index]