File: plotNetworkWiring.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 (91 lines) | stat: -rw-r--r-- 2,728 bytes parent folder | download | duplicates (5)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Plot a wiring graph of the network <network> with the supplied
# graphical parameters.
# Requires igraph.
# Returns the igraph structure representing the wiring graph. 
plotNetworkWiring <- function(network,layout=layout.fruchterman.reingold,plotIt=TRUE,...)
{
  stopifnot(inherits(network,"ProbabilisticBooleanNetwork") | inherits(network,"BooleanNetworkCollection")
            | inherits(network,"BooleanNetwork") | inherits(network,"SymbolicBooleanNetwork"))
  
  if (installed.packages()["igraph","Version"] < package_version("0.6"))
    bias <- 1
  else
    bias <- 0 
    
  edgeList <- c()
  
  # construct list of edges from interactions

  if (inherits(network,"BooleanNetwork"))
  # deterministic network
  {
    for (i in seq_along(network$genes))
    {
      if (network$interactions[[i]]$input[1] != 0)
      # no edges for constant genes
      {
        edgeList <- rbind(edgeList,
                  cbind(network$interactions[[i]]$input,
                  rep(i,length(network$interactions[[i]]$input))))
      }
    }
  }
  else
  if (inherits(network,"SymbolicBooleanNetwork"))
  # symbolic network
  {
    inputs <- lapply(network$interactions, getInputs, index=TRUE)
    for (i in seq_along(network$genes))
    {
      edgeList <- rbind(edgeList,
                  cbind(inputs[[i]],
                  rep(i,length(inputs[[i]]))))
    }
  }  
  else
  # probabilistic network
  {
    for (i in seq_along(network$genes))
    {
      for (j in seq_along(network$interactions[[i]]))
      {
        if (network$interactions[[i]][[j]]$input[1] != 0)
        # no edges for constant genes
        {
          edgeList <- rbind(edgeList,
                            cbind(network$interactions[[i]][[j]]$input,
                            rep(i,length(network$interactions[[i]][[j]]$input))))
        }
      }
    }
  }

  # build graph from edge list
  res <- graph.data.frame(edgeList-bias,directed=TRUE,vertices=as.data.frame((seq_along(network$genes)) - bias))
  res <- set.vertex.attribute(res,"name",value=network$genes)
  
  args <- list(...)
  
  # check for certain graphical parameters in ... 
  # that have different default values in this plot
  if (is.null(args$vertex.color))
    args$vertex.color <- "grey"
    
  if (is.null(args$edge.arrow.size))
    args$edge.arrow.size <- 0.5
    
  if (is.null(args$vertex.label.cex))
    args$vertex.label.cex <- 0.7

  if (is.null(args$vertex.size))
    args$vertex.size <- 18    

  if (plotIt)
  {
    plot(res,vertex.label=network$genes,vertex.label.cex=args$vertex.label.cex,
         vertex.size=args$vertex.size,vertex.color=args$vertex.color,
         edge.arrow.size=args$edge.arrow.size,
         layout=layout,...)
  }
  return(invisible(res))
}