Kegg database

From aipoch/medical-research-skills · View interactive version

Kegg database is an AI agent skill from the GitHub repository aipoch/medical-research-skills. Direct access to KEGG via the REST API for academic-only pathway/gene/compound/drug queries; use when you need precise HTTP-level control or targeted KEGG ID mapping.

How to use this skill

Skill file

Source: https://github.com/aipoch/medical-research-skills

When to Use

Note: KEGG REST access is intended for academic use. Non-academic/commercial use may require a separate KEGG license.

Key Features

Dependencies

Example Usage

"""
End-to-end example:
1) Find a human gene by keyword
2) Link the gene to pathways
3) Retrieve one pathway entry
4) Convert the gene ID to UniProt
"""

from scripts.kegg_api import kegg_find, kegg_link, kegg_get, kegg_conv

# 1) Search for a gene keyword in KEGG GENES
hits = kegg_find("genes", "p53")
print("FIND results (first lines):")
print("\n".join(hits.splitlines()[:5]), "\n")

# Choose a known KEGG gene ID for TP53 (human)
gene_id = "hsa:7157"

# 2) Link gene -> pathways
pathway_links = kegg_link("pathway", gene_id)
print("LINK gene -> pathways (first lines):")
print("\n".join(pathway_links.splitlines()[:5]), "\n")

# Parse the first pathway ID from the link output
# Typical line format: path:hsaXXXXX<TAB>hsa:7157
first_line = next((ln for ln in pathway_links.splitlines() if ln.strip()), None)
if not first_line:
    raise RuntimeError("No pathways returned for the gene ID.")

path_id = first_line.split("\t")[0].replace("path:", "")
print("Selected pathway:", path_id, "\n")

# 3) Retrieve the pathway entry (flat text)
pathway_entry = kegg_get(path_id)
print("GET pathway entry (first 30 lines):")
print("\n".join(pathway_entry.splitlines()[:30]), "\n")

# 4) Convert KEGG gene ID -> UniProt
uniprot_map = kegg_conv("uniprot", gene_id)
print("CONV KEGG -> UniProt:")
print(uniprot_map)

Implementation Details

API-to-function mapping

This skill wraps KEGG REST endpoints into Python functions (see scripts/kegg_api.py):

Retrieves database or organism metadata (release info, counts, etc.).

Lists entries in a database; optionally scoped to an organism (e.g., ("pathway", "hsa")).

Also supports listing explicit IDs (batch-style) when passed as a single string.

Searches by keyword or by chemical properties. Common option values:

Retrieves full entries or specific formats:

Batching rules:

Converts IDs between KEGG and external databases (e.g., uniprot, ncbi-geneid, pubchem, chebi).

Output is tab-delimited pairs: source_id<TAB>target_id.

Cross-references entries across KEGG databases (e.g., gene → pathway, pathway → compound, gene → KO).

Returns known drug–drug interactions for one or more KEGG drug IDs (up to typical batch limits).

Practical constraints and error handling

Reference documentation

For detailed endpoint syntax, database lists, and species codes, consult:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.