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.

You are not allowed to attach a file to this page.

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux