# R/graph-plots.R In robertness/pathflow: Converts biochemical reaction networks to pathway maps.

#### Documented in drawGraphWithInvariants

```#' A graphing function for invariants.
drawGraphWithInvariants <- function(graph, g.layout){
#Did this as a function so I could apply to multiple graphs
#Takes in a graph as described above, with a type attribute labeled "place" or "transition"
places <- V(graph)[V(graph)\$type == "place"]\$name
transitions <- V(graph)[V(graph)\$type == "transition"]\$name
## Incidence matrix is derived by taking reactant - reaction relationship matrix
## and product - reaction relation matrix and subtracting former from latter.
S <- post - pre
# Invariant calculation matrix
pInvariants <- getMinimalInvariants(S)
tInvariants <- getMinimalInvariants(t(S))
# Name them
names(pInvariants) <- unlist(lapply(pInvariants, function(p) paste(p, collapse = "--")))
names(tInvariants) <- unlist(lapply(tInvariants, function(t) paste(t, collapse = "--")))
# Label nodes in the graph
require(reshape, quietly=TRUE)
invariantMap <- rbind(melt(pInvariants), melt(tInvariants))
names(invariantMap) <- c("name", "invariant")
rownames(invariantMap) <- as.character(invariantMap\$name)
V(graph)\$invariant <- invariantMap[V(graph)\$name, "invariant"]
invariantVertex <- lapply(c(pInvariants, tInvariants), function(inv){
V(graph)[V(graph)\$name %in% inv]
})
V(graph)\$color <- "lightblue"
V(graph)[is.na(V(graph)\$invariant)]\$color <- "pink"
V(graph)[V(graph)\$name == "E1"]\$color <- "blue"
V(graph)[V(graph)\$name == "PP_K"]\$color <- "red"
plot.igraph(graph, layout = g.layout, vertex.size =3, vertex.label.dist=-.37,
edge.arrow.size=.4, mark.groups=invariantVertex)
}
```
robertness/pathflow documentation built on May 25, 2017, 5:22 a.m.