Attachment 'ba_model.py'
Download 1 from cytoscape import Cytoscape
2
3 import cytoscape.layout.CyLayouts as CyLayouts
4 import java.lang.Integer as Integer
5 import random
6
7 ORIGINAL_NODES = 2
8 MAX_LOOP = 1000 - ORIGINAL_NODES
9 EACH_TRIAL = 2
10
11 # Create network
12 graph = Cytoscape.createNetwork("Barabasi-Albert generated by Python Script");
13
14 #Create seed graph
15 node1 = Cytoscape.getCyNode("Seed 1", True)
16 node2 = Cytoscape.getCyNode("Seed 2", True)
17 nodes = [node1, node2]
18
19 graph.addNode(node1)
20 graph.addNode(node2)
21 edge = Cytoscape.getCyEdge(node1, node2, "interaction", "-", True);
22 graph.addEdge(edge);
23
24 degree = 0.0
25 prob = 0.0
26 i = 0
27
28 # Grow the seed graph
29 print "\n\n============Barabasi-Albert Random Graph Generator ============"
30 print "\nGenerating network (1000 nodes). Please wait..."
31
32 while (i<MAX_LOOP) :
33 newNode = Cytoscape.getCyNode(Integer.toString(i), True)
34 graph.addNode(newNode)
35
36 j = 0
37 while (j<EACH_TRIAL):
38 created = False
39 while (created == False):
40 idx = random.random() * len(nodes)
41 selectedNode = nodes[int(idx)]
42 degree = graph.getDegree(selectedNode)
43 prob = (degree + 1.0) / (graph.getNodeCount() + graph.getEdgeCount() - 1.0)
44 if prob >= random.random() and newNode.getIdentifier != selectedNode.getIdentifier:
45 created = True;
46
47 edge = Cytoscape.getCyEdge(newNode, selectedNode, "interaction", "-", True)
48 graph.addEdge(edge)
49 nodes.append(newNode)
50 j = j+1
51
52 i = i+1
53
54 # Layout nodes
55
56 print "Network generated. Start layout..."
57
58 CyLayouts.getLayout("force-directed").doLayout();
59 Cytoscape.getCurrentNetworkView().redrawGraph(False, True);
60
61 print "\n\nDone!"
62
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.