-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.R
111 lines (94 loc) · 3.76 KB
/
graph.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
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
#====================================================================
# To read graphData and visualize the correspondig graph
# By (Ameer) Amirhossein Afshinfard - [email protected]
# Bioinformatics Research Lab, Sharif Unversity of Technology.
# https://rstudio-pubs-static.s3.amazonaws.com/74248_3bd99f966ed94a91b36d39d8f21e3dc3.html
# http://users.cecs.anu.edu.au/~xlx/teaching/css2013/handout/igraph.pdf
# http://igraph.org/r/doc/tkplot.html
# https://stackoverflow.com/questions/5364264/how-to-control-the-igraph-plot-layout-with-fixed-positions
# https://github.com/igraph/rigraph/issues/63
# http://igraph.org/r/doc/subgraph.html
# http://www.shizukalab.com/toolkits/sna/plotting-networks-pt-2
# http://igraph.org/r/doc/decompose.html
# http://igraph.org/r/doc/components.html
# http://igraph.org/r/doc/layout_in_circle.html
# http://igraph.org/r/doc/edge_attr.html
#
#====================================================================
## read data
library(igraph)
#<<<<<<< HEAD
#=======
#>>>>>>> 5e7bf2f71818386c65a6e73cd252a10aca92b1d5
dev.off()
sparseMatrix = read.table("/home/ameer/ExactSV/SV_out/graphData",sep = "\t",col.names=c("row","col","Weight"));
#sparseMatrix[,1:2]=sparseMatrix[,1:2]+1
nodeLoci = read.table("/home/ameer/ExactSV/SV_out/graphData2",sep = "\t",col.names=c("X","Y"));
nodeLoci
nodeWeights = read.table("/home/ameer/ExactSV/SV_out/graphData3",sep = "\t",col.names=c("Weight"));
nodeWeights
graphDim = dim(nodeWeights)[1]
adjaMatrix = matrix(0,graphDim,graphDim)
adjaMatrix[as.matrix(sparseMatrix[,1:2])]=sparseMatrix[,3]
sum(as.logical(adjaMatrix))
class(adjaMatrix)
dim(adjaMatrix)
myGraph = graph_from_adjacency_matrix(adjaMatrix, mode = c("max"), weighted = TRUE, diag = TRUE,
add.colnames = NULL, add.rownames = NA)
E(myGraph)
is_weighted(myGraph)
tkplot(myGraph)
plot(myGraph)
l <-layout.reingold.tilford(myGraph)
class(l )
class(nodeLoci)
l = as.matrix(nodeLoci)
l2 = l
l2[,1] = log(l[,1])
l2[32,1] = 14
plot(myGraph,
layout = l)
tkplot(myGraph,
layout = l2)
tkplot(myGraph,
layout = l)
a= V(myGraph)
a[1] = 2
a = 1:56
a[1]=2
a[2]=1
a
l = layout_in_circle(myGraph, order = V(myGraph))
l = layout_in_circle(myGraph, order = a)
tkplot(myGraph,
layout = l)
node
l
#####################################################################################################
#####################################################################################################
#####################################################################################################
install.packages("GGally")
install.packages("network")
install.packages("sna")
install.packages("devtools")
devtools::install_github("briatte/ggnet")
library(ggnet)
library(network)
library(sna)
library(ggplot2)
net = network(adjaMatrix,directed = FALSE,ignore.eval = FALSE,names.eval = "weights")
network.vertex.names(net) = as.character(1:10000)
ggnet2(net, node.size = 5,label = as.character(as.matrix(nodeWeights)),
label.color = "black",edge.label = "weights",edge.label.color = "darkred", edge.size = 1,
edge.color = "black",node.color = "grey")
net %v% "x" = nodeLoci[,1]
net %v% "y" = as.numeric(as.matrix((runif(length(nodeLoci[,2]))/5)-0.1))
ggnet2(net, node.size = 5, mode = c("x", "y"),label = as.character(as.matrix(nodeWeights)),
label.color = "black",edge.label = "weights",edge.label.color = "darkred", edge.size = 1,
edge.color = "black",node.color = "grey")
net %v% "x" = nodeLoci[,1]
net %v% "y" = as.numeric(nodeLoci[,2]+as.matrix((runif(length(nodeLoci[,2]))/5)-0.1))
ggnet2(net, node.size = 5, mode = c("x", "y"),label = as.character(as.matrix(nodeWeights)),
label.color = "black",edge.label = "weights",edge.label.color = "darkred", edge.size = 1,
edge.color = "black",node.color = "grey")
dev.off()