-
Notifications
You must be signed in to change notification settings - Fork 0
/
vx680.html
225 lines (197 loc) · 7.23 KB
/
vx680.html
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<!-- saved from url=(0044)http://kenedict.com/networks/worldcup14/vis/ , thanks Andre!-->
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF8">
<title>VX680 Network</title>
<script type="text/javascript" src="vis.js"></script>
<script type="text/javascript" src="nodes.js"></script>
<script type="text/javascript" src="edges.js"></script>
<link type="text/css" rel="stylesheet" href="vis.css">
<style type="text/css">
#mynetwork {
width: 800px;
height: 800px;
border: 1px solid lightgray;
}
</style>
</head>
<body>
<h2>VX860</h2>
<div style="width:800px; font-size:14px;">
This visualization uses vis.js, and is based on <a href="http://visjs.org/examples/network/29_neighbourhood_highlight.html">vis.js example 29</a>. Clicking a node grays out all nodes besides the first degree connections to it, and displays the protein names of only the first and second degree nodes. I've taken node and edge information from <a href="http://string-db.org">string-db</a> for VX680's possible 1st degree connections of ABL1, BCR, Aurora Kinases A-C, and FLT3. This takes all connections above what string-db lists as 0.700 confidence.
<br /><br />
</div>
<div id="mynetwork"></div>
<script type="text/javascript">
var network;
var nodes = new vis.DataSet();
var edges = new vis.DataSet();
function redrawAll() {
nodes.clear();
edges.clear();
network = null;
// create a network
nodes.add(nodesData);
edges.add(edgesData);
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
nodes: {
shape: 'dot',
radiusMin: 10,
radiusMax: 30,
fontSize: 12,
fontFace: "Tahoma",
scaleFontWithValue:true,
fontSizeMin:8,
fontSizeMax:20,
fontThreshold:12,
fontSizeMaxVisible:20
},
edges: {
width: 0.15,
inheritColor: "from"
},
tooltip: {
delay: 200,
fontSize: 12,
color: {
background: "#fff"
}
},
smoothCurves: {dynamic:false, type: "continuous"},
stabilize: false,
//physics: {barnesHut: {gravitationalConstant: 0, centralGravity: 1, springConstant: 1}},
physics: {barnesHut: {enabled: false}},
hideEdgesOnDrag: true
};
network = new vis.Network(container, data, options);
network.on("click",onClick);
}
function onClick(selectedItems) {
var nodeId;
var degrees = 2;
// we get all data from the dataset once to avoid updating multiple times.
var allNodes = nodes.get({returnType:"Object"});
if (selectedItems.nodes.length == 0) {
// restore on unselect
for (nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
allNodes[nodeId].color = undefined;
if (allNodes[nodeId].oldLabel !== undefined) {
allNodes[nodeId].label = allNodes[nodeId].oldLabel;
allNodes[nodeId].oldLabel = undefined;
}
allNodes[nodeId]['levelOfSeperation'] = undefined;
allNodes[nodeId]['inConnectionList'] = undefined;
}
}
}
else {
// we clear the level of separation in all nodes.
clearLevelOfSeperation(allNodes);
// we will now start to collect all the connected nodes we want to highlight.
var connectedNodes = selectedItems.nodes;
// we can store them into levels of separation and we could then later use this to define a color per level
// any data can be added to a node, this is just stored in the nodeObject.
storeLevelOfSeperation(connectedNodes,0, allNodes);
for (var i = 1; i < degrees + 1; i++) {
appendConnectedNodes(connectedNodes);
storeLevelOfSeperation(connectedNodes, i, allNodes);
}
for (nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
if (allNodes[nodeId]['inConnectionList'] == true) {
if (allNodes[nodeId]['levelOfSeperation'] !== undefined) {
if (allNodes[nodeId]['levelOfSeperation'] >= 2) {
allNodes[nodeId].color = 'rgba(150,150,150,0.75)';
}
else {
allNodes[nodeId].color = undefined;
}
}
else {
allNodes[nodeId].color = undefined;
}
if (allNodes[nodeId].oldLabel !== undefined) {
allNodes[nodeId].label = allNodes[nodeId].oldLabel;
allNodes[nodeId].oldLabel = undefined;
}
}
else {
allNodes[nodeId].color = 'rgba(200,200,200,0.5)';
if (allNodes[nodeId].oldLabel === undefined) {
allNodes[nodeId].oldLabel = allNodes[nodeId].label;
allNodes[nodeId].label = "";
}
}
}
}
}
var updateArray = [];
for (nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
updateArray.push(allNodes[nodeId]);
}
}
nodes.update(updateArray);
}
/**
* update the allNodes object with the level of separation.
* Arrays are passed by reference, we do not need to return them because we are working in the same object.
*/
function storeLevelOfSeperation(connectedNodes, level, allNodes) {
for (var i = 0; i < connectedNodes.length; i++) {
var nodeId = connectedNodes[i];
if (allNodes[nodeId]['levelOfSeperation'] === undefined) {
allNodes[nodeId]['levelOfSeperation'] = level;
}
allNodes[nodeId]['inConnectionList'] = true;
}
}
function clearLevelOfSeperation(allNodes) {
for (var nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
allNodes[nodeId]['levelOfSeperation'] = undefined;
allNodes[nodeId]['inConnectionList'] = undefined;
}
}
}
/**
* Add the connected nodes to the list of nodes we already have
*
*
*/
function appendConnectedNodes(sourceNodes) {
var tempSourceNodes = [];
// first we make a copy of the nodes so we do not extend the array we loop over.
for (var i = 0; i < sourceNodes.length; i++) {
tempSourceNodes.push(sourceNodes[i])
}
for (var i = 0; i < tempSourceNodes.length; i++) {
var nodeId = tempSourceNodes[i];
if (sourceNodes.indexOf(nodeId) == -1) {
sourceNodes.push(nodeId);
}
var connectedNodes = network.getConnectedNodes(nodeId);
addUnique(connectedNodes,sourceNodes);
}
tempSourceNodes = null;
}
/**
* Join two arrays without duplicates
* @param fromArray
* @param toArray
*/
function addUnique(fromArray, toArray) {
for (var i = 0; i < fromArray.length; i++) {
if (toArray.indexOf(fromArray[i]) == -1) {
toArray.push(fromArray[i]);
}
}
}
redrawAll()
</script>
</body></html>