1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
# Export a state table in <stateGraph> to a Pajek graph
toPajek <- function (stateGraph, file="boolean.net", includeLabels=FALSE, ...)
{
args <- list(...)
if (!is.null(args$attractorInfo))
{
warning("The parameter \"attractorInfo\" is deprecated. Use \"stateGraph\" instead!")
stateGraph <- args$attractorInfo
}
if (!inherits(stateGraph,"TransitionTable"))
stateGraph <- getTransitionTable(stateGraph)
geneCols <- setdiff(colnames(stateGraph),c("attractorAssignment","transitionsToAttractor"))
numGenes <- (length(geneCols)) / 2
from <- apply(stateGraph[,1:numGenes,drop=FALSE],1,paste,collapse="")
to <- apply(stateGraph[,((numGenes+1):(2*numGenes)),drop=FALSE],1,paste,collapse="")
vertices <- unique(c(from,to))
vertexIndices <- seq_along(vertices)
names(vertexIndices) <- vertices
from <- vertexIndices[from]
to <- vertexIndices[to]
sink(file)
cat("*Vertices ", length(vertices), "\r\n", sep = "")
if (includeLabels)
{
for (i in seq_along(vertices))
cat(i," \"",vertices[i],"\"\r\n",sep="")
}
cat("*Arcs\r\n")
for (i in seq_along(from))
cat(from[i]," ",to[i]," 1\r\n",sep="")
sink()
}
|