kg_microbe.transform_utils.kegg package

Submodules

kg_microbe.transform_utils.kegg.kegg module

Transform for KEGG (Kyoto Encyclopedia of Genes and Genomes) orthology.

class kg_microbe.transform_utils.kegg.kegg.KEGGTransform(input_dir=None, output_dir=None)

Bases: Transform

Transform KEGG orthology data into KGX format.

add_edge(subject, predicate, obj, relation)

Add an edge to the collection.

Parameters:
  • subject (str) – Subject node ID

  • predicate (str) – Biolink predicate

  • obj (str) – Object node ID

  • relation (str) – RO or other relation ontology term

Return type:

None

add_ko_node(ko_id, description)

Add a KEGG KO node.

Parameters:
  • ko_id (str) – KO identifier (e.g., ‘K00001’)

  • description (str) – KO description

Return type:

None

add_module_node(module_id, module_name)

Add a KEGG module node.

Parameters:
  • module_id (str) – Module identifier (e.g., ‘M00001’)

  • module_name (str) – Module name

Return type:

None

add_pathway_node(pathway_id, pathway_name)

Add a KEGG pathway node.

Parameters:
  • pathway_id (str) – Pathway identifier (e.g., ‘ko00010’)

  • pathway_name (str) – Pathway name

Return type:

None

run(data_file=None, show_status=True)

Run the KEGG transform.

Reads KEGG KO list and details from cached files (downloaded via bulk script), and creates nodes and edges for KO entries, pathways, and modules.

Parameters:
  • data_file (Optional[Path]) – Not used (kept for API compatibility)

  • show_status (bool) – Show progress messages (default: True)

Return type:

None

write_output()

Write nodes and edges to TSV files.

Return type:

None

kg_microbe.transform_utils.kegg.utils module

Utility functions for KEGG transform.

kg_microbe.transform_utils.kegg.utils.extract_ko_ids_from_list(ko_ids, max_fetch=None)

Fetch details for a list of KO IDs.

Parameters:
  • ko_ids (List[str]) – List of KO identifiers

  • max_fetch (Optional[int]) – Maximum number of entries to fetch (for testing)

Return type:

Dict[str, Dict]

Returns:

Dictionary mapping KO ID to details

kg_microbe.transform_utils.kegg.utils.get_kegg_ko_details(ko_id)

Fetch detailed information for a specific KEGG KO entry.

Parameters:

ko_id (str) – KO identifier (e.g., ‘K00001’)

Return type:

Optional[Dict[str, any]]

Returns:

Dictionary with KO details (name, definition, pathway, etc.)

kg_microbe.transform_utils.kegg.utils.get_kegg_ko_list()

Fetch list of all KEGG Orthology (KO) entries.

Returns dictionary mapping KO ID to description.

Return type:

Dict[str, str]

Returns:

Dictionary mapping KO ID (e.g., ‘K00001’) to description

kg_microbe.transform_utils.kegg.utils.load_kegg_ko_details_from_cache(cache_file)

Load KEGG KO details from cached JSON file.

Supports two formats: 1. Minimal format (ko_minimal.json): Only pathways and modules (~30MB) 2. Full format (ko_details.json): Full entry text (~894MB)

Parameters:

cache_file (Path) – Path to ko_minimal.json or ko_details.json file

Return type:

Dict[str, Dict]

Returns:

Dictionary mapping KO ID to details

kg_microbe.transform_utils.kegg.utils.parse_kegg_entry(entry_text)

Parse KEGG entry text format.

KEGG entries have a specific format with sections like: ENTRY K00001 NAME E1.1.1.1, adh DEFINITION alcohol dehydrogenase [EC:1.1.1.1] PATHWAY ko00010 Glycolysis / Gluconeogenesis MODULE M00001 Glycolysis …

Parameters:

entry_text (str) – Raw text from KEGG API

Return type:

Dict[str, any]

Returns:

Dictionary with parsed fields

kg_microbe.transform_utils.kegg.utils.parse_kegg_ko_list_file(ko_list_file)

Parse KEGG KO list from downloaded file.

File format: ko:K00001<tab>description

Parameters:

ko_list_file (Path) – Path to downloaded ko_list.txt file

Return type:

Dict[str, str]

Returns:

Dictionary mapping KO ID to description

Module contents

KEGG (Kyoto Encyclopedia of Genes and Genomes) transform.

class kg_microbe.transform_utils.kegg.KEGGTransform(input_dir=None, output_dir=None)

Bases: Transform

Transform KEGG orthology data into KGX format.

add_edge(subject, predicate, obj, relation)

Add an edge to the collection.

Parameters:
  • subject (str) – Subject node ID

  • predicate (str) – Biolink predicate

  • obj (str) – Object node ID

  • relation (str) – RO or other relation ontology term

Return type:

None

add_ko_node(ko_id, description)

Add a KEGG KO node.

Parameters:
  • ko_id (str) – KO identifier (e.g., ‘K00001’)

  • description (str) – KO description

Return type:

None

add_module_node(module_id, module_name)

Add a KEGG module node.

Parameters:
  • module_id (str) – Module identifier (e.g., ‘M00001’)

  • module_name (str) – Module name

Return type:

None

add_pathway_node(pathway_id, pathway_name)

Add a KEGG pathway node.

Parameters:
  • pathway_id (str) – Pathway identifier (e.g., ‘ko00010’)

  • pathway_name (str) – Pathway name

Return type:

None

run(data_file=None, show_status=True)

Run the KEGG transform.

Reads KEGG KO list and details from cached files (downloaded via bulk script), and creates nodes and edges for KO entries, pathways, and modules.

Parameters:
  • data_file (Optional[Path]) – Not used (kept for API compatibility)

  • show_status (bool) – Show progress messages (default: True)

Return type:

None

write_output()

Write nodes and edges to TSV files.

Return type:

None