| Title: | Parse, Expand, Annotate and Visualize KEGG Pathway Networks as Tidy Graphs |
|---|---|
| Description: | Provides tools to parse KEGG pathway KGML files into tidy graphs, expand metanodes (e.g., multi-gene entries), annotate them with custom dictionaries, and produce consistent visualizations using ggraph. Enables integration of KEGG pathways with tidygraph-based workflows. |
| Authors: | Guillermo de Anda Jáuregui [aut, cre] |
| Maintainer: | Guillermo de Anda Jáuregui <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.65 |
| Built: | 2026-10-02 23:10:36 UTC |
| Source: | https://github.com/bioc/punKEGGer |
Joins a KEGG layout table (as returned by layout_kegg()) to a tidygraph object,
using the meta_id field of each node as the key.
add_kegg_layout(graph, layout_tbl)add_kegg_layout(graph, layout_tbl)
graph |
A |
layout_tbl |
A tibble with layout coordinates: |
The same tidygraph, with x and y coordinates added to nodes.
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) g <- combine_kegg_network(doc) layout_tbl <- layout_kegg(doc) g_layout <- add_kegg_layout(g, layout_tbl) # View the layout coordinates head(tidygraph::as_tibble(g_layout))kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) g <- combine_kegg_network(doc) layout_tbl <- layout_kegg(doc) g_layout <- add_kegg_layout(g, layout_tbl) # View the layout coordinates head(tidygraph::as_tibble(g_layout))
Adds external identifiers (e.g., HGNC symbols, Ensembl IDs) to the nodes of a
tidygraph-style KEGG network, using a custom dictionary.
annotate_kegg_graph(graph, kegg_dict, identifiers = c("hgnc_symbol"))annotate_kegg_graph(graph, kegg_dict, identifiers = c("hgnc_symbol"))
graph |
A tidygraph object (nodes should be named with KEGG IDs). |
kegg_dict |
A tibble with one column |
identifiers |
Character vector of column names in |
Note: You must provide your own annotation dictionary (kegg_dict) as a
tibble with at least one column named kegg_id, containing KEGG gene IDs in
the form "hsa:1234". This dictionary can be generated from BioMart or other
curated sources.
The same tidygraph, with new columns added to the node attributes.
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") dict_file <- system.file("extdata", "example_dict.hsa04210.csv", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) dict <- read.csv(dict_file) nodes <- extract_kegg_nodes(doc) meta_dict <- create_meta_dict(nodes, dict) g <- combine_kegg_network(doc) g_annot <- annotate_kegg_graph(g, meta_dict) head(tidygraph::as_tibble(g_annot))kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") dict_file <- system.file("extdata", "example_dict.hsa04210.csv", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) dict <- read.csv(dict_file) nodes <- extract_kegg_nodes(doc) meta_dict <- create_meta_dict(nodes, dict) g <- combine_kegg_network(doc) g_annot <- annotate_kegg_graph(g, meta_dict) head(tidygraph::as_tibble(g_annot))
Parses both standard KEGG relations and intra-group edges, and builds a directed tidygraph. Also assigns meta_id to each node: either its group_id (if in a group) or its own ID.
combine_kegg_network(kgml)combine_kegg_network(kgml)
kgml |
A parsed XML document from |
A tidygraph object with all edges from the KGML and nodes carrying meta_id.
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) g <- combine_kegg_network(doc) print(g) igraph::gorder(g)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) g <- combine_kegg_network(doc) print(g) igraph::gorder(g)
Takes the output of extract_kegg_nodes() and a KEGG annotation dictionary
(e.g., from BioMart or custom source), and merges them based on kegg_id.
This enables annotating each metanode (meta_id) with HGNC, Ensembl, Entrez, etc.
create_meta_dict(node_info, kegg_dict)create_meta_dict(node_info, kegg_dict)
node_info |
A tibble from |
kegg_dict |
A tibble mapping KEGG gene IDs to external identifiers.
Must contain a column |
A tibble linking each meta_id to any identifiers in kegg_dict.
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") dict_file <- system.file("extdata", "example_dict.hsa04210.csv", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) nodes <- extract_kegg_nodes(doc) dict <- read.csv(dict_file) meta_dict <- create_meta_dict(nodes, dict) head(meta_dict)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") dict_file <- system.file("extdata", "example_dict.hsa04210.csv", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) nodes <- extract_kegg_nodes(doc) dict <- read.csv(dict_file) meta_dict <- create_meta_dict(nodes, dict) head(meta_dict)
Takes a tidygraph where node names are KGML entry IDs and expands the network by replacing group/multi-gene nodes with individual gene-level edges.
expand_metagraph(g, node_info, node_types = c("gene"))expand_metagraph(g, node_info, node_types = c("gene"))
g |
A |
node_info |
A tibble as returned by |
node_types |
Character vector indicating which node types to expand (default is |
A new tidygraph object with expanded node IDs (e.g., hsa:00001, hsa:00002).
# Parse KGML and extract nodes and relations kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) node_info <- extract_kegg_nodes(doc) rels <- parse_kegg_relations_clean(doc) g <- combine_kegg_network(doc) # Expand the graph from metanodes to gene-level nodes g_exp <- expand_metagraph(g, node_info) # Compare number of nodes before and after expansion igraph::gorder(g) # number of metanodes igraph::gorder(g_exp) # number of gene-level nodes# Parse KGML and extract nodes and relations kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) node_info <- extract_kegg_nodes(doc) rels <- parse_kegg_relations_clean(doc) g <- combine_kegg_network(doc) # Expand the graph from metanodes to gene-level nodes g_exp <- expand_metagraph(g, node_info) # Compare number of nodes before and after expansion igraph::gorder(g) # number of metanodes igraph::gorder(g_exp) # number of gene-level nodes
Parses all entry elements from a KEGG KGML XML document and extracts ID, name,
type, and individual KEGG IDs. Supports multi-gene entries (e.g., hsa:1234+hsa:5678)
by expanding them into separate rows with a shared meta_id.
extract_kegg_nodes(kgml)extract_kegg_nodes(kgml)
kgml |
A parsed XML document from |
A tibble with columns: id, meta_id, type, kegg_id
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) nodes <- extract_kegg_nodes(doc) head(nodes)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) nodes <- extract_kegg_nodes(doc) head(nodes)
Downloads a KEGG pathway in KGML format using KEGGREST::keggGet()
and returns it as an xml2 document ready for downstream parsing with
punKEGGer.
fetch_kegg_kgml(pathway_id)fetch_kegg_kgml(pathway_id)
pathway_id |
A KEGG pathway identifier, e.g. |
An xml2 document.
kgml <- fetch_kegg_kgml("hsa04210") g <- combine_kegg_network(kgml)kgml <- fetch_kegg_kgml("hsa04210") g <- combine_kegg_network(kgml)
Parses the graphics element of each node in the KGML to extract manual layout
positions (x, y), which are typically defined for KEGG maps.
layout_kegg(kgml)layout_kegg(kgml)
kgml |
A parsed XML document from |
A tibble with columns: id, x, y (corresponding to KEGG entry IDs).
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) layout_tbl <- layout_kegg(doc) head(layout_tbl)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) layout_tbl <- layout_kegg(doc) head(layout_tbl)
Extracts group-type entries from a KEGG KGML file and generates both: (1) a mapping of group ID to component node IDs (with meta_id), (2) a set of intra-group edges linking the components as undirected pairs.
parse_kegg_groups(kgml)parse_kegg_groups(kgml)
kgml |
A parsed XML document from |
A list with two elements:
A tibble mapping each member ID to its meta_id (group_id or itself).
A tibble with pairwise intra-group edges (from, to, type = "group").
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) group_data <- parse_kegg_groups(doc) head(group_data$mapping) head(group_data$edges)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) group_data <- parse_kegg_groups(doc) head(group_data$mapping) head(group_data$edges)
Extracts pairwise relations between KEGG entries and their subtypes if available.
parse_kegg_relations_clean(kgml)parse_kegg_relations_clean(kgml)
kgml |
A parsed XML document from |
A tibble with columns: from, to, type, subtype.
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) rels <- parse_kegg_relations_clean(doc) head(rels)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") doc <- xml2::read_xml(kgml_file) rels <- parse_kegg_relations_clean(doc) head(rels)
Generates a ggraph plot of a KEGG network with manual layout (x, y),
colored by node type and edge subtype. The user can specify which identifier
to display on each node label (e.g., hgnc_symbol).
plot_kegg_graph(g, id = hgnc_symbol)plot_kegg_graph(g, id = hgnc_symbol)
g |
A |
id |
Unquoted column name to use for node labels (e.g., |
A ggplot object with the KEGG network visualization.
kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") dict_file <- system.file("extdata", "example_dict.hsa04210.csv", package = "punKEGGer") kgml <- xml2::read_xml(kgml_file) g <- combine_kegg_network(kgml) node_info <- extract_kegg_nodes(kgml) dict <- read.csv(dict_file) meta_dict <- create_meta_dict(node_info, dict) g_exp <- expand_metagraph(g, node_info, node_types = "gene") g_annot <- annotate_kegg_graph(g_exp, meta_dict, identifiers = "hgnc_symbol") layout_tbl <- layout_kegg(kgml) g_layout <- add_kegg_layout(g_annot, layout_tbl) plot_kegg_graph(g_layout, id = hgnc_symbol)kgml_file <- system.file("extdata", "hsa04210.xml", package = "punKEGGer") dict_file <- system.file("extdata", "example_dict.hsa04210.csv", package = "punKEGGer") kgml <- xml2::read_xml(kgml_file) g <- combine_kegg_network(kgml) node_info <- extract_kegg_nodes(kgml) dict <- read.csv(dict_file) meta_dict <- create_meta_dict(node_info, dict) g_exp <- expand_metagraph(g, node_info, node_types = "gene") g_annot <- annotate_kegg_graph(g_exp, meta_dict, identifiers = "hgnc_symbol") layout_tbl <- layout_kegg(kgml) g_layout <- add_kegg_layout(g_annot, layout_tbl) plot_kegg_graph(g_layout, id = hgnc_symbol)