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.

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