View source: R/map_information_on_reaction_network.R
| add_edge_attributes | R Documentation |
igraph objectThe function adds edge weights to a igraph object g. The
weights are stored in the attributes object. The function will return
a igraph object with updated edge weights.
The attributes object can be either a matrix or a
data.frame.
The matrix is an adjacency matrix containing as
entries the weights. The weights will be stored in the E(g)$value
slot of the returned igraph object.
The data.frame contains the columns vertex, a
character vector of length 2, specifying the out- and ingoing
vertices for the edge and the edge weights in the remaining columns. The
weights will be stored in the respective slots with same names as the
colnames of attributes of the returned igraph object.
add_edge_attributes(g, attributes, cols_vertex = colnames(attributes)[1:2])
g |
|
attributes |
|
cols_vertex |
|
cols_vertex has to be adjusted only when attributes is a
data.frame. The character of length 2 will specify the columns
containing the out- and ingoing vertices of the graph.
In case of attributes is a matrix, the matrix entries will be
stored in E(g)$value
igraph object
Thomas Naake, thomasnaake@googlemail.com
FA <- c("FA 12:0", "FA 14:0", "FA 16:0")
## create data.frame with reactions and reaction order
reactions <- rbind(
c(1, "RHEA:15421", "M_ATP + M_CoA + M_FA = M_PPi + M_AMP + M_AcylCoA", FALSE),
c(2, "RHEA:15325", "M_Glycerol-3-P + M_AcylCoA = M_CoA + M_LPA", FALSE),
c(3, "RHEA:19709", "M_AcylCoA + M_LPA = M_CoA + M_PA", FALSE),
c(4, "RHEA:27429", "M_H2O + M_PA = M_Pi + M_1,2-DG", FALSE)
)
reactions <- data.frame(order = reactions[, 1], reaction_RHEA = reactions[, 2],
reaction_formula = reactions[, 3], directed = reactions[, 4])
reactions$order <- as.numeric(reactions$order)
reactions$directed <- as.logical(reactions$directed)
## create the list with reactions
reaction_l <- create_reactions(substrates = list(FA = FA), reactions = reactions)
## create the adjacency matrix
reaction_adj <- create_reaction_adjacency_matrix(reaction_l)
## create graph
g <- igraph::graph_from_adjacency_matrix(reaction_adj, mode = "directed", weighted = TRUE)
## attributes: data.frame
attributes <- data.frame(
rbind(
c("CoA 12:0", "PA 12:0/0:0", 0.5),
c("CoA 12:0", "PA 14:0/12:0", 0.8)
))
names(attributes) <- c("from", "to", "weight")
attributes$weight <- as.numeric(attributes$weight)
## apply the function
add_edge_attributes(g, attributes, cols_vertex = c("from", "to"))
## attributes: matrix
attributes <- matrix(c(0, 0.5, 0.8, 0, 0, 0, 0, 0, 0), ncol = 3, byrow = TRUE,
dimnames = list(
c("CoA 12:0", "PA 12:0/0:0", "PA 14:0/12:0"),
c("CoA 12:0", "PA 12:0/0:0", "PA 14:0/12:0")))
## apply the function
add_edge_attributes(g, attributes)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.