% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/network_utils.R
\name{replaceNode}
\alias{replaceNode}
\title{Replace Nodes in a Network Table}
\usage{
replaceNode(nodes_to_replace, replacement_node, network_table)
}
\arguments{
\item{nodes_to_replace}{Character vector of node IDs to be replaced. Compound IDs can
be given as \code{"Cxxxxx"} or \code{"cpd:Cxxxxx"}; both are accepted.}

\item{replacement_node}{Character string giving the new node ID to use as replacement
(same flexibility as \code{nodes_to_replace} for compound IDs).}

\item{network_table}{A 2- or 3-column matrix representing the network
(e.g. as returned by \code{buildKeggNetwork()}).}
}
\value{
A network matrix of the same structure as \code{network_table}, with all
occurrences of \code{nodes_to_replace} replaced by \code{replacement_node}. Duplicate edges
created by the replacement are removed.
}
\description{
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.
}
\details{
All matches are performed on KEGG-style node labels. For KEGG compounds,
the function internally normalises \code{"Cxxxxx"} and \code{"cpd:Cxxxxx"}
to a consistent \code{"cpd:Cxxxxx"} form before replacement.
}
\examples{
## 1) Load the precomputed example network; see buildKeggNetwork() 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 <- 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
findMappedNodes(
  nodes         = c("cpd:C01213", "cpd:C00683"),
  network_table = net_hsa_clustered
)

}
\seealso{
\code{\link{findMappedNodes}}
}
