Attachment 'ba_model_generator.rb'
Download 1 require 'java'
2
3 include_class 'cytoscape.Cytoscape'
4 include_class 'cytoscape.CyNode'
5 include_class 'cytoscape.CyEdge'
6 include_class 'cytoscape.CyNetwork'
7 include_class 'cytoscape.layout.CyLayouts'
8 include_class 'java.lang.Integer'
9
10 ORIGINAL_NODES = 2
11 MAX_LOOP = 1000 - ORIGINAL_NODES
12 EACH_TRIAL = 2
13
14 # Create network
15 graph = Cytoscape.createNetwork("Barabasi-Albert Scale Free Network");
16
17 nodes = Array.new
18
19 #Create seed graph
20 node1 = Cytoscape.getCyNode("Seed 1", true)
21 node2 = Cytoscape.getCyNode("Seed 2", true)
22 nodes << node1
23 nodes << node2
24 graph.addNode(node1)
25 graph.addNode(node2)
26 edge = Cytoscape.getCyEdge(node1, node2, "interaction", "-", true);
27 graph.addEdge(edge);
28
29 degree = 0.0
30 prob = 0.0
31 i = 0
32
33 # Grow the seed graph
34 while i<MAX_LOOP do
35 newNode = Cytoscape.getCyNode("Node " + Integer.toString(i), true)
36 graph.addNode(newNode)
37
38 j = 0
39 while j<EACH_TRIAL do
40 created = false
41 while created == false do
42 selectedNode = nodes[rand(nodes.length)]
43 degree = graph.getDegree(selectedNode)
44 prob = (degree + 1.0) / (graph.getNodeCount() + graph.getEdgeCount() - 1.0)
45 if prob >= rand && newNode.getIdentifier != selectedNode.getIdentifier
46 created = true;
47 end
48 end
49
50 edge = Cytoscape.getCyEdge(newNode, selectedNode, "interaction", "-", true);
51 graph.addEdge(edge);
52 nodes << newNode
53 j = j+1
54 end
55 i = i+1
56 end
57
58 # Layout nodes
59 CyLayouts.getLayout("force-directed").doLayout();
60 Cytoscape.getCurrentNetworkView().redrawGraph(false, true);
61
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2011-10-20 20:44:43, 1.7 KB) [[attachment:ba_model.py]]
- [get | view] (2011-10-20 20:44:43, 1.4 KB) [[attachment:ba_model_generator.rb]]
- [get | view] (2011-10-20 20:44:43, 0.6 KB) [[attachment:complete_graph.js]]
- [get | view] (2011-10-20 20:44:43, 0.9 KB) [[attachment:dialog.js]]
- [get | view] (2011-10-20 20:44:43, 64.3 KB) [[attachment:groovyEngine1.png]]
- [get | view] (2011-10-20 20:44:43, 0.2 KB) [[attachment:hello_cytoscape.js]]
- [get | view] (2011-10-20 20:44:43, 0.2 KB) [[attachment:hello_cytoscape.rb]]
- [get | view] (2011-10-20 20:44:43, 5.7 KB) [[attachment:javascriptSample1.png]]
- [get | view] (2011-10-20 20:44:43, 291.8 KB) [[attachment:javascriptSample2.png]]
- [get | view] (2011-10-20 20:44:43, 70.6 KB) [[attachment:javascriptSample3.png]]
- [get | view] (2011-10-20 20:44:43, 59.0 KB) [[attachment:javascriptSample4.png]]
- [get | view] (2011-10-20 20:44:43, 1.7 KB) [[attachment:kegg_sample1.rb]]
- [get | view] (2011-10-20 20:44:43, 0.4 KB) [[attachment:load_multiple_networks.rb]]
- [get | view] (2011-10-20 20:44:43, 0.6 KB) [[attachment:matrix.rb]]
- [get | view] (2011-10-20 20:44:43, 5.4 KB) [[attachment:matrix1.png]]
- [get | view] (2011-10-20 20:44:43, 49.2 KB) [[attachment:pythonEngine1.png]]
- [get | view] (2011-10-20 20:44:43, 286.7 KB) [[attachment:pythonEngine2.png]]
- [get | view] (2011-10-20 20:44:43, 116.9 KB) [[attachment:rubyConsole1.png]]
- [get | view] (2011-10-20 20:44:43, 64.2 KB) [[attachment:rubyConsole2.png]]
- [get | view] (2011-10-20 20:44:43, 19.6 KB) [[attachment:rubyEngine.png]]
- [get | view] (2011-10-20 20:44:43, 12.1 KB) [[attachment:rubySample1.png]]
- [get | view] (2011-10-20 20:44:43, 136.9 KB) [[attachment:rubySample2.png]]
- [get | view] (2011-10-20 20:44:43, 194.9 KB) [[attachment:rubySample3.png]]
- [get | view] (2011-10-20 20:44:43, 284.7 KB) [[attachment:rubySample4.png]]
- [get | view] (2011-10-20 20:44:43, 1.8 KB) [[attachment:sample_human_network.sif]]
- [get | view] (2011-10-20 20:44:43, 45.6 KB) [[attachment:scripting1.png]]
- [get | view] (2011-10-20 20:44:43, 343.9 KB) [[attachment:scripting2.png]]
- [get | view] (2011-10-20 20:44:43, 1.1 KB) [[attachment:social_graph.js]]
- [get | view] (2011-10-20 20:44:43, 2.7 KB) [[attachment:social_graph_new.js]]
- [get | view] (2011-10-20 20:44:43, 120.9 KB) [[attachment:twitterSample1.png]]
- [get | view] (2011-10-20 20:44:43, 324.2 KB) [[attachment:twitterSample2.png]]
You are not allowed to attach a file to this page.