| Title: | Creating, Rendering, and Mapping Omics Data on KEGG Pathway Graphs |
|---|---|
| Description: | KEGGemUP retrieves and renders interactively KEGG pathway graphs. The retrieval makes full use of the caching functionality to avoid unnecessary download processes. The interactivity of the graph is warranted via the visNetwork interface to the vis.js library, fully supporting bindings to be used in Shiny for further operations. |
| Authors: | Edoardo Filippi [aut] (ORCID: <https://orcid.org/0009-0003-9858-0137>), Federico Marini [aut, cre] (ORCID: <https://orcid.org/0000-0003-3252-7758>) |
| Maintainer: | Federico Marini <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.0 |
| Built: | 2026-05-27 11:17:28 UTC |
| Source: | https://github.com/BiocStaging/KEGGemUP |
Cleanup the title node from a KEGG igraph object
cleanup_title_node(g)cleanup_title_node(g)
g |
The igraph object |
Strips away the node starting with the TITLE: label.
In some situations, that node might not be too heavily needed...
An igraph object, without the node originally kept as "TITLE:..."
graph <- create_kegg_graph(pathway_id = "hsa04110") graph_notitlenode <- cleanup_title_node(graph) graph_notitlenode render_kegg_graph(graph_notitlenode)graph <- create_kegg_graph(pathway_id = "hsa04110") graph_notitlenode <- cleanup_title_node(graph) graph_notitlenode render_kegg_graph(graph_notitlenode)
Convert KEGG pathway to igraph object
create_kegg_graph(pathway_id, kgml_file = NULL, verbose = FALSE)create_kegg_graph(pathway_id, kgml_file = NULL, verbose = FALSE)
pathway_id |
Character, KEGG pathway ID (e.g., 'hsa04110') or NULL if using kgml_file |
kgml_file |
Path to a local KGML file (optional, if pathway_id is provided) |
verbose |
Logical indicating whether to print verbose messages (default: FALSE) |
An igraph object representing the KEGG pathway graph
pathway <- "hsa04110" # Example pathway ID graph <- create_kegg_graph(pathway_id = pathway, verbose = TRUE) plot(graph) # Plot the graph using igraph's plotting functionspathway <- "hsa04110" # Example pathway ID graph <- create_kegg_graph(pathway_id = pathway, verbose = TRUE) plot(graph) # Plot the graph using igraph's plotting functions
Return all cached KEGG and mapping files from BiocFileCache
display_cache_KEGGemUP()display_cache_KEGGemUP()
This function retrieves information about all cached KEGG pathway files and mapping files stored using BiocFileCache.
A list containing data frames of cached KEGG and mapping files
cache_info <- display_cache_KEGGemUP() # View cached KEGG pathway files print(cache_info$kegg) # View cached mapping files print(cache_info$mappings)cache_info <- display_cache_KEGGemUP() # View cached KEGG pathway files print(cache_info$kegg) # View cached mapping files print(cache_info$mappings)
Exporting a KEGG graph into its components, nodes and edges, as tab-separated text files (having them represented as dataframes for max portability)
export_kegg_graph(g, basename)export_kegg_graph(g, basename)
g |
An igraph graph object, e.g. created with KEGGemUP |
basename |
Character string, specifying the base name for the files to write the two individual data frames, for nodes and edges |
NULL, invisibly
g <- create_kegg_graph(pathway_id = "hsa04110") export_kegg_graph(g, basename = tempfile())g <- create_kegg_graph(pathway_id = "hsa04110") export_kegg_graph(g, basename = tempfile())
Get KEGG database, with caching.
get_kegg_db(db_name = "compound", path = NULL, bfc = NULL, verbose = FALSE)get_kegg_db(db_name = "compound", path = NULL, bfc = NULL, verbose = FALSE)
db_name |
Name of the KEGG database to retrieve (default: "compound"). |
path |
Optional path to save the KEGG database file if not using cache. Defaults to NULL. |
bfc |
BiocFileCache object for caching KEGG database files. Defaults to NULL |
verbose |
Logical, if TRUE, print additional messages. |
The valid KEGG database names are:
kegg | pathway | brite | module | ko | genes |
A data frame with KEGG IDs and names.
# Saving in path data_dir <- tempdir() kegg_compounds <- get_kegg_db( db_name = "compound", path = data_dir, verbose = TRUE ) # Just returning without saving kegg_compounds_onthefly <- get_kegg_db( db_name = "compound", verbose = TRUE ) head(kegg_compounds_onthefly) # saving to cache (in a temp dir) kegg_compounds_cached <- get_kegg_db( db_name = "compound", bfc = BiocFileCache::BiocFileCache(tempdir()), verbose = TRUE )# Saving in path data_dir <- tempdir() kegg_compounds <- get_kegg_db( db_name = "compound", path = data_dir, verbose = TRUE ) # Just returning without saving kegg_compounds_onthefly <- get_kegg_db( db_name = "compound", verbose = TRUE ) head(kegg_compounds_onthefly) # saving to cache (in a temp dir) kegg_compounds_cached <- get_kegg_db( db_name = "compound", bfc = BiocFileCache::BiocFileCache(tempdir()), verbose = TRUE )
Highlight a subset of the graph based on KEGG IDs
highlight_kegg_graph(g, ids_to_highlight)highlight_kegg_graph(g, ids_to_highlight)
g |
An igraph object to visualize. Must have vertex attributes 'x' and 'y' for layout. |
ids_to_highlight |
Character vector of KEGG IDs to include in the highlighted subset. |
This function highlights the nodes corresponding to the provided KEGG IDs and fades the rest of the graph. It modifies vertex attributes to achieve this effect.
An igraph object with highlighted nodes and faded non-highlighted nodes and edges.
pathway <- "mmu00230" g <- create_kegg_graph(pathway) KEGG_to_include <- c("C00262", "C00385", "C00366", "C00294", "C00387", "C01762", "C05512", "C00301", "C01185", "C00455", "22436", "14544", "18950", "11486", "80285", "59027") highlighted_subg <- highlight_kegg_graph(g, KEGG_to_include)pathway <- "mmu00230" g <- create_kegg_graph(pathway) KEGG_to_include <- c("C00262", "C00385", "C00366", "C00294", "C00387", "C01762", "C05512", "C00301", "C01185", "C00455", "22436", "14544", "18950", "11486", "80285", "59027") highlighted_subg <- highlight_kegg_graph(g, KEGG_to_include)
Map differential expression results to nodes
map_results_to_graph( g, de_results, feature_column = NULL, value_column = NULL, verbose = FALSE, palette = NULL, palette_limit = NULL, palettes_list = list(NA_character_), palettes_limits_list = c(NA_real_) )map_results_to_graph( g, de_results, feature_column = NULL, value_column = NULL, verbose = FALSE, palette = NULL, palette_limit = NULL, palettes_list = list(NA_character_), palettes_limits_list = c(NA_real_) )
g |
An igraph object representing the KEGG pathway graph. |
de_results |
A data frame or a list of data frames containing differential expression results |
feature_column |
Name of the column in de_results that contains KEGG IDs |
value_column |
Name of the column in de_results that contains values to map |
verbose |
Logical indicating whether to print verbose messages (default: FALSE) |
palette |
Optional color palette for mapping values (default: NULL, will use a default palette) |
palette_limit |
Optional numeric limit for the color palette (default: NULL, will be determined from data) |
palettes_list |
Optional list of color palettes if de_results is a list (default: NULL) |
palettes_limits_list |
Optional list of numeric limits for multiple palettes if de_results is a list (default: NULL) |
This function can be used to map the differential expression
results to the graph,
the input of the graph must be the output of the function
create_kegg_graph in the igraph format.
The results to be mapped can be
provided either as a list or as a single data.frame.
If a single data.frame
is provided, the default column names
that it will look for are KEGG IDs and values are
'KEGG_ids' and 'log2FoldChange',
respectively, but these can be changed using the
feature_column and value_column parameters.
An igraph object with differential expression results mapped to node attributes
pathway <- "hsa04110" # Example pathway ID graph <- create_kegg_graph(pathway_id = pathway) # Example differential expression results de_results <- data.frame( KEGG_ids = c("hsa:1234", "hsa:5678", "cpd:C00022"), log2FoldChange = c(1.5, -2.0, 0.5) ) vis_graph <- map_results_to_graph( graph, de_results, feature_column = "KEGG_ids", value_column = "log2FoldChange" )pathway <- "hsa04110" # Example pathway ID graph <- create_kegg_graph(pathway_id = pathway) # Example differential expression results de_results <- data.frame( KEGG_ids = c("hsa:1234", "hsa:5678", "cpd:C00022"), log2FoldChange = c(1.5, -2.0, 0.5) ) vis_graph <- map_results_to_graph( graph, de_results, feature_column = "KEGG_ids", value_column = "log2FoldChange" )
Plot KEGG pathway graph using visNetwork
render_kegg_graph( g, scaling_factor = 1.5, relationships = c("all", "reactions", "relations", "none"), visualization_type = c("standard", "positions", "node_name", "node_size") )render_kegg_graph( g, scaling_factor = 1.5, relationships = c("all", "reactions", "relations", "none"), visualization_type = c("standard", "positions", "node_name", "node_size") )
g |
An igraph object representing the KEGG pathway graph. |
scaling_factor |
Numeric factor to scale node sizes (default: 1.5). |
relationships |
Character specifying which relationships to include in edges ("all", "reactions", "relations", "none"; default: "all"). |
visualization_type |
Character specifying the type of visualization for nodes: "standard", "positions", "node_name", or "node_size" (default: "standard"). |
This function takes an igraph object representing a KEGG pathway graph and creates a visNetwork visualization. It maps node attributes to visual properties.
A visNetwork object representing the KEGG pathway graph with mapped results.
pathway <- "hsa04110" # Example pathway ID graph <- create_kegg_graph(pathway_id = pathway) # Example differential expression results de_results <- data.frame( KEGG_ids = c("hsa:1234", "hsa:5678", "cpd:C00022"), log2FoldChange = c(1.5, -2.0, 0.5) ) graph <- map_results_to_graph( graph, de_results, feature_column = "KEGG_ids", value_column = "log2FoldChange") vis_graph <- render_kegg_graph(graph, scaling_factor = 1.5, relationships = "all", visualization_type = "standard")pathway <- "hsa04110" # Example pathway ID graph <- create_kegg_graph(pathway_id = pathway) # Example differential expression results de_results <- data.frame( KEGG_ids = c("hsa:1234", "hsa:5678", "cpd:C00022"), log2FoldChange = c(1.5, -2.0, 0.5) ) graph <- map_results_to_graph( graph, de_results, feature_column = "KEGG_ids", value_column = "log2FoldChange") vis_graph <- render_kegg_graph(graph, scaling_factor = 1.5, relationships = "all", visualization_type = "standard")
data.frame containing Differential Expression Analysis, generated
with limma
A sample data.frame containing Differential Expression Analysis, generated
with limma
A data.frame object
This data.frame object contains the results of a Differential
Expression Analysis performed (with limma) on data from the macrophage
package, contrasting the counts from naive macrophage to those associated
with IFNg.
The code to create said object can be found in the folder /inst/scripts in
the KEGGemUP package, the file is called create_deresults.R.
A sample data.frame object, extracted from the topTable function
as a result of running the limma DE workflow
Alasoo, et al. "Shared genetic effects on chromatin and gene expression indicate a role for enhancer priming in immune response", Nature Genetics, January 2018 doi: 10.1038/s41588-018-0046-7.
Reset the KEGG and mapping caches by deleting all cached files
reset_cache_KEGGemUP()reset_cache_KEGGemUP()
This function deletes all cached KEGG pathway files and mapping files stored using BiocFileCache. It prompts the user for confirmation before proceeding with the deletion.
(invisible) NULL
## Not run: reset_cache_KEGGemUP() ## End(Not run)## Not run: reset_cache_KEGGemUP() ## End(Not run)
Download all KEGG pathways for a given organism
retrieve_all_pathways(org, wait = 0.5, verbose = FALSE)retrieve_all_pathways(org, wait = 0.5, verbose = FALSE)
org |
KEGG organism code (e.g., 'hsa' for human). |
wait |
Numeric value, needs to be strictly positive. Indicates the amount in seconds to wait in between requests, being polite and respectful of the limit rates imposed by KEGG. Defaults to 0.5, which is safely a bit above the rate of 3max/sec. |
verbose |
Logical, if TRUE, print additional messages. |
This function can take a while to run completely, but is an efficient way to retrieve all the kgml files encoding for the KEGG pathways. Some failures could be triggered by a rate limitation imposed by the KEGG website. Since this caches the files locally, it is safe to rerun to complete the operation without extra unneeded requests to the API
The BiocFileCache object is returned invisibly
# Download all pathways for human ## Not run: retrieve_all_pathways("hsa", verbose = TRUE) ## End(Not run)# Download all pathways for human ## Not run: retrieve_all_pathways("hsa", verbose = TRUE) ## End(Not run)
Download and cache KEGG KGML files.
retrieve_kgml(pathway_id, bfc = NULL, path = NULL, verbose = FALSE)retrieve_kgml(pathway_id, bfc = NULL, path = NULL, verbose = FALSE)
pathway_id |
Character, KEGG pathway ID (e.g., 'hsa04110'). |
bfc |
BiocFileCache object for caching KEGG KGML files. Defaults to NULL |
path |
Optional path to save the KGML file if not using cache. Defaults to NULL |
verbose |
Logical, if TRUE, print additional messages. |
This function can save an individual KGML to the cache or to a path.
If specified, the BiocFileCache cache is prioritized.
If a path if specified and it is a directory, it will save the file there.
If the path specified a file path, this will be the location to store the
file. If it is left as NULL, it will save the KMGL file in the current
working directory
Path to the cached KGML file.
data_dir <- tempdir() kgml_path <- retrieve_kgml("hsa04110", path = data_dir, verbose = TRUE) cache_dir <- tempdir() kgml_path_cached <- retrieve_kgml("hsa04110", bfc = BiocFileCache::BiocFileCache(cache_dir), verbose = TRUE )data_dir <- tempdir() kgml_path <- retrieve_kgml("hsa04110", path = data_dir, verbose = TRUE) cache_dir <- tempdir() kgml_path_cached <- retrieve_kgml("hsa04110", bfc = BiocFileCache::BiocFileCache(cache_dir), verbose = TRUE )
Create igraph visualization with improved layout
subset_kegg_graph(g, ids_to_include)subset_kegg_graph(g, ids_to_include)
g |
An igraph object to visualize. Must have vertex attributes 'x' and 'y' for layout. |
ids_to_include |
Character vector of KEGG IDs to include in the subset graph. |
All the edges between the vertices are plotted automatically.
A plot of the igraph object with improved layout.
pathway <- "mmu00230" g <- create_kegg_graph(pathway) KEGG_to_include <- c("C00262", "C00385", "C00366", "C00294", "C00387", "C01762", "C05512", "C00301", "C01185", "C00455", "22436", "14544", "18950", "11486", "80285", "59027") subg <- subset_kegg_graph(g, KEGG_to_include) # plot(g) # plot(subg)pathway <- "mmu00230" g <- create_kegg_graph(pathway) KEGG_to_include <- c("C00262", "C00385", "C00366", "C00294", "C00387", "C01762", "C05512", "C00301", "C01185", "C00455", "22436", "14544", "18950", "11486", "80285", "59027") subg <- subset_kegg_graph(g, KEGG_to_include) # plot(g) # plot(subg)