BuildNetwork: Network object creation

Description Usage Arguments Value Author(s) See Also Examples

Description

Given a list of scored edges and a REQUIRED vector of labels (e.g, 1:p), this function builds an object "Network". This is useful for exporting a network described by a list of edges to a network described by an adjacency matrix.

Usage

1
BuildNetwork(Edges,Labels,nonedges.val=NA)

Arguments

Edges

a n \times 3 matrix (each line contains a couple of vertices plus the associated score)

Labels

a vector of labels for the vertices

nonedges.val

optional. Value attributed to the not existing edges in the generated score matrix out$Score, default=NA

Value

a list that contains out$Vertices$Num the number of vertices, out$Vertices$Labels a vector of labels of the vertices, out$Vertices$Connected a vector of the connected vertices, out$Edges$Prop the proportion of edges, out$Edges$Num the number of edges, the graph of the network (out$AdjMatrix an adjacency matrix and out$Edges$List a list of edges) and out$Score a score matrix.

Author(s)

Lebre Sophie (http://icube-bfo.unistra.fr/en/index.php/Sophie_Lebre),

Chiquet Julien (http://stat.genopole.cnrs.fr/~jchiquet).

See Also

BuildEdges

Examples

  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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
library(G1DBN)

## ========================
## SIMULATING THE NETWORK
## ________________________

## number of genes
p <- 10
## number of time points
n <- 20
## proportion of genes
geneProp <- 0.05
## the network - adjacency Matrix
MyNet <- SimulNetworkAdjMatrix(p,geneProp,c(-1.5,-0.5,0.5,1.5))

cat("\n==========================================\n")
cat("SIMULATION\n")

## ======================================
## SIMULATING THE TIME SERIES EXPERIMENTS
## ______________________________________
##
## Autoregressive model
##
cat("Time series experiments with")

## initializing the B vector
B <- runif(p,-1,1)
## initializing the variance of the noise
sigmaEps <- runif(p,0.1,0.5)
## initializing the process Xt
X0 <- B + rnorm(p,0,sigmaEps*10)
## the times series process
Xn <- SimulGeneExpressionAR1(MyNet$A,B,X0,sigmaEps,n)

## ======================================
## NETWORK INFERENCE WITH G1DBN
## ______________________________________
##
cat("\n==========================================\n")
cat("NETWORK INFERENCE\n")
cat("Using a Dynamic Bayesian Network model\n")

## STEP 1
## ------
cat("STEP 1...\n")
S1 <- DBNScoreStep1(Xn, method='ls')

## STEP 2
## ------
cat("STEP 2...\n")
alpha1=0.5
S2 <- DBNScoreStep2(S1$S1ls, data=Xn, method='ls', alpha1=alpha1)

## ======================================
## POST TREATMENTS

## building the inferred Graph
G1 <- BuildEdges(S1$S1ls,threshold=alpha1,dec=FALSE)

## encoding as the adjancecy matrix graph
Step1InferredNet <- BuildNetwork(G1,1:p)
Step1InferredNet

#Step 2
alpha2=0.05
G2 <- BuildEdges(S2,threshold=alpha2,dec=FALSE)
Step2InferredNet <- BuildNetwork(G2,1:p)


## ======================================
## PLOTTING THE RESULTS...
## ______________________________________
## Not run: 
cat("\n==========================================\n")
cat("SUMMARY\n")
cat("Plotting the results...\n")
split.screen(c(1,3))


## The Original graph and data
## ---------------------------
# set the edges list of the simulated network
G0 <- BuildEdges(MyNet$AdjMatrix,threshold=0.9,dec=TRUE)

## Nodes coordinates are calculated according to the global structure of the network
all_parents=c(G0[,1],G1[,1], G2[,1])
all_targets=c(G0[,2],G1[,2], G2[,2])
posEdgesG0=1:dim(G0)[1]
posEdgesG1=(dim(G0)[1]+1):(dim(G0)[1]+dim(G1)[1])
posEdgesG2=(dim(G0)[1]+dim(G1)[1]+1):length(all_parents)

## Global network with all the edges
netAll =
graph.edgelist(cbind(as.character(all_parents),as.character(all_targets)))

## Nodes coordinates
nodeCoord=layout.fruchterman.reingold(netAll)


#after Step 1
screen(1)
# set the edges list
netG1 = graph.edgelist(cbind(as.character(G1[,1]),as.character(G1[,2])))
# set the object for plotting the network with global coordinates of all nodes
G1toPlot=delete.edges(netAll, E(netAll)[c(posEdgesG0,posEdgesG2)-1] )
# plot the network
plot(G1toPlot, layout=nodeCoord, vertex.label = 
get.vertex.attribute(G1toPlot, name="name"), edge.arrow.size = 0.2,
main="G1DBN Inferred network:\n Step 1")

#after Step 2
screen(2)
# set the edges list
netG2 = graph.edgelist(cbind(as.character(G2[,1]),as.character(G2[,2])))
# set the object for plotting the network with global coordinates of all nodes
G2toPlot=delete.edges(netAll, E(netAll)[c(posEdgesG0,posEdgesG1)-1 ] )
# plot the network
plot(G2toPlot, layout=nodeCoord, vertex.label = 
get.vertex.attribute(G2toPlot, name="name"),edge.arrow.size = 0.2,
main="G1DBN Inferred network:\n Step 2")

screen(3)
net0 = graph.edgelist(cbind(as.character(G0[,1]),as.character(G0[,2])))
# set the object for plotting the network with global coordinates of all nodes
G0toPlot=delete.edges(netAll, E(netAll)[c(posEdgesG1,posEdgesG2)-1] )
plot(G0toPlot, layout=nodeCoord, vertex.label =
get.vertex.attribute(G0toPlot, name="name"), edge.arrow.size = 0.2,
main="Simulated network:")

close.screen(all = TRUE)

## End(Not run)
cat("")
cat("\nDONE !\n")

Example output

Loading required package: MASS
Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union


==========================================
SIMULATION
Time series experiments with
==========================================
NETWORK INFERENCE
Using a Dynamic Bayesian Network model
STEP 1...
Treating 10 vertices:
10% 20% 30% 40% 50% 60% 70% 80% 90% 100% 
STEP 2...
$Vertices
$Vertices$Num
[1] 10

$Vertices$Labels
 [1]  1  2  3  4  5  6  7  8  9 10

$Vertices$Connected
 [1]  1  2  3  4  5  6  7  8  9 10


$Edges
$Edges$Prop
[1] 0.18

$Edges$Num
[1] 18

$Edges$List
      Pred Target Score
 [1,]   10      8 0.000
 [2,]    9     10 0.000
 [3,]    7      4 0.000
 [4,]    1      1 0.001
 [5,]    5      2 0.002
 [6,]   10      3 0.023
 [7,]    2      1 0.088
 [8,]    5      7 0.130
 [9,]    3      7 0.184
[10,]   10      9 0.281
[11,]    5      5 0.288
[12,]    1      8 0.297
[13,]    7      8 0.300
[14,]    1      3 0.372
[15,]   10      2 0.400
[16,]    7      6 0.418
[17,]    2     10 0.465
[18,]    1      7 0.480


$AdjMatrix
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    1    0    0    0    0    0    0    0     0
 [2,]    0    0    0    0    1    0    0    0    0     1
 [3,]    1    0    0    0    0    0    0    0    0     1
 [4,]    0    0    0    0    0    0    1    0    0     0
 [5,]    0    0    0    0    1    0    0    0    0     0
 [6,]    0    0    0    0    0    0    1    0    0     0
 [7,]    1    0    1    0    1    0    0    0    0     0
 [8,]    1    0    0    0    0    0    1    0    0     1
 [9,]    0    0    0    0    0    0    0    0    0     1
[10,]    0    1    0    0    0    0    0    0    1     0

$Score
       [,1]  [,2]  [,3] [,4]  [,5] [,6]  [,7] [,8] [,9] [,10]
 [1,] 0.001 0.088    NA   NA    NA   NA    NA   NA   NA    NA
 [2,]    NA    NA    NA   NA 0.002   NA    NA   NA   NA 0.400
 [3,] 0.372    NA    NA   NA    NA   NA    NA   NA   NA 0.023
 [4,]    NA    NA    NA   NA    NA   NA 0.000   NA   NA    NA
 [5,]    NA    NA    NA   NA 0.288   NA    NA   NA   NA    NA
 [6,]    NA    NA    NA   NA    NA   NA 0.418   NA   NA    NA
 [7,] 0.480    NA 0.184   NA 0.130   NA    NA   NA   NA    NA
 [8,] 0.297    NA    NA   NA    NA   NA 0.300   NA   NA 0.000
 [9,]    NA    NA    NA   NA    NA   NA    NA   NA   NA 0.281
[10,]    NA 0.465    NA   NA    NA   NA    NA   NA    0    NA


==========================================
SUMMARY
Plotting the results...
[1] 1 2 3

DONE !

G1DBN documentation built on May 2, 2019, 3:41 p.m.

Related to BuildNetwork in G1DBN...