forked from emblab-westlake/MbioAssy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_Random_network.R
37 lines (28 loc) · 1.29 KB
/
5_Random_network.R
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
###@author: Feng Ju
###@email: jufeng@westlake.edu.cn
###@cite Ju F, Xia Y, Guo F, Wang ZP, Zhang T. 2014.
###@Taxonomic relatedness shapes bacterial assembly in activated sludge of globally distributed wastewater treatment plants.
###@Environmental Microbiology. 16(8):2421-2432
library(igraph)
#set the size of random network
n=2194 #number of nodes
e=44680 #number of edges
#generate 1000 random networks
for (i in 1:1000) {
g <- erdos.renyi.game(n, e,'gnm',weight=T,mode="undirected")
# Global toplogical features
c <- cluster_walktrap(g)
md <- modularity(g, membership(c), weights = NULL)
cc <- transitivity(g, vids = NULL,
weights = NULL)
spl <- average.path.length(g, directed=FALSE, unconnected=TRUE)
gd <- graph.density(g, loops=FALSE)
nd <- diameter(g, directed = FALSE, unconnected = TRUE, weights = NULL)
ND <- degree(g, v = V(g), mode="all")
ad <- mean(node.degree)
global.topol <- data.frame(n,e,cc,spl,md,gd,nd,ad)
write.table(global.topol, file = sprintf("N%dE%d.er.random.network.xls",n,e),
append = TRUE, sep = "\t",row.names = FALSE, col.names = TRUE) }
# print node distribution statistics
degree <- data.frame(table(degree=factor(ND, levels=seq_len(max(ND)))))
plot(degree)