forked from zhaotao1987/SynNet-Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infomap.r
48 lines (31 loc) · 1.52 KB
/
infomap.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
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/Rscript
# Usage: Rscript myscript.R networkfile(in 2 columns) outputname
#
# Be aware of the delimit and header in the network file,make changes to Line 15 if needed.
# Try if args work.
#head(args[1])
require(igraph)
args<-commandArgs(TRUE)
#data <-read.table(args[1],sep='\t',header=F,skip=4)
# Your network should in a two-column edgelist format.
data <-read.table(args[1],sep='\t',header=F)
# convert edgelist into a undirected graph object
network <- graph.data.frame(data,directed=F)
# simplify command to remove duplicated edges, if exist, error would occur when clustering.
net_simple <- simplify(network)
# Write_graph(net_simple,file="simple_network",format=c("ncol"))
# write_graph(net_simple,file=args[2],format=c("ncol"))
# Kcore Table
# kc <- coreness(net_simple,mode="all")
# write.table(kc,args[4],quote=F,sep='\t',row.names=T,col.names=F)
# You could set a filter here for kcore higher than 3
# Now we do clustering for the network
# clusters1 <- cluster_louvain(network)
# clusters2 <- cluster_walktrap(network)
clusters3 <- cluster_infomap(net_simple)
out3 <- as.data.frame(list(names=clusters3$names, mem=clusters3$membership))
write.table(out3,args[2],quote=F,sep='\t',row.names=F)
# out1 <- as.data.frame(list(names=clusters1$names, mem=clusters1$membership))
# write.table(out1,args[2],quote=F,sep='\t',row.names=F)
# out2 <- as.data.frame(list(names=clusters2$names, mem=clusters2$membership))
# write.table(out2,args[3],quote=F,sep='\t',row.names=F)