Author: kono
Date: 2008-09-24 16:10:55 -0700 (Wed, 24 Sep 2008)
New Revision: 14957

Added:
   csplugins/trunk/ucsd/kono/PythonEnginePlugin/testscripts/
   csplugins/trunk/ucsd/kono/PythonEnginePlugin/testscripts/test1.py
Log:
Initial checkin for Python plugin code.

Added: csplugins/trunk/ucsd/kono/PythonEnginePlugin/testscripts/test1.py
===================================================================
--- csplugins/trunk/ucsd/kono/PythonEnginePlugin/testscripts/test1.py   
2008-09-24 23:10:44 UTC (rev 14956)
+++ csplugins/trunk/ucsd/kono/PythonEnginePlugin/testscripts/test1.py   
2008-09-24 23:10:55 UTC (rev 14957)
@@ -0,0 +1,61 @@
+from cytoscape import Cytoscape
+
+import cytoscape.layout.CyLayouts as CyLayouts
+import java.lang.Integer as Integer
+import random
+
+ORIGINAL_NODES = 2
+MAX_LOOP = 1000 - ORIGINAL_NODES
+EACH_TRIAL = 2
+
+# Create network
+graph = Cytoscape.createNetwork("Barabasi-Albert generated by Python Script");
+
+#Create seed graph
+node1 = Cytoscape.getCyNode("Seed 1", True)
+node2 = Cytoscape.getCyNode("Seed 2", True)
+nodes = [node1, node2]
+
+graph.addNode(node1)
+graph.addNode(node2)
+edge = Cytoscape.getCyEdge(node1, node2, "interaction", "-", True);
+graph.addEdge(edge);
+
+degree = 0.0
+prob = 0.0
+i = 0
+
+# Grow the seed graph
+print "\n\n============Barabasi-Albert Random Graph Generator ============"
+print "\nGenerating network (1000 nodes).  Please wait..."
+
+while (i<MAX_LOOP) :
+    newNode = Cytoscape.getCyNode(Integer.toString(i), True)
+    graph.addNode(newNode)
+    
+    j = 0
+    while (j<EACH_TRIAL):   
+        created = False
+        while (created == False):
+            idx = random.random() * len(nodes)
+            selectedNode = nodes[int(idx)]
+            degree = graph.getDegree(selectedNode)
+            prob = (degree + 1.0) / (graph.getNodeCount() + 
graph.getEdgeCount() - 1.0)
+            if prob >= random.random() and newNode.getIdentifier != 
selectedNode.getIdentifier:
+                created = True;
+        
+        edge = Cytoscape.getCyEdge(newNode, selectedNode, "interaction", "-", 
True)
+        graph.addEdge(edge)
+        nodes.append(newNode)
+        j = j+1        
+    
+    i = i+1
+
+# Layout nodes
+
+print "Network generated.  Start layout..."
+
+CyLayouts.getLayout("force-directed").doLayout();
+Cytoscape.getCurrentNetworkView().redrawGraph(False, True);
+
+print "\n\nDone!"
\ No newline at end of file


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to