File: toPajek.R

package info (click to toggle)
r-cran-boolnet 2.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: ansic: 12,452; sh: 16; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download | duplicates (6)
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()
}