| Title: | KEGG-Based Metabolic and Signaling Network Analysis for Systems Biology |
|---|---|
| Description: | Provides tools to construct KEGG-based metabolic and signaling networks as edge lists for single-organism or cross-species analyses. The package supports identifier mapping, shortest-path and topology analyses, community detection, permutation testing, pathway over-representation analysis, and node annotation for host-microbiome studies. It also provides network visualisation in R and Cytoscape and supports extension of KEGG-based networks through additional reaction resources and user-defined reactions. |
| Authors: | Zhaojie Wang [aut, cre] (ORCID: <https://orcid.org/0009-0009-7191-2107>), Francesc Puig-Castellvi [aut], Manyi Jia [aut], Marc-Emmanuel Dumas [aut, ths] |
| Maintainer: | Zhaojie Wang <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.1 |
| Built: | 2026-06-09 16:38:29 UTC |
| Source: | https://github.com/BiocStaging/MetaPathNet |
A precomputed host-microbe example network constructed from human and Escherichia coli KEGG pathways related to tryptophan metabolism and immune/signaling context. This dataset is intended for runnable examples, tests, and package demonstrations without requiring live KEGG queries.
data(MetaPathNet_example_network)data(MetaPathNet_example_network)
A character matrix with 1769 rows and 3 columns:
Source node identifier.
Target node identifier.
Interaction type between source and target.
A character matrix containing source nodes, target nodes, and interaction types.
Constructed using MPN_keggNetwork() and
MPN_mergeNetworks() from KEGG pathways hsa00380,
hsa04060, hsa04630, hsa04064, hsa04660,
hsa04659, eco00380, and eco00400.
Annotates KEGG Orthology (KO) nodes in a MetaPathNet-style network by
pathway context: "metabolic", "signaling", or
"metabolic&signaling". Classification is derived from KEGG BRITE
pathway hierarchy and KO-to-pathway links. The function returns a KO-level
annotation table (compound nodes excluded) and can optionally export a
Cytoscape network with KO class colouring.
MPN_annotateKoClass( network_table, name = FALSE, export_cytoscape = FALSE, compound_color = "#9DC7DD", metabolic_color = "#9ED17B", signaling_color = "#C45745", metabolic_signaling_color = "#B57F60", other_color = "#D1C2C2", network_title = "", collection_title = "" )MPN_annotateKoClass( network_table, name = FALSE, export_cytoscape = FALSE, compound_color = "#9DC7DD", metabolic_color = "#9ED17B", signaling_color = "#C45745", metabolic_signaling_color = "#B57F60", other_color = "#D1C2C2", network_title = "", collection_title = "" )
network_table |
A MetaPathNet-style network with at least two columns:
|
name |
Logical. If |
export_cytoscape |
Logical. If |
compound_color |
Hex colour for compound nodes (used only when
|
metabolic_color |
Hex colour for KO nodes classified as
|
signaling_color |
Hex colour for KO nodes classified as
|
metabolic_signaling_color |
Hex colour for KO nodes classified as
|
other_color |
Hex colour for KO nodes whose class cannot be determined
and for non-compound, non-KO nodes (used only when
|
network_title |
Character. Cytoscape network title (used only when
|
collection_title |
Character. Cytoscape collection title (used only when
|
Cytoscape (version >= 3.9.0) must be open and reachable via
RCy3 only when export_cytoscape = TRUE.
Reverse duplicated edges are collapsed for Cytoscape display when they
share the same metabolic interaction type
KO functional class is derived from the KEGG BRITE pathway hierarchy
(br:br08901). Pathways under the "Metabolism" branch are
classified as metabolic, whereas all other linked pathways are treated as
signaling for this annotation workflow.
A data frame with columns id, type, name, and
ko_class. Compound nodes are excluded from the returned table.
If export_cytoscape = TRUE, the same annotation is also applied to a
Cytoscape network as a side effect, with node colours mapped to
ko_class; the function invisibly returns the annotation data frame.
MPN_annotateOrigin for host vs bacteria origin, and
MPN_viewNetworkCy for generic Cytoscape visualisation of
MetaPathNet networks.
## 1) Prepare a mixed human–E. coli tryptophan-focused network ## Human: tryptophan metabolism + selected immune/inflammatory signaling pathways ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Combined host–microbe network net_trp_mixed <- MetaPathNet_example_network ## 2) Build a shortest-path subnetwork (used here as the input network_table) source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## 3) KO class annotation table (data frame output) ko_class_df <- MPN_annotateKoClass( network_table = paths_trp_mixed, name = FALSE )## 1) Prepare a mixed human–E. coli tryptophan-focused network ## Human: tryptophan metabolism + selected immune/inflammatory signaling pathways ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Combined host–microbe network net_trp_mixed <- MetaPathNet_example_network ## 2) Build a shortest-path subnetwork (used here as the input network_table) source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## 3) KO class annotation table (data frame output) ko_class_df <- MPN_annotateKoClass( network_table = paths_trp_mixed, name = FALSE )
Annotates nodes in a MetaPathNet-style network with inferred biological
origin, focusing on KEGG Orthology (KO) nodes. KO origin is classified as
human-only ("hsa"), bacteria-only ("bacteria"),
shared ("hsa&bacteria"), or "other" based on KEGG annotations.
Compound nodes are assigned the separate class "compound".
MPN_annotateOrigin( network_table, bacteria_codes = NULL, name = FALSE, export_cytoscape = FALSE, compound_color = "#9DC7DD", hsa_color = "#C45745", micro_color = "#9ED17B", hsa_micro_color = "#B57F60", other_color = "#D1C2C2", network_title = "", collection_title = "" )MPN_annotateOrigin( network_table, bacteria_codes = NULL, name = FALSE, export_cytoscape = FALSE, compound_color = "#9DC7DD", hsa_color = "#C45745", micro_color = "#9ED17B", hsa_micro_color = "#B57F60", other_color = "#D1C2C2", network_title = "", collection_title = "" )
network_table |
A MetaPathNet-style network with at least two columns:
|
bacteria_codes |
Optional character vector of KEGG organism codes.
Restricts the |
name |
Logical. If |
export_cytoscape |
Logical (default |
compound_color |
Hex colour for compound nodes. |
hsa_color |
Hex colour for KO nodes classified as |
micro_color |
Hex colour for KO nodes classified as |
hsa_micro_color |
Hex colour for KO nodes classified as |
other_color |
Hex colour for KO nodes classified as |
network_title |
Character. Cytoscape network title (used only when
|
collection_title |
Character. Cytoscape collection title (used only when
|
The primary output is a node-level annotation table (ID, type, display name, origin). Cytoscape export is optional and can be enabled to visualise the annotated network with origin-based node colours.
KO origin is inferred from KEGG GENES annotations via
KEGGREST::keggGet():
"hsa" if the KO has human genes only.
"bacteria" if the KO has bacterial genes only.
"hsa&bacteria" if both human and bacterial genes are present.
"other" if none of the above can be established.
Bacterial organism codes are derived from KEGGREST::keggList("organism")
using the "Prokaryotes;Bacteria" phylogeny prefix. The
bacteria_codes argument can be used to restrict the bacterial origin
class to a user-defined organism panel (e.g. cohort-specific microbes).
If bacteria_codes = NULL (default), all KEGG bacterial organism codes
are used.
Cytoscape (v3.9.0) must be running
Reverse duplicated edges are collapsed for Cytoscape display when they share the same metabolic interaction type
A node-level data frame with columns:
id: KEGG node identifier.
type: coarse node type ("KO", "Compound", "Other").
name: display label (KEGG ID or converted KEGG name/symbol).
origin: inferred origin class ("compound", "hsa",
"bacteria", "hsa&bacteria", "other").
If export_cytoscape = TRUE, the function also creates and styles a
Cytoscape network as a side effect, and returns the same annotation table
invisibly.
MPN_annotateKoClass for KO functional class annotation, and
MPN_viewNetworkCy for generic Cytoscape rendering.
## 1) Build a mixed human-E. coli Trp-focused network (used below) ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp_mixed <- MetaPathNet_example_network ## 2) Build a shortest-path subnetwork (paths_trp_mixed) for origin annotation source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01610", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108", "cpd:C00458", "cpd:C00336") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## 3) Return annotation table only (main use) origin_paths_trp_mixed <- MPN_annotateOrigin( network_table = paths_trp_mixed, bacteria_codes = NULL, # NULL = use all KEGG bacterial organism codes name = FALSE, # convert IDs to KEGG names/symbols in the output table export_cytoscape = FALSE )## 1) Build a mixed human-E. coli Trp-focused network (used below) ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp_mixed <- MetaPathNet_example_network ## 2) Build a shortest-path subnetwork (paths_trp_mixed) for origin annotation source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01610", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108", "cpd:C00458", "cpd:C00336") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## 3) Return annotation table only (main use) origin_paths_trp_mixed <- MPN_annotateOrigin( network_table = paths_trp_mixed, bacteria_codes = NULL, # NULL = use all KEGG bacterial organism codes name = FALSE, # convert IDs to KEGG names/symbols in the output table export_cytoscape = FALSE )
Applies graph-based community detection (Louvain or Leiden) to a KEGG-derived network and returns an annotated edge list with cluster membership for each source and target node. This supports module-based interpretation and visualisation of large metabolic / signalling networks.
MPN_clusterNetwork( network_table, method = c("louvain", "leiden"), resolution = 0.1 )MPN_clusterNetwork( network_table, method = c("louvain", "leiden"), resolution = 0.1 )
network_table |
A matrix or data.frame with at least 3 columns,
representing a directed KEGG-based network (typically from
|
method |
Character. Community detection algorithm:
|
resolution |
Numeric (default: |
Community detection is performed on the full graph (all nodes together), using an undirected collapsed version of the input network.
In the returned edge list, source_cluster and target_cluster
are endpoint annotations: they indicate the community membership of the
source node and target node of each edge, respectively.
This edge-level annotation format is used to keep the output compatible
with downstream visualisation and filtering functions (e.g.
MPN_viewClusterCy() and MPN_viewNetworkR()).
In MetaPathNet, these cluster assignments can also be used to define modules for downstream enrichment or ego-network extraction.
A matrix with the same rows as network_table and the original
first three columns:
Source node identifier.
Target node identifier.
Interaction or edge annotation.
plus two additional columns:
Community label of the source node.
Community label of the target node.
Blondel, V. D., Guillaume, J.-L., Lambiotte, R., and Lefebvre, E. (2008). Fast unfolding of communities in large networks. Journal of Statistical Mechanics: Theory and Experiment, 2008(10), P10008. doi:10.1088/1742-5468/2008/10/P10008
Traag, V. A., Waltman, L., and van Eck, N. J. (2019). From Louvain to Leiden: guaranteeing well-connected communities. Scientific Reports, 9, 5233. doi:10.1038/s41598-019-41695-z
MPN_keggNetwork, MPN_crossSpeciesNetwork,
MPN_viewClusterCy, MPN_viewNetworkR
## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp <- MetaPathNet_example_network ## 2) Run community detection on the example network net_trp_clusters <- MPN_clusterNetwork( network_table = net_trp, method = "leiden", resolution = 0.01 ) ## 3) (Optional) Visualise one cluster in R ## Here, source_cluster and target_cluster are node-cluster labels ## attached to each edge endpoint. subnet_cluster1 <- net_trp_clusters[ net_trp_clusters[, "source_cluster"] == 1 | net_trp_clusters[, "target_cluster"] == 1, ] p_cluster1 <- MPN_viewNetworkR( network_table = subnet_cluster1, category = TRUE, name = TRUE, layout = "fr", node_size = 3, network_title = "Cluster 1 subnetwork in example network" ) print(p_cluster1) ## Not run: ## Requires a running Cytoscape session for network layout and rendering ## 4) Recommended: full cluster-aware visualisation in Cytoscape MPN_viewClusterCy( cluster_matrix = net_trp_clusters, label = "all", # convert KEGG IDs to biological names and label all nodes category = TRUE, # shape by node type (Compound / KO / Contextual) network_title = "Example network clusters", collection_title = "MetaPathNet_Examples" ) ## End(Not run)## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp <- MetaPathNet_example_network ## 2) Run community detection on the example network net_trp_clusters <- MPN_clusterNetwork( network_table = net_trp, method = "leiden", resolution = 0.01 ) ## 3) (Optional) Visualise one cluster in R ## Here, source_cluster and target_cluster are node-cluster labels ## attached to each edge endpoint. subnet_cluster1 <- net_trp_clusters[ net_trp_clusters[, "source_cluster"] == 1 | net_trp_clusters[, "target_cluster"] == 1, ] p_cluster1 <- MPN_viewNetworkR( network_table = subnet_cluster1, category = TRUE, name = TRUE, layout = "fr", node_size = 3, network_title = "Cluster 1 subnetwork in example network" ) print(p_cluster1) ## Not run: ## Requires a running Cytoscape session for network layout and rendering ## 4) Recommended: full cluster-aware visualisation in Cytoscape MPN_viewClusterCy( cluster_matrix = net_trp_clusters, label = "all", # convert KEGG IDs to biological names and label all nodes category = TRUE, # shape by node type (Compound / KO / Contextual) network_title = "Example network clusters", collection_title = "MetaPathNet_Examples" ) ## End(Not run)
Builds a compound-centred ego subnetwork around one or more KEGG compounds across one or several organisms. The resulting network is returned as a MetaPathNet-style edge list (3-column matrix) that can be used directly for visualisation or further network analysis.
MPN_compoundEgoNetwork( compounds, organism_codes, path_type = c("metabolic", "signaling", "integrated"), order = 2, mode = c("out", "all", "in") )MPN_compoundEgoNetwork( compounds, organism_codes, path_type = c("metabolic", "signaling", "integrated"), order = 2, mode = c("out", "all", "in") )
compounds |
Character vector of KEGG compound identifiers. Only IDs in
the formats |
organism_codes |
Character vector of one or more KEGG organism codes
(e.g. |
path_type |
Character; type of pathways to include when building the organism-specific networks. One of:
The classification is derived from |
order |
Integer (default: |
mode |
Character; directionality of the ego search, passed to
|
Organism-specific ego subnetworks are merged, deduplicated, and returned as a single combined network.
Internally, compound–pathway mapping is performed via KEGG REST / KGML
queries (using a non-exported helper), then routed through
MPN_keggNetwork and MPN_egoNetwork. These details
are handled automatically and do not require user intervention.
A character matrix with three columns:
Source node of each edge in the combined ego subnetwork.
Target node of each edge in the combined ego subnetwork.
Interaction or edge type, as returned by
MPN_keggNetwork (e.g. "k_compound:reversible",
"k_activation", etc.).
If no ego subnetworks can be generated for the given inputs, the function stops with an error.
MPN_getPathIDs,
MPN_keggNetwork,
MPN_egoNetwork
## Not run: ## Requires extensive KEGG API querying; runtime depends on server response ## 1) Define Trp/kynurenine/serotonin/anthranilate seeds seed_compounds <- c( "cpd:C00078", # L-tryptophan "cpd:C00328", # L-kynurenine "cpd:C00780", # serotonin "cpd:C00108" # anthranilate ) ## 2) Build ego network (order = 2, metabolic pathways, human only) ego_trp_hsa <- MPN_compoundEgoNetwork( compounds = seed_compounds, organism_codes = "hsa", path_type = "metabolic", order = 2, mode = "out" ) ## 3) (Optional) Visualise in Cytoscape ## Cytoscape must be open and running MPN_viewNetworkCy( network_table = ego_trp_hsa, name = TRUE, category = TRUE, network_title = "Human metabolic ego network", collection_title = "MetaPathNet_Examples" ) ## End(Not run)## Not run: ## Requires extensive KEGG API querying; runtime depends on server response ## 1) Define Trp/kynurenine/serotonin/anthranilate seeds seed_compounds <- c( "cpd:C00078", # L-tryptophan "cpd:C00328", # L-kynurenine "cpd:C00780", # serotonin "cpd:C00108" # anthranilate ) ## 2) Build ego network (order = 2, metabolic pathways, human only) ego_trp_hsa <- MPN_compoundEgoNetwork( compounds = seed_compounds, organism_codes = "hsa", path_type = "metabolic", order = 2, mode = "out" ) ## 3) (Optional) Visualise in Cytoscape ## Cytoscape must be open and running MPN_viewNetworkCy( network_table = ego_trp_hsa, name = TRUE, category = TRUE, network_title = "Human metabolic ego network", collection_title = "MetaPathNet_Examples" ) ## End(Not run)
Converts Ensembl or Entrez gene identifiers to KEGG gene IDs and, optionally, to KEGG Orthology (KO) IDs using mygene and KEGGREST. The input gene type must be specified.
MPN_convertGene(genes, gene_type = c("ensembl", "entrez"), orthology = TRUE)MPN_convertGene(genes, gene_type = c("ensembl", "entrez"), orthology = TRUE)
genes |
A character vector of gene IDs. All IDs must be of the same type,
specified by |
gene_type |
Type of gene ID supplied. One of |
orthology |
Logical; if |
This function supports integration of commonly used gene identifier systems (Ensembl/Entrez) into KO-based and KEGG network workflows.
The returned data frame keeps all input IDs, including those that cannot
be mapped; unmapped entries are labelled as "unmapped" in the
corresponding columns. This is useful when building KO- or pathway-centric
views of host genes, for example in tryptophan–kynurenine metabolism or
other immune–metabolic axes.
Only one gene type can be used per call; mixed Ensembl/Entrez input must be split beforehand.
When gene_type = "ensembl", Ensembl IDs are first converted to
Entrez IDs using mygene, then mapped to KEGG gene IDs via
KEGGREST.
When gene_type = "entrez", input IDs are checked for a numeric
pattern; non-numeric entries are retained and marked as
"unmapped".
KEGG gene IDs are optionally mapped to KO terms using
keggLink when orthology = TRUE.
If any step fails (no Entrez, no KEGG gene, or no KO), the
corresponding field is set to "unmapped"; no rows are dropped.
A data.frame with columns:
Input_ID: original gene ID (Ensembl or Entrez).
Entrez_ID: mapped Entrez ID, or "unmapped".
KEGG_ID: mapped KEGG gene ID, or "unmapped".
KO_ID: mapped KEGG Orthology ID, or "unmapped"
(present only when orthology = TRUE).
## Example 1 — Ensembl IDs for human tryptophan–kynurenine genes trp_kynurenine_ens <- c("ENSG00000151790", "ENSG00000131203") MPN_convertGene( genes = trp_kynurenine_ens, gene_type = "ensembl", orthology = TRUE ) ## Example 2 — Entrez IDs linked to downstream MetaPathNet network use ## Human enzymes TDO2 (6999) and IDO1 (3620), plus tnaA (948221; a typical microbial enzyme), ## are included here to illustrate how converted KO terms can be checked in a human network. trp_kynurenine_genes <- c("6999", "3620", "948221") trp_kyn_conversion <- MPN_convertGene( genes = trp_kynurenine_genes, gene_type = "entrez", orthology = TRUE )## Example 1 — Ensembl IDs for human tryptophan–kynurenine genes trp_kynurenine_ens <- c("ENSG00000151790", "ENSG00000131203") MPN_convertGene( genes = trp_kynurenine_ens, gene_type = "ensembl", orthology = TRUE ) ## Example 2 — Entrez IDs linked to downstream MetaPathNet network use ## Human enzymes TDO2 (6999) and IDO1 (3620), plus tnaA (948221; a typical microbial enzyme), ## are included here to illustrate how converted KO terms can be checked in a human network. trp_kynurenine_genes <- c("6999", "3620", "948221") trp_kyn_conversion <- MPN_convertGene( genes = trp_kynurenine_genes, gene_type = "entrez", orthology = TRUE )
Constructs and merges MetaPathNet tables (integrated metabolic and/or signaling networks) across one or multiple KEGG organisms.
MPN_crossSpeciesNetwork( organism_codes, path_type = c("metabolic", "signaling", "integrated") )MPN_crossSpeciesNetwork( organism_codes, path_type = c("metabolic", "signaling", "integrated") )
organism_codes |
Character vector of KEGG organism codes (e.g., "hsa" for Homo sapiens, "eco" for E. coli, "bsu" for Bacillus subtilis). |
path_type |
Character. One of:
|
KEGG pathway lists are retrieved via MPN_getPathIDs() for all requested organisms.
Each species is processed separately, generating a species-specific MetaPathNet table
via MPN_keggNetwork() according to path_type.
Species-level tables are then merged and deduplicated into a single cross-species network.
A data frame representing the merged MetaPathNet network, with three columns:
Source node (KO, compound, or gene).
Target node (KO, compound, or gene).
Type of biological interaction or reaction.
MPN_getPathIDs for retrieving pathway lists,
and MPN_keggNetwork for building individual pathway networks.
## Cross-species metabolic network (human + E. coli strains) ## Note: Network construction can be time-consuming and depends on KEGG server response host_microbe_code <- c("ece", "eco", "ecoo", "ecc", "ecs", "hsa") ## Not run: ## Requires extensive KEGG API querying; runtime depends on server response net_hsa_ecoli <- MPN_crossSpeciesNetwork( organism_codes = host_microbe_code, path_type = "metabolic" # metabolic layer only ) ## End(Not run)## Cross-species metabolic network (human + E. coli strains) ## Note: Network construction can be time-consuming and depends on KEGG server response host_microbe_code <- c("ece", "eco", "ecoo", "ecc", "ecs", "hsa") ## Not run: ## Requires extensive KEGG API querying; runtime depends on server response net_hsa_ecoli <- MPN_crossSpeciesNetwork( organism_codes = host_microbe_code, path_type = "metabolic" # metabolic layer only ) ## End(Not run)
Convert one or more manually curated reactions into the standard
MetaPathNet 3-column edge list format
(source, target, interaction_type).
MPN_customReaction( reaction_table, substrate_col = "substrates", product_col = "products", ko_col = NULL, direction_col = NULL )MPN_customReaction( reaction_table, substrate_col = "substrates", product_col = "products", ko_col = NULL, direction_col = NULL )
reaction_table |
A data.frame in which each row corresponds to one custom reaction. |
substrate_col |
Character. Name of the column containing substrate node IDs. Multiple IDs must be separated by semicolons. |
product_col |
Character. Name of the column containing product node IDs. Multiple IDs must be separated by semicolons. |
ko_col |
Optional character. Name of the column containing KO IDs.
Multiple IDs must be separated by semicolons. If |
direction_col |
Optional character. Name of the column containing
reaction direction. Accepted values are |
Each input row represents one reaction. Substrates and products can contain
one or multiple node IDs, separated by semicolons. Optional KO annotations
can be provided to build compound-KO-compound edges; otherwise the function
returns direct compound-compound edges. User-defined compounds or enzymes can
first be mapped to KEGG identifiers with MPN_keggFinder() when possible.
A character matrix with three columns:
Source node ID.
Target node ID.
Reaction type, e.g.
"custom:reversible", "custom:irreversible", or
"custom:unknown".
MPN_keggFinder, MPN_mapReaction,
MPN_mergeNetworks
## Example — Add a user-defined irreversible reaction ## 1) Build a custom reaction table ## Multiple substrates, products, or KO terms must be separated by semicolons. custom_df <- data.frame( reaction_id = "custom_reaction_1", substrates = "cpd:C00078; cpd:C00001", products = "cpd:C00328", ko = "K00453", direction = "irreversible", stringsAsFactors = FALSE ) ## 2) Convert the user-defined reaction into MetaPathNet-style edges custom_edges <- MPN_customReaction( reaction_table = custom_df, substrate_col = "substrates", product_col = "products", ko_col = "ko", direction_col = "direction" ) custom_edges## Example — Add a user-defined irreversible reaction ## 1) Build a custom reaction table ## Multiple substrates, products, or KO terms must be separated by semicolons. custom_df <- data.frame( reaction_id = "custom_reaction_1", substrates = "cpd:C00078; cpd:C00001", products = "cpd:C00328", ko = "K00453", direction = "irreversible", stringsAsFactors = FALSE ) ## 2) Convert the user-defined reaction into MetaPathNet-style edges custom_edges <- MPN_customReaction( reaction_table = custom_df, substrate_col = "substrates", product_col = "products", ko_col = "ko", direction_col = "direction" ) custom_edges
Compute shortest-path distances between selected source and target nodes
in a KEGG-based network produced by MPN_keggNetwork() (or related
functions). Source nodes are often KEGG KOs (upstream biological functions)
and target nodes are often KEGG compounds (downstream metabolites), but this
is a recommended usage pattern rather than a strict requirement.
MPN_distances( network_table, mode = c("out", "in", "all"), source_nodes, target_nodes, name = FALSE )MPN_distances( network_table, mode = c("out", "in", "all"), source_nodes, target_nodes, name = FALSE )
network_table |
A 3-column matrix or data.frame of edges
( |
mode |
Character, passed to
|
source_nodes |
Character vector of source nodes. Use |
target_nodes |
Character vector of target nodes. Use |
name |
Logical (default |
The function builds a directed igraph object from the first two columns
of network_table and computes pairwise shortest-path distances using
igraph::distances(). For unweighted networks such as MetaPathNet edge
lists, distance lengths are computed with a breadth-first search strategy.
Compound-like node IDs supplied as "Cxxxxx" or "cpd:Cxxxxx"
are treated equivalently and internally harmonised to "cpd:Cxxxxx".
If both source_nodes = "all" and target_nodes = "all", the
function automatically assigns non-compound nodes (e.g. KOs/genes) as sources
and compound-like nodes (cpd:, dr:, gl:) as targets.
If any node is present in both the mapped source and target sets, the function stops and reports the overlapping node(s), because distance from a node to itself is 0 and is not allowed in this workflow.
Distances equal to Inf indicate unreachable source-target pairs under
the selected mode, i.e. no valid path exists between those nodes in
the current network direction setting.
If name = TRUE, KEGGREST::keggGet() is used to retrieve KEGG
names. This may be slow for large node sets.
A numeric matrix of shortest-path distances. Rows correspond to source nodes and columns to target nodes.
## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## 2) Define node sets of interest in this network ## - source_nodes: KOs representing enzymes/genes of interest in Trp/kynurenine biology ## - target_nodes: KEGG compounds representing metabolites of interest in the same context ## Note: MPN_distances can accept any node types, but source/target must be disjoint: ## if a node is in both sets, the function stops because self-distance is 0. source_nodes <- c("K00486", "K00453", "K00463", "K09093", "K01667") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463") ## Keep only nodes that are present in the network (avoid "not mapped" errors) map_src <- MPN_findMappedNodes(source_nodes, MetaPathNet_example_network) map_tgt <- MPN_findMappedNodes(target_nodes, MetaPathNet_example_network) ## 3) Compute the shortest-path distance matrix dist_trp <- MPN_distances( network_table = MetaPathNet_example_network, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, name = FALSE ) dist_trp## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## 2) Define node sets of interest in this network ## - source_nodes: KOs representing enzymes/genes of interest in Trp/kynurenine biology ## - target_nodes: KEGG compounds representing metabolites of interest in the same context ## Note: MPN_distances can accept any node types, but source/target must be disjoint: ## if a node is in both sets, the function stops because self-distance is 0. source_nodes <- c("K00486", "K00453", "K00463", "K09093", "K01667") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463") ## Keep only nodes that are present in the network (avoid "not mapped" errors) map_src <- MPN_findMappedNodes(source_nodes, MetaPathNet_example_network) map_tgt <- MPN_findMappedNodes(target_nodes, MetaPathNet_example_network) ## 3) Compute the shortest-path distance matrix dist_trp <- MPN_distances( network_table = MetaPathNet_example_network, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, name = FALSE ) dist_trp
Builds an ego (neighbourhood) subnetwork around one or more seed nodes in a
directed network, up to a user-defined distance (order). In graph
terminology, ego refers to the focal node(s) used as the starting
point(s), and the function returns the local network around them. This is
useful to inspect which nodes connect to a selected compound, KO, or other
node(s) within a chosen radius in a pathway- or organism-specific network.
MPN_egoNetwork( network_table, nodes, order = 2, mode = c("out", "all", "in"), mindist = 0, output = c("matrix", "vector") )MPN_egoNetwork( network_table, nodes, order = 2, mode = c("out", "all", "in"), mindist = 0, output = c("matrix", "vector") )
network_table |
A three-column matrix or data.frame representing a
directed network. The first three columns must correspond to
|
nodes |
Character vector of one or more node IDs (e.g.
|
order |
Integer (default |
mode |
Character. Directionality of the search, passed to
|
mindist |
Integer (default |
output |
Character. Type of result:
|
The default output is a 3-column MetaPathNet-style edge list
(source, target, interaction_type); alternatively, the
function can return only the unique node vector of the ego neighbourhood.
Internally, the function:
checks and normalizes network_table and input nodes;
builds a directed igraph object from the first three columns;
maps the requested ego nodes to existing vertex names (with a message for nodes not found);
uses igraph::ego() to collect all vertices within
[mindist, order] of the mapped egos;
returns either the induced edge list ("matrix") or the node
set ("vector").
For large networks and high values of order, ego subnetworks can
become large and slower to generate. It is often practical to start with
order = 1 or 2 and increase only if needed.
If output = "matrix", a character matrix with columns
source, target, interaction_type representing the
induced subnetwork on all nodes within [mindist, order] of the ego
nodes (according to mode). If no edges are found, an empty
3-column matrix with these columns is returned.
If output = "vector", a character vector of unique node IDs in the
ego subnetwork is returned.
Ego-network (ego graph) concept is standard in social/network analysis; see Wasserman S, Faust K (1994). Social Network Analysis: Methods and Applications. Cambridge University Press.
The neighbourhood extraction in this function is implemented with
igraph::ego() from the igraph package.
ego,
induced_subgraph,
MPN_enrichPathway,
MPN_viewNetworkR
## Example — Ego subnetwork around tryptophan-related metabolites in a mixed hsa/eco network ## 1) Build a mixed host–microbe network for tryptophan-related metabolism ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Combined host–microbe network net_trp_mixed <- MetaPathNet_example_network ## 2) Extract an ego subnetwork around key metabolites used as seed nodes ## (tryptophan, serotonin, and indole are central compounds in the example storyline) ego_trp_compounds <- MPN_egoNetwork( network_table = net_trp_mixed, nodes = c( "cpd:C00078", # L-tryptophan "cpd:C00780", # serotonin "cpd:C00463" # indole ), order = 2, mode = "out", mindist = 0, output = "matrix" )## Example — Ego subnetwork around tryptophan-related metabolites in a mixed hsa/eco network ## 1) Build a mixed host–microbe network for tryptophan-related metabolism ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Combined host–microbe network net_trp_mixed <- MetaPathNet_example_network ## 2) Extract an ego subnetwork around key metabolites used as seed nodes ## (tryptophan, serotonin, and indole are central compounds in the example storyline) ego_trp_compounds <- MPN_egoNetwork( network_table = net_trp_mixed, nodes = c( "cpd:C00078", # L-tryptophan "cpd:C00780", # serotonin "cpd:C00463" # indole ), order = 2, mode = "out", mindist = 0, output = "matrix" )
Performs pathway enrichment analysis (over-representation analysis, ORA) using the hypergeometric test with Benjamini–Hochberg correction on nodes from KEGG-derived networks. Supports KO-level, compound-level, or integrated (KO + compound) analyses.
MPN_enrichPathway( test_set, background_set, pathway_set, entity = c("ko", "compound", "integrated"), pvalueCutoff = 0.05, add_hits = FALSE )MPN_enrichPathway( test_set, background_set, pathway_set, entity = c("ko", "compound", "integrated"), pvalueCutoff = 0.05, add_hits = FALSE )
test_set |
Character vector of node IDs (e.g. KEGG compounds, KO IDs), or a network matrix/data.frame, in which case unique nodes from the first two columns are used. |
background_set |
Character vector of node IDs or a network matrix/data.frame defining the background universe for enrichment analysis. |
pathway_set |
Either a character vector of KEGG reference pathway IDs or a named list where each element contains the node members of one pathway. |
entity |
Character string specifying which entity type is tested:
|
pvalueCutoff |
Numeric. Significance cutoff for adjusted p-values
(default |
add_hits |
Logical. If |
If test_set or background_set is a matrix/data.frame, unique
nodes are taken from the first two columns. The test set is intersected with
the background (test_set <= background_set) before enrichment.
Enrichment is computed with the hypergeometric distribution (phyper)
followed by Benjamini–Hochberg FDR adjustment.
A data frame with columns:
KEGG pathway ID (e.g. "map00380").
Pathway description from KEGG.
Number of background nodes in the pathway.
Number of test nodes in the pathway.
(Optional) Semicolon-separated test nodes in the pathway.
Raw hypergeometric p-value.
Adjusted p-value (Benjamini–Hochberg).
(test_overlap / |test_set|) / (bg_overlap / |background_set|).
"significant" or "NS" based on pvalueCutoff.
Pathways with zero test hits are excluded automatically. Very small test sets or test sets almost identical to the background may yield uninformative results (p-values close to 1).
MPN_egoNetwork, MPN_getPathIDs,
keggLink, keggCompounds
## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Define a small test set from the example network test_nodes <- c("K00463", "K00453", "cpd:C00078", "cpd:C02700") ## Run integrated pathway over-representation analysis enrich_res <- MPN_enrichPathway( test_set = test_nodes, background_set = MetaPathNet_example_network, pathway_set = c("map00380", "map00400"), entity = "integrated", pvalueCutoff = 1, add_hits = TRUE ) ## Preview enrichment results head(enrich_res)## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Define a small test set from the example network test_nodes <- c("K00463", "K00453", "cpd:C00078", "cpd:C02700") ## Run integrated pathway over-representation analysis enrich_res <- MPN_enrichPathway( test_set = test_nodes, background_set = MetaPathNet_example_network, pathway_set = c("map00380", "map00400"), entity = "integrated", pvalueCutoff = 1, add_hits = TRUE ) ## Preview enrichment results head(enrich_res)
Check which nodes from a user-supplied vector are present in a given network edge list and which are absent.
MPN_findMappedNodes(nodes, network_table)MPN_findMappedNodes(nodes, network_table)
nodes |
Character vector of node IDs (e.g. KEGG compounds, KO IDs, reaction IDs) to check. |
network_table |
Matrix or data frame (2 or 3 columns) representing a
network, typically generated by |
This function is a small utility to verify that user-specified compounds, genes/KOs, or reactions are present in a network before running downstream analyses (e.g. distance calculations, shortest paths, ego networks).
A list with two components:
Character vector of nodes found in the network.
Character vector of nodes not found in the network.
## Example — Check presence of Trp-pathway nodes in a MetaPathNet example network ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Define a small set of candidate nodes (compounds + KO + fake ID) candidate_nodes <- c( "C00078", # tryptophan (will be normalised to "cpd:C00078") "cpd:C00328", # L-kynurenine "K00463", # tryptophan synthase beta chain "NotID" # fake node, should be unmapped ) ## Check which of these nodes are present in the network res <- MPN_findMappedNodes( nodes = candidate_nodes, network_table = MetaPathNet_example_network ) res$mapped_nodes # present in MetaPathNet_example_network res$unmapped_nodes # absent from MetaPathNet_example_network## Example — Check presence of Trp-pathway nodes in a MetaPathNet example network ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Define a small set of candidate nodes (compounds + KO + fake ID) candidate_nodes <- c( "C00078", # tryptophan (will be normalised to "cpd:C00078") "cpd:C00328", # L-kynurenine "K00463", # tryptophan synthase beta chain "NotID" # fake node, should be unmapped ) ## Check which of these nodes are present in the network res <- MPN_findMappedNodes( nodes = candidate_nodes, network_table = MetaPathNet_example_network ) res$mapped_nodes # present in MetaPathNet_example_network res$unmapped_nodes # absent from MetaPathNet_example_network
Retrieves KEGG pathway IDs for one or more organisms and assigns each to a functional category and type based on KEGG BRITE hierarchy.
MPN_getPathIDs(organism_code)MPN_getPathIDs(organism_code)
organism_code |
Character vector of KEGG organism codes. |
Pathway classification uses the KEGG BRITE hierarchy br08901.
Pathways under the top-level category "Metabolism" are typed as
"metabolic"; all others are typed as "signaling". Global
and overview maps are excluded from the output.
A data.frame with columns:
Full KEGG pathway ID.
Full KEGG pathway name.
Top-level and subcategory from KEGG BRITE hierarchy.
"metabolic" or "signaling", based on top-level category.
KEGG organism code.
MPN_keggNetwork for building networks from these pathway sets.
## 1) Retrieve all human pathways and filter for tryptophan metabolism path_hsa <- MPN_getPathIDs("hsa") trp_hsa <- subset(path_hsa, grepl("Tryptophan metabolism", Path_description)) head(trp_hsa) ## 2) Retrieve pathways for multiple organisms org_vec <- c("hsa", "eco", "bsu") path_multi <- MPN_getPathIDs(org_vec) ## 3) Show pathways shared across the selected organisms ## (appear once per species, so shared ones have count == length(org_vec)) shared_counts <- table(path_multi$Path_description) head(shared_counts[shared_counts == length(org_vec)]) ## 4) Filter tryptophan metabolism pathways and show which species contain them trp_multi <- subset(path_multi, grepl("Tryptophan metabolism", Path_description)) head(trp_multi) table(trp_multi$Species)## 1) Retrieve all human pathways and filter for tryptophan metabolism path_hsa <- MPN_getPathIDs("hsa") trp_hsa <- subset(path_hsa, grepl("Tryptophan metabolism", Path_description)) head(trp_hsa) ## 2) Retrieve pathways for multiple organisms org_vec <- c("hsa", "eco", "bsu") path_multi <- MPN_getPathIDs(org_vec) ## 3) Show pathways shared across the selected organisms ## (appear once per species, so shared ones have count == length(org_vec)) shared_counts <- table(path_multi$Path_description) head(shared_counts[shared_counts == length(org_vec)]) ## 4) Filter tryptophan metabolism pathways and show which species contain them trp_multi <- subset(path_multi, grepl("Tryptophan metabolism", Path_description)) head(trp_multi) table(trp_multi$Species)
Map user-supplied compound, organism, or KO queries to KEGG identifiers.
MPN_keggFinder( KEGG_database = c("compound", "organism", "ko"), searchBy = NULL, query = NULL )MPN_keggFinder( KEGG_database = c("compound", "organism", "ko"), searchBy = NULL, query = NULL )
KEGG_database |
Character string specifying the KEGG entry type:
|
searchBy |
Character string specifying the query type.
For |
query |
Vector of queries to be matched. Non-character input is
coerced to |
For compounds, name queries are first matched against the live KEGG compound table. Unresolved queries, as well as SID, CID, SMILES, InChI, and InChIKey inputs, are further queried through PubChem and converted to KEGG compound IDs when possible.
For organisms, matching is performed against the live KEGG organism table. Name queries are checked against both scientific names and common names extracted from the KEGG species field.
For KO terms, the current KEGG KO table is retrieved through the KEGG
REST API. Symbol queries may return multiple KO IDs combined with
"/".
A data.frame with the input values and matched KEGG
identifiers:
for KEGG_database = "compound": columns
Input, KEGG_ID;
for KEGG_database = "organism": columns
Input, Organism_Code;
for KEGG_database = "ko": columns
Input, KO_ID.
If no match is found, the corresponding identifier is NA.
Some inputs may return multiple rows when multiple matches are found.
## 1) Map compounds to KEGG compound IDs MPN_keggFinder( KEGG_database = "compound", searchBy = "name", query = c("tryptophan", "indole", "serotonin") ) ## 2) Map organisms to KEGG organism codes by name ## NA is returned for "dragon" because it is not a real organism in KEGG. MPN_keggFinder( KEGG_database = "organism", searchBy = "name", query = c("human", "horse", "dragon") ) ## 3) Map enzyme EC numbers to KEGG KO identifiers MPN_keggFinder( KEGG_database = "ko", searchBy = "ECnumber", query = c("4.1.99.1", "1.13.11.27") )## 1) Map compounds to KEGG compound IDs MPN_keggFinder( KEGG_database = "compound", searchBy = "name", query = c("tryptophan", "indole", "serotonin") ) ## 2) Map organisms to KEGG organism codes by name ## NA is returned for "dragon" because it is not a real organism in KEGG. MPN_keggFinder( KEGG_database = "organism", searchBy = "name", query = c("human", "horse", "dragon") ) ## 3) Map enzyme EC numbers to KEGG KO identifiers MPN_keggFinder( KEGG_database = "ko", searchBy = "ECnumber", query = c("4.1.99.1", "1.13.11.27") )
Constructs a directed network (3-column edge list) from user-specified KEGG metabolic and/or signaling pathways. KEGG KGML files are downloaded and parsed, networks are merged, organism-specific gene IDs in signaling pathways are converted to KEGG Orthology (KO) IDs, self-loops are removed, and interaction types are annotated.
MPN_keggNetwork(metabo_paths = NULL, signaling_paths = NULL)MPN_keggNetwork(metabo_paths = NULL, signaling_paths = NULL)
metabo_paths |
Character vector of KEGG pathway IDs for metabolic
pathways (e.g. |
signaling_paths |
Character vector of KEGG pathway IDs for signaling
pathways (e.g. |
All pathways supplied in metabo_paths and
signaling_paths must belong to the same organism
(same prefix, e.g. "hsa", "eco", "bsu").
If both metabolic and signaling pathways are provided, the output network is the union of both layers.
Invalid or unavailable pathway IDs are skipped with a message, and the network is built from valid pathways only.
A data.frame with 3 columns:
Source node (compound or KO/gene).
Target node (KO/gene or compound).
Interaction type (e.g. metabolic reaction, activation, inhibition, phosphorylation).
MPN_getPathIDs for pathway ID retrieval.
## Not run: ## Requires extensive KEGG API querying; runtime depends on server response ## Example 1 — Human tryptophan metabolism + immune signaling ## Metabolic pathway: Tryptophan metabolism (human) metabo_paths_hsa <- c("hsa00380") ## Selected immune / inflammatory signaling pathways (human) signaling_paths_hsa <- c( "hsa04060", # Cytokine–cytokine receptor interaction "hsa04630", # JAK–STAT signaling pathway "hsa04064", # NF-kappa B signaling pathway "hsa04660", # T cell receptor signaling pathway "hsa04659" # Th17 cell differentiation ) net_trp_hsa <- MPN_keggNetwork( metabo_paths = metabo_paths_hsa, signaling_paths = signaling_paths_hsa ) head(net_trp_hsa) ## Example 2 — E. coli tryptophan metabolism + biosynthesis metabo_paths_eco <- c( "eco00380", # Tryptophan metabolism (E. coli) "eco00400" # Phenylalanine, tyrosine and tryptophan biosynthesis (E. coli) ) net_trp_eco <- MPN_keggNetwork( metabo_paths = metabo_paths_eco, signaling_paths = NULL ) head(net_trp_eco) ## End(Not run)## Not run: ## Requires extensive KEGG API querying; runtime depends on server response ## Example 1 — Human tryptophan metabolism + immune signaling ## Metabolic pathway: Tryptophan metabolism (human) metabo_paths_hsa <- c("hsa00380") ## Selected immune / inflammatory signaling pathways (human) signaling_paths_hsa <- c( "hsa04060", # Cytokine–cytokine receptor interaction "hsa04630", # JAK–STAT signaling pathway "hsa04064", # NF-kappa B signaling pathway "hsa04660", # T cell receptor signaling pathway "hsa04659" # Th17 cell differentiation ) net_trp_hsa <- MPN_keggNetwork( metabo_paths = metabo_paths_hsa, signaling_paths = signaling_paths_hsa ) head(net_trp_hsa) ## Example 2 — E. coli tryptophan metabolism + biosynthesis metabo_paths_eco <- c( "eco00380", # Tryptophan metabolism (E. coli) "eco00400" # Phenylalanine, tyrosine and tryptophan biosynthesis (E. coli) ) net_trp_eco <- MPN_keggNetwork( metabo_paths = metabo_paths_eco, signaling_paths = NULL ) head(net_trp_eco) ## End(Not run)
MPN_mapReaction() converts reaction identifiers into the standard
MetaPathNet 3-column edge list format
(source, target, interaction_type).
MPN_mapReaction(reaction_ids, source = c("rhea", "metacyc", "kegg"))MPN_mapReaction(reaction_ids, source = c("rhea", "metacyc", "kegg"))
reaction_ids |
Character vector of reaction identifiers. |
source |
Character string indicating the origin of the reaction IDs. Supported values are:
|
The function supports direct KEGG reaction IDs, as well as external reaction identifiers from Rhea and MetaCyc. For external sources, it uses the MetaNetX SPARQL endpoint as a neutral layer to translate reaction IDs into KEGG reaction IDs where possible. KEGG-mapped reactions are then converted into MetaPathNet-style KO–compound edges. If no KEGG mapping is available, MetaNetX reaction equations are used to generate fallback compound-to-compound edges.
For source = "kegg", reaction IDs are converted directly using KEGG
reaction entries. Reaction equations are parsed to infer substrates,
products, and directionality. KEGG Orthology (KO) identifiers are retrieved
preferentially from the reaction ORTHOLOGY field, and if unavailable,
the function falls back to reaction-to-enzyme and enzyme-to-KO mapping.
For source = "rhea" and source = "metacyc", the function first
queries MetaNetX to identify corresponding MetaNetX reactions, then attempts
to recover KEGG reaction IDs. KEGG-mapped reactions follow the same semantics
as the metabolic layer of MetaPathNet: compounds are coded as
"cpd:Cxxxxx", KOs as "Kxxxxx", and directionality
(reversible vs irreversible) is derived from the KEGG
EQUATION field.
Reactions without KEGG mapping are represented as compound-to-compound
relations, using human-readable compound names as node IDs and
"external" as interaction type. This preserves reaction information
while clearly marking the non-KEGG origin of these edges.
A character matrix with three columns:
Source node ID (compound, KO, or compound name for non-KEGG reactions).
Target node ID.
For KEGG-mapped reactions, values such as
"k_compound:reversible" or
"k_compound:irreversible"; for reactions without KEGG
mapping, "external".
If no valid reactions can be converted, an empty 3-column matrix is returned and a warning is issued.
MPN_keggNetwork, MPN_crossSpeciesNetwork
## NOTE: The following examples require live access to KEGG REST and/or the ## MetaNetX SPARQL endpoint. ## 1) Map a MetaCyc reaction and inspect the returned MetaPathNet-style edges trp_metacyc_edges <- MPN_mapReaction( reaction_ids = "TRYPTOPHAN-RXN", source = "metacyc" ) ## 2) Map a Rhea reaction rhea16505_edges <- MPN_mapReaction( reaction_ids = "16505", source = "rhea" ) ## 3) Map KEGG reaction IDs directly tma_edges <- MPN_mapReaction( reaction_ids = c("R05623", "R10285"), source = "kegg" )## NOTE: The following examples require live access to KEGG REST and/or the ## MetaNetX SPARQL endpoint. ## 1) Map a MetaCyc reaction and inspect the returned MetaPathNet-style edges trp_metacyc_edges <- MPN_mapReaction( reaction_ids = "TRYPTOPHAN-RXN", source = "metacyc" ) ## 2) Map a Rhea reaction rhea16505_edges <- MPN_mapReaction( reaction_ids = "16505", source = "rhea" ) ## 3) Map KEGG reaction IDs directly tma_edges <- MPN_mapReaction( reaction_ids = c("R05623", "R10285"), source = "kegg" )
Merges two or more MetaPathNet-style edge lists into a single network.
All inputs must be 3-column matrices or data.frames corresponding to
source, target, and interaction_type.
MPN_mergeNetworks(...)MPN_mergeNetworks(...)
... |
Two or more MetaPathNet-style network tables. |
All inputs must be MetaPathNet-style edge lists with at least
3 columns corresponding to source, target, and
interaction_type.
Only the first 3 columns of each input are used.
Duplicated rows across input networks are removed after merging.
A 3-column matrix containing the merged MetaPathNet-style edge list with duplicated rows removed.
MPN_keggNetwork, MPN_crossSpeciesNetwork
## Example 1 — Merge two example network subsets ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Create two small example network subsets example_network_1 <- MetaPathNet_example_network[seq_len(20), , drop = FALSE] example_network_2 <- MetaPathNet_example_network[21:40, , drop = FALSE] ## Merge both subsets into one edge list merged_network <- MPN_mergeNetworks(example_network_1, example_network_2) head(merged_network)## Example 1 — Merge two example network subsets ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Create two small example network subsets example_network_1 <- MetaPathNet_example_network[seq_len(20), , drop = FALSE] example_network_2 <- MetaPathNet_example_network[21:40, , drop = FALSE] ## Merge both subsets into one edge list merged_network <- MPN_mergeNetworks(example_network_1, example_network_2) head(merged_network)
Computes pairwise Jaccard similarity between two or more KEGG-derived networks, either at the node level (unique node sets) or edge level (directed source–target pairs, optionally including interaction type).
MPN_netSimilarity(..., type = c("edge", "node"), match_interaction = FALSE)MPN_netSimilarity(..., type = c("edge", "node"), match_interaction = FALSE)
... |
Two or more network matrices, typically generated by
|
type |
Character, |
match_interaction |
Logical. When |
This function is particularly useful for comparing pathways across
organisms or conditions using networks built with MPN_keggNetwork().
A numeric similarity matrix with dimensions
length(list(...)) x length(list(...)). Row and column names are
derived from the argument names in .... Diagonal entries are 1;
off-diagonal entries are Jaccard indices,
where and are node sets (for type = "node") or
edge sets (for type = "edge"). If both sets are empty, the
similarity is NA_real_.
Fuxman Bass JI, Diallo A, Nelson J, Soto JM, Myers CL, Walhout AJ. Using networks to measure similarity between genes: association index selection. Nat Methods. 2013;10(12):1169–1176. doi:10.1038/nmeth.2728.
MPN_keggNetwork for network construction,
MPN_getPathIDs for pathway ID retrieval.
## 1) Prepare example network subsets data(MetaPathNet_example_network) net_example_1 <- MetaPathNet_example_network[seq_len(50), , drop = FALSE] net_example_2 <- MetaPathNet_example_network[51:100, , drop = FALSE] net_example_3 <- MetaPathNet_example_network[101:150, , drop = FALSE] net_example_4 <- MetaPathNet_example_network[151:200, , drop = FALSE] net_example_5 <- MetaPathNet_example_network[201:250, , drop = FALSE] ## 2) Edge-level similarity (Jaccard on directed edges, ignoring interaction type) ## This compares overlap in network structure (source-target pairs). sim_edge_example <- MPN_netSimilarity( net_example_1, net_example_2, net_example_3, net_example_4, net_example_5, type = "edge", match_interaction = FALSE ) ## 3) (Optional) Node-level similarity (Jaccard on unique node sets) ## This compares overlap in node composition, regardless of how nodes are connected. sim_node_example <- MPN_netSimilarity( net_example_1, net_example_2, net_example_3, net_example_4, net_example_5, type = "node", match_interaction = FALSE )## 1) Prepare example network subsets data(MetaPathNet_example_network) net_example_1 <- MetaPathNet_example_network[seq_len(50), , drop = FALSE] net_example_2 <- MetaPathNet_example_network[51:100, , drop = FALSE] net_example_3 <- MetaPathNet_example_network[101:150, , drop = FALSE] net_example_4 <- MetaPathNet_example_network[151:200, , drop = FALSE] net_example_5 <- MetaPathNet_example_network[201:250, , drop = FALSE] ## 2) Edge-level similarity (Jaccard on directed edges, ignoring interaction type) ## This compares overlap in network structure (source-target pairs). sim_edge_example <- MPN_netSimilarity( net_example_1, net_example_2, net_example_3, net_example_4, net_example_5, type = "edge", match_interaction = FALSE ) ## 3) (Optional) Node-level similarity (Jaccard on unique node sets) ## This compares overlap in node composition, regardless of how nodes are connected. sim_node_example <- MPN_netSimilarity( net_example_1, net_example_2, net_example_3, net_example_4, net_example_5, type = "node", match_interaction = FALSE )
Performs a permutation-based test on the mean shortest-path length between a set of source nodes and target nodes within a KEGG-derived network. The observed mean shortest-path distance is compared to a null distribution obtained by repeatedly sampling random source and target sets of the same size and node-type composition from the same network.
MPN_permutePaths( network_table, source_nodes, target_nodes, n_perm = 10000, mode = c("out", "in", "all"), plot = FALSE, return_perm = FALSE )MPN_permutePaths( network_table, source_nodes, target_nodes, n_perm = 10000, mode = c("out", "in", "all"), plot = FALSE, return_perm = FALSE )
network_table |
A 3-column matrix or data.frame representing
directed network edges. Columns must correspond to
|
source_nodes |
Character vector of KEGG node IDs used as sources in the permutation test. |
target_nodes |
Character vector of KEGG node IDs used as targets in the permutation test. |
n_perm |
Integer. Number of permutations used to build the null
distribution of mean shortest-path lengths (default: |
mode |
Character. Direction parameter passed to
|
plot |
Logical (default: |
return_perm |
Logical (default: |
Internally, the function:
identifies supported node types in network_table,
currently KEGG Orthology nodes ("K" prefix) and
KEGG compound nodes ("cpd:" prefix);
maps the user-supplied source and target nodes onto the network;
removes unreachable pairs (distance = Inf) when calculating
observed and permuted mean distances;
derives an empirical one-sided p-value from the proportion of permuted means that are smaller than the observed mean.
Source and target node sets are user-defined and may contain supported KEGG
node types according to the biological question being addressed. A smaller
mean shortest-path length indicates tighter connectivity. Therefore, the
reported p-value tests whether random source-target sets tend to be
more tightly connected than the observed set
().
If return_perm = FALSE, a data.frame with one row:
Observed mean shortest-path length (finite distances only; unreachable pairs are excluded).
Mean of permuted mean shortest-path lengths under the null (finite values only).
Empirical one-sided p-value
.
Number of permutations used.
If return_perm = TRUE, a list with:
The summary data.frame described above.
Numeric vector of permuted mean shortest-path lengths (finite values only).
If plot = TRUE, a ggplot2-based histogram + density overlay
of the permutation distribution is printed. For custom visualisation,
set return_perm = TRUE and use the random_sp vector
together with stats in your own plotting code.
MPN_distances for shortest-path distance matrices,
MPN_shortestPaths for explicit shortest paths,
MPN_keggNetwork, MPN_crossSpeciesNetwork for
KEGG-based network construction.
## 1) Prepare a mixed human–E. coli network focused on tryptophan-related pathways ## Human: tryptophan metabolism + selected signaling pathways ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Combine host and microbe networks into one edge list net_trp_mixed <- MetaPathNet_example_network ## 2) Define source and target node sets for the Trp/kynurenine/serotonin context source_nodes <- c( "K00486", # kynurenine 3-monooxygenase "K00453", # tryptophan 2,3-dioxygenase "K00463", # indoleamine 2,3-dioxygenase "K01667", # kynureninase "K01696", # tryptophan synthase beta chain "K01695" # tryptophan synthase alpha chain ) target_nodes <- c( "cpd:C00078", # L-tryptophan "cpd:C00328", # L-kynurenine "cpd:C00780", # serotonin "cpd:C00463", # indole "cpd:C00108" # anthranilate ) ## 3) Permutation test on mean shortest-path length between the two node sets perm_trp <- MPN_permutePaths( network_table = net_trp_mixed, # mixed hsa/eco Trp + immune-related network source_nodes = source_nodes, target_nodes = target_nodes, n_perm = 100, # increase (e.g. 10000) for more stable inference mode = "out", plot = FALSE, # show permutation distribution return_perm = TRUE # keep individual permuted means ) ## 4) View summary statistics perm_trp$stats## 1) Prepare a mixed human–E. coli network focused on tryptophan-related pathways ## Human: tryptophan metabolism + selected signaling pathways ## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Combine host and microbe networks into one edge list net_trp_mixed <- MetaPathNet_example_network ## 2) Define source and target node sets for the Trp/kynurenine/serotonin context source_nodes <- c( "K00486", # kynurenine 3-monooxygenase "K00453", # tryptophan 2,3-dioxygenase "K00463", # indoleamine 2,3-dioxygenase "K01667", # kynureninase "K01696", # tryptophan synthase beta chain "K01695" # tryptophan synthase alpha chain ) target_nodes <- c( "cpd:C00078", # L-tryptophan "cpd:C00328", # L-kynurenine "cpd:C00780", # serotonin "cpd:C00463", # indole "cpd:C00108" # anthranilate ) ## 3) Permutation test on mean shortest-path length between the two node sets perm_trp <- MPN_permutePaths( network_table = net_trp_mixed, # mixed hsa/eco Trp + immune-related network source_nodes = source_nodes, target_nodes = target_nodes, n_perm = 100, # increase (e.g. 10000) for more stable inference mode = "out", plot = FALSE, # show permutation distribution return_perm = TRUE # keep individual permuted means ) ## 4) View summary statistics perm_trp$stats
Removes all edges from a network where either endpoint is annotated as a
KEGG drug (prefix "dr:").
MPN_removeDrugs(network_table)MPN_removeDrugs(network_table)
network_table |
A two- or three-column matrix representing the network
(edge list), typically as returned by |
The function scans the first two columns (source and target) for node IDs
containing the "dr:" prefix. All rows involving such nodes are
removed. If no drug nodes are found, the original matrix is returned and
a message is printed.
A matrix of the same format as the input, with all drug nodes
(prefix "dr:") and their incident edges removed.
## 1) Prepare an example network containing KEGG drug nodes data(MetaPathNet_example_network) net_hsa <- rbind( MetaPathNet_example_network, c("dr:D00001", "K00463", "drug_example"), c("K00463", "dr:D00002", "drug_example") ) ## 2) Remove all KEGG drug nodes (dr:...) from the network net_hsa_nodrug <- MPN_removeDrugs(net_hsa) ## 3) Compare dimensions before and after drug removal dim(net_hsa) # Original network dimensions dim(net_hsa_nodrug) # Network dimensions after drug removal nrow(net_hsa) - nrow(net_hsa_nodrug) # Number of drug-related edges removed## 1) Prepare an example network containing KEGG drug nodes data(MetaPathNet_example_network) net_hsa <- rbind( MetaPathNet_example_network, c("dr:D00001", "K00463", "drug_example"), c("K00463", "dr:D00002", "drug_example") ) ## 2) Remove all KEGG drug nodes (dr:...) from the network net_hsa_nodrug <- MPN_removeDrugs(net_hsa) ## 3) Compare dimensions before and after drug removal dim(net_hsa) # Original network dimensions dim(net_hsa_nodrug) # Network dimensions after drug removal nrow(net_hsa) - nrow(net_hsa_nodrug) # Number of drug-related edges removed
Removes one or more nodes (compounds, KOs, reactions, etc.) from a network edge list. All edges involving any of the specified nodes are removed.
MPN_removeNode(nodes_to_remove, network_table)MPN_removeNode(nodes_to_remove, network_table)
nodes_to_remove |
Character vector of node IDs to remove from the network
(e.g. KEGG compound IDs, KO IDs). For compounds, both |
network_table |
A matrix (typically 2 or 3 columns) representing the
network edge list, as generated by |
All occurrences of the supplied node IDs are set to NA, and all
rows containing NA are then removed. This is useful to prune
unwanted nodes before downstream analyses such as distance or shortest-path
calculations.
A matrix of the same format as network_table, with all edges
involving the specified nodes removed and duplicate edges dropped.
## Example — Remove a selected node from a human integrated network ## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_hsa <- MetaPathNet_example_network ## 2) Define node to remove nodes_to_remove <- "cpd:C01213" # (R)-Methylmalonyl-CoA ## 3) Remove all edges involving the selected node net_hsa_filtered <- MPN_removeNode( nodes_to_remove = nodes_to_remove, network_table = net_hsa ) ## 4) Check that the node is no longer present MPN_findMappedNodes( nodes = nodes_to_remove, network_table = net_hsa_filtered )$mapped_nodes ## 5) Compare network size before and after node removal dim(net_hsa) # Original network dimensions dim(net_hsa_filtered) # Network dimensions after node removal nrow(net_hsa) - nrow(net_hsa_filtered) # Number of removed edges## Example — Remove a selected node from a human integrated network ## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_hsa <- MetaPathNet_example_network ## 2) Define node to remove nodes_to_remove <- "cpd:C01213" # (R)-Methylmalonyl-CoA ## 3) Remove all edges involving the selected node net_hsa_filtered <- MPN_removeNode( nodes_to_remove = nodes_to_remove, network_table = net_hsa ) ## 4) Check that the node is no longer present MPN_findMappedNodes( nodes = nodes_to_remove, network_table = net_hsa_filtered )$mapped_nodes ## 5) Compare network size before and after node removal dim(net_hsa) # Original network dimensions dim(net_hsa_filtered) # Network dimensions after node removal nrow(net_hsa) - nrow(net_hsa_filtered) # Number of removed edges
Replace one or more node IDs in a network matrix by a single new ID. This is typically used to cluster equivalent metabolites (e.g. isomers) under a common identifier before downstream analysis.
MPN_replaceNode(nodes_to_replace, replacement_node, network_table)MPN_replaceNode(nodes_to_replace, replacement_node, network_table)
nodes_to_replace |
Character vector of node IDs to be replaced. Compound IDs can
be given as |
replacement_node |
Character string giving the new node ID to use as replacement
(same flexibility as |
network_table |
A 2- or 3-column matrix representing the network
(e.g. as returned by |
All matches are performed on KEGG-style node labels. For KEGG compounds,
the function internally normalises "Cxxxxx" and "cpd:Cxxxxx"
to a consistent "cpd:Cxxxxx" form before replacement.
A network matrix of the same structure as network_table, with all
occurrences of nodes_to_replace replaced by replacement_node. Duplicate edges
created by the replacement are removed.
## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_hsa <- MetaPathNet_example_network ## 2) (R)- and (S)-methylmalonyl-CoA are stereoisomers and can be merged ## into a single node nodes_to_merge <- c("cpd:C01213", "cpd:C00683") replacement_node <- "cpd:C00683" ## 3) Replace the selected nodes with one common identifier net_hsa_clustered <- MPN_replaceNode( nodes_to_replace = nodes_to_merge, replacement_node = replacement_node, network_table = net_hsa ) ## 4) Check that the replacement was applied in the updated network MPN_findMappedNodes( nodes = c("cpd:C01213", "cpd:C00683"), network_table = net_hsa_clustered )## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_hsa <- MetaPathNet_example_network ## 2) (R)- and (S)-methylmalonyl-CoA are stereoisomers and can be merged ## into a single node nodes_to_merge <- c("cpd:C01213", "cpd:C00683") replacement_node <- "cpd:C00683" ## 3) Replace the selected nodes with one common identifier net_hsa_clustered <- MPN_replaceNode( nodes_to_replace = nodes_to_merge, replacement_node = replacement_node, network_table = net_hsa ) ## 4) Check that the replacement was applied in the updated network MPN_findMappedNodes( nodes = c("cpd:C01213", "cpd:C00683"), network_table = net_hsa_clustered )
Computes shortest paths between specified source and target node sets in a KEGG-based network. Source nodes are often KEGG KOs/genes (upstream biological functions) and target nodes are often KEGG compounds (downstream metabolites), but this is a recommended usage pattern rather than a strict requirement.
MPN_shortestPaths( network_table, source_nodes, target_nodes, mode = c("out", "in", "all"), output = c("path_list", "network_matrix"), name = FALSE, distance_threshold = Inf, betweenness = FALSE, reactant_filter = FALSE )MPN_shortestPaths( network_table, source_nodes, target_nodes, mode = c("out", "in", "all"), output = c("path_list", "network_matrix"), name = FALSE, distance_threshold = Inf, betweenness = FALSE, reactant_filter = FALSE )
network_table |
A 3-column matrix or data.frame of edges with columns
|
source_nodes |
Character vector of KEGG node IDs to use as path sources. |
target_nodes |
Character vector of KEGG node IDs to use as path targets. |
mode |
Character; direction mode passed to
|
output |
Character; output format:
|
name |
Logical; if |
distance_threshold |
Numeric; only source-target pairs with
shortest-path distance |
betweenness |
Logical (default |
reactant_filter |
Logical (default |
Valid source-target pairs are first filtered by graph distance, and paths can be returned either as path lists or as a condensed edge list.
The function:
Accepts matrix or data.frame input and internally
standardizes it to a character edge table.
Builds a directed igraph graph from network_table and
computes pairwise shortest-path distances (breadth-first search on
this unweighted graph).
Stops if any node is present in both source_nodes and
target_nodes, because the distance from a node to itself is 0
and is not allowed in this workflow.
Keeps only mapped source-target pairs with finite distance within
distance_threshold; unreachable pairs (Inf) and pairs
longer than the threshold are filtered out and not processed further.
If mode = "all", shortest-path search ignores edge direction.
However, for output = "network_matrix", the returned
interaction_type values are still recovered from the original
directed edge annotation in network_table, including reverse
matching when needed.
If reactant_filter = TRUE, candidate shortest paths are
further filtered by checking whether consecutive compound-compound
transitions are supported by KEGG reaction data.
Depending on output:
"path_list" - named list; each element is one or more shortest
paths (character vectors of node IDs or names).
"network_matrix" - 3-column matrix of unique edges traversed
by the identified shortest paths. Edges are returned in path order,
and interaction_type is assigned from the original network
edge annotation.
Name/symbol conversion relies on the KEGG REST API and can be slow for large
node sets. The internal 6-step cutoff is empirical and intended to prevent
excessive enumeration of very long shortest paths. When betweenness = TRUE,
enumerating all shortest paths for tie-breaking may increase runtime and memory use.
## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Use the precomputed object as the example network_table net_trp_mixed <- MetaPathNet_example_network ## 2) Define source and target nodes of interest in this network ## Source/target can be any KEGG node types, but they must be mapped in the network ## and should not overlap (same node cannot be both source and target). source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01610", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108", "cpd:C00458", "cpd:C00336") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) ## 3) Optional: inspect shortest-path distances between mapped node sets ## (useful for checking connectivity before extracting shortest paths) dist_trp <- MPN_distances( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, name = FALSE ) ## 4) Extract shortest paths as annotated path list ## Pairs that are unreachable (Inf distance) or above the distance threshold ## are filtered internally. paths_trp_mixed_list <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "path_list", name = FALSE, distance_threshold = 6 ) ## 5) Extract a subnetwork containing all edges used in the selected shortest paths paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE )## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Use the precomputed object as the example network_table net_trp_mixed <- MetaPathNet_example_network ## 2) Define source and target nodes of interest in this network ## Source/target can be any KEGG node types, but they must be mapped in the network ## and should not overlap (same node cannot be both source and target). source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01610", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108", "cpd:C00458", "cpd:C00336") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) ## 3) Optional: inspect shortest-path distances between mapped node sets ## (useful for checking connectivity before extracting shortest paths) dist_trp <- MPN_distances( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, name = FALSE ) ## 4) Extract shortest paths as annotated path list ## Pairs that are unreachable (Inf distance) or above the distance threshold ## are filtered internally. paths_trp_mixed_list <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "path_list", name = FALSE, distance_threshold = 6 ) ## 5) Extract a subnetwork containing all edges used in the selected shortest paths paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE )
Suggest candidate organisms from KEGG KO IDs or candidate KEGG Orthology (KO) annotations from KEGG compound IDs.
MPN_suggestEntities(query, entity = c("ko", "compound"))MPN_suggestEntities(query, entity = c("ko", "compound"))
query |
Character vector of KEGG identifiers. For
|
entity |
Character string specifying the input type:
|
This function supports semi-automated candidate selection during network construction.
For entity = "ko", each KO is queried with
KEGGREST::keggLink() to retrieve genes carrying that
orthology assignment. Organism codes are extracted from the linked
KEGG gene IDs, matched to the live KEGG organism table, filtered to
prokaryotes and Homo sapiens (hsa), and ranked by the
number of query KOs found in each organism.
For entity = "compound", each compound is queried with
KEGGREST::keggGet(), linked KEGG reaction IDs are extracted,
and each reaction is searched for KO annotations through its
$ORTHOLOGY field.
Input IDs are validated before querying KEGG. If none of the input IDs have a valid format, the function stops with an error. Invalid IDs are otherwise removed with a message. KEGG retrieval failures, missing reaction links, and missing orthology annotations are handled internally and reported without interrupting execution.
A data.frame whose structure depends on the entity type:
entity = "ko":Columns organism_name,
organism_code, overlap_count, and
overlap_hits. Rows are ranked by decreasing
overlap_count.
entity = "compound":Columns
compound_id, compound_name, KO_ID, and
KO_name. Rows are deduplicated.
An empty data frame with the appropriate columns is returned when no candidates are found.
MPN_keggFinder for converting metabolite names,
organism names, or enzyme EC numbers to KEGG identifiers.
## 1) Compound to KO: retrieve candidate KOs from mapped compounds cpd_ids <- MPN_keggFinder( KEGG_database = "compound", searchBy = "name", query = c("tryptophan", "indole", "serotonin") ) ko_results <- MPN_suggestEntities( query = cpd_ids$KEGG_ID, entity = "compound" ) ## 2) KO to organism: retrieve candidate prokaryotic organisms org_results <- MPN_suggestEntities( query = ko_results$KO_ID, entity = "ko" ) head(org_results)## 1) Compound to KO: retrieve candidate KOs from mapped compounds cpd_ids <- MPN_keggFinder( KEGG_database = "compound", searchBy = "name", query = c("tryptophan", "indole", "serotonin") ) ko_results <- MPN_suggestEntities( query = cpd_ids$KEGG_ID, entity = "compound" ) ## 2) KO to organism: retrieve candidate prokaryotic organisms org_results <- MPN_suggestEntities( query = ko_results$KO_ID, entity = "ko" ) head(org_results)
Sends a cluster-annotated MetaPathNet network (typically the output of
MPN_clusterNetwork()) to Cytoscape for interactive exploration.
Nodes are coloured by community (cluster), optionally shaped by category
(compound / KO / contextual), and can be labelled with KEGG-derived names.
MPN_viewClusterCy( cluster_matrix, label = c("none", "all", "non_background"), category = TRUE, network_title = "", collection_title = "" )MPN_viewClusterCy( cluster_matrix, label = c("none", "all", "non_background"), category = TRUE, network_title = "", collection_title = "" )
cluster_matrix |
A matrix or data.frame with at least five columns:
|
label |
Character; controls KEGG-based node labelling. One of:
|
category |
Logical. If |
network_title |
Character. Cytoscape network title. If empty or
|
collection_title |
Character. Cytoscape collection title. If empty or
|
Cytoscape (version >= 3.9.0) must be running and reachable via RCy3 before calling this function.
The function reconstructs node-level cluster membership from the
source_cluster and target_cluster columns, identifies the
largest community as a background cluster (for label = "non_background"),
optionally converts KEGG IDs to names via KEGGREST, and then creates a
Cytoscape network via RCy3 with:
colour mapping by cluster,
shape mapping by node type (if category = TRUE),
node labels from the chosen label mode.
KEGG name conversion can be slow on large networks, especially with
label = "all". For big MetaPathNet networks, label = "non_background"
is often a good compromise.
Invisibly returns NULL. The function acts via side effects in
Cytoscape, creating and styling a new network.
MPN_clusterNetwork for community detection, and
MPN_viewNetworkCy for non-clustered KEGG network visualisation.
## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp <- MetaPathNet_example_network ## 2) Detect communities on the full network graph net_trp_clusters <- MPN_clusterNetwork( network_table = net_trp, method = "leiden", resolution = 0.01 ) ## Not run: ## Requires a running Cytoscape session for network layout and rendering ## 3) Recommended: full cluster-aware visualisation in Cytoscape MPN_viewClusterCy( cluster_matrix = net_trp_clusters, label = "all", # convert KEGG IDs to biological names and label all nodes category = TRUE, # shape by node type (Compound / KO / Contextual) network_title = "Example network clusters", collection_title = "MetaPathNet_Examples" ) ## 4) Faster option for larger networks: label only non-background clusters MPN_viewClusterCy( cluster_matrix = net_trp_clusters, label = "non_background", category = TRUE, network_title = "Example network clusters (foreground labels)", collection_title = "MetaPathNet_Examples" ) ## End(Not run)## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp <- MetaPathNet_example_network ## 2) Detect communities on the full network graph net_trp_clusters <- MPN_clusterNetwork( network_table = net_trp, method = "leiden", resolution = 0.01 ) ## Not run: ## Requires a running Cytoscape session for network layout and rendering ## 3) Recommended: full cluster-aware visualisation in Cytoscape MPN_viewClusterCy( cluster_matrix = net_trp_clusters, label = "all", # convert KEGG IDs to biological names and label all nodes category = TRUE, # shape by node type (Compound / KO / Contextual) network_title = "Example network clusters", collection_title = "MetaPathNet_Examples" ) ## 4) Faster option for larger networks: label only non-background clusters MPN_viewClusterCy( cluster_matrix = net_trp_clusters, label = "non_background", category = TRUE, network_title = "Example network clusters (foreground labels)", collection_title = "MetaPathNet_Examples" ) ## End(Not run)
Imports a MetaPathNet-style network table (typically from MPN_keggNetwork()
or MPN_shortestPaths()) into Cytoscape and applies basic visual styling.
Nodes can be coloured by type (compound / KO / other). Node labels can be kept
as KEGG IDs (default) or converted to KEGG-derived names.
MPN_viewNetworkCy( network_table, name = FALSE, category = TRUE, style_interaction = FALSE, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "", collection_title = "" )MPN_viewNetworkCy( network_table, name = FALSE, category = TRUE, style_interaction = FALSE, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "", collection_title = "" )
network_table |
A 3-column matrix or data.frame representing the network
(columns: |
name |
Logical (default |
category |
Logical. If |
style_interaction |
Logical (default |
node_compound |
Colour for compound nodes (default |
node_gene |
Colour for KO/gene nodes (default |
network_title |
Character. Title of the network in Cytoscape. |
collection_title |
Character. Cytoscape collection name. |
Cytoscape (v3.9.0) must be running and reachable via RCy3
before calling this function.
Reverse duplicated edges are collapsed for Cytoscape display when they share the same metabolic interaction type
When name = TRUE, KEGG IDs are resolved once per node. This can be slow
for large networks and depends on KEGG API response time.
Invisibly returns NULL. The function acts by side-effect in Cytoscape,
creating a styled network ready for manual or scripted exploration.
MPN_keggNetwork, MPN_viewNetworkR,
MPN_shortestPaths
## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp_mixed <- MetaPathNet_example_network ## 2) Extract a shortest-path subnetwork (paths_trp_mixed) source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01610", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108", "cpd:C00458", "cpd:C00336") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## Not run: ## Requires a running Cytoscape session for network layout and rendering ## Example 1 — Shortest-path subnetwork with KEGG name conversion + interaction styling ## (k_compound:reversible shown as parallel lines; k_compound:irreversible with arrows) MPN_viewNetworkCy( network_table = paths_trp_mixed, name = TRUE, category = TRUE, style_interaction = TRUE, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "Trp-immune shortest paths", collection_title = "MetaPathNet_Examples" ) ## Example 2 — Full Trp network without name conversion (faster) MPN_viewNetworkCy( network_table = net_trp_mixed, name = FALSE, category = TRUE, style_interaction = FALSE, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "Trp-immune network", collection_title = "MetaPathNet_Examples" ) ## End(Not run)## 1) Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) net_trp_mixed <- MetaPathNet_example_network ## 2) Extract a shortest-path subnetwork (paths_trp_mixed) source_nodes <- c("K00486", "K00453", "K00463", "K01667", "K01696", "K01610", "K01695") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C00780", "cpd:C00463", "cpd:C00108", "cpd:C00458", "cpd:C00336") map_src <- MPN_findMappedNodes(source_nodes, net_trp_mixed) map_tgt <- MPN_findMappedNodes(target_nodes, net_trp_mixed) paths_trp_mixed <- MPN_shortestPaths( network_table = net_trp_mixed, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## Not run: ## Requires a running Cytoscape session for network layout and rendering ## Example 1 — Shortest-path subnetwork with KEGG name conversion + interaction styling ## (k_compound:reversible shown as parallel lines; k_compound:irreversible with arrows) MPN_viewNetworkCy( network_table = paths_trp_mixed, name = TRUE, category = TRUE, style_interaction = TRUE, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "Trp-immune shortest paths", collection_title = "MetaPathNet_Examples" ) ## Example 2 — Full Trp network without name conversion (faster) MPN_viewNetworkCy( network_table = net_trp_mixed, name = FALSE, category = TRUE, style_interaction = FALSE, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "Trp-immune network", collection_title = "MetaPathNet_Examples" ) ## End(Not run)
Plots a KEGG-derived network matrix (e.g. from MPN_keggNetwork() or
MPN_shortestPaths()) directly in R using ggraph. Nodes can be
coloured by type (compound, KO, contextual) and labelled with KEGG IDs or
KEGG-derived names.
MPN_viewNetworkR( network_table, category = TRUE, name = FALSE, layout = "randomly", node_size = 2, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "MetaPathNet Network" )MPN_viewNetworkR( network_table, category = TRUE, name = FALSE, layout = "randomly", node_size = 2, node_compound = "#9DC7DD", node_gene = "#9ED17B", network_title = "MetaPathNet Network" )
network_table |
A network matrix with at least three columns: source, target,
interaction type (e.g. output of |
category |
Logical. If |
name |
Logical (default |
layout |
Character. Layout algorithm for ggraph
(e.g. |
node_size |
Numeric. Base size for nodes (and label text) in the plot. |
node_compound |
Colour for compound nodes (default |
node_gene |
Colour for KO nodes (default |
network_title |
Character. Optional plot title. |
For large networks (> 2000 edges), only the largest connected
component is displayed. If more than ~300 nodes are present, a message
suggests using MPN_viewNetworkCy() for Cytoscape-based visualisation.
When name = TRUE, KEGG REST queries are issued for each node, which
can be slow for large graphs.
A ggplot object.
MPN_viewNetworkCy, MPN_crossSpeciesNetwork,
MPN_keggNetwork, MPN_shortestPaths
## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Define source and target node sets, then keep only nodes mapped in the network source_nodes <- c("K00453", "K00463", "K01667") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C02700") map_src <- MPN_findMappedNodes(source_nodes, MetaPathNet_example_network) map_tgt <- MPN_findMappedNodes(target_nodes, MetaPathNet_example_network) ## Extract a shortest-path subnetwork for visualisation paths_trp <- MPN_shortestPaths( network_table = MetaPathNet_example_network, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## Visualise the shortest-path subnetwork in R p_trp <- MPN_viewNetworkR( network_table = paths_trp, category = TRUE, name = FALSE, layout = "fr", node_size = 5, network_title = "Tryptophan shortest-path subnetwork" ) print(p_trp)## Load the precomputed example network; see MPN_keggNetwork() for its construction data(MetaPathNet_example_network) ## Define source and target node sets, then keep only nodes mapped in the network source_nodes <- c("K00453", "K00463", "K01667") target_nodes <- c("cpd:C00078", "cpd:C00328", "cpd:C02700") map_src <- MPN_findMappedNodes(source_nodes, MetaPathNet_example_network) map_tgt <- MPN_findMappedNodes(target_nodes, MetaPathNet_example_network) ## Extract a shortest-path subnetwork for visualisation paths_trp <- MPN_shortestPaths( network_table = MetaPathNet_example_network, source_nodes = map_src$mapped_nodes, target_nodes = map_tgt$mapped_nodes, mode = "out", output = "network_matrix", name = FALSE, distance_threshold = 6 ) ## Visualise the shortest-path subnetwork in R p_trp <- MPN_viewNetworkR( network_table = paths_trp, category = TRUE, name = FALSE, layout = "fr", node_size = 5, network_title = "Tryptophan shortest-path subnetwork" ) print(p_trp)