CytoscapeRPC Python Example

From BioAssist
Jump to: navigation, search

Xmlrpclib is part of the standard Python distribution so no additional packages are required. When using Ipython you can use command line completion to see which method names are available.

Code Result
  1. import xmlrpclib
  2.  
  3. # Connect to server: specify the location and port
  4. server = xmlrpclib.ServerProxy("http://localhost:9000")
  5.  
  6. # Test if connection works: should print 'It works!'
  7. print server.Cytoscape.test()
  8.  
  9. # Create new network
  10. networkid = server.Cytoscape.createNetwork("Cytoscape Python test")
  11.  
  12. # Create some nodes
  13. server.Cytoscape.createNodes(networkid, ['a', 'b', 'c', 'd', 'e'])
  14.  
  15. # Create some edges
  16. server.Cytoscape.createEdgesFromVector(['a', 'a', 'b', 'd', 'd'], 
  17.         ['b', 'c', 'c', 'd', 'e'])
  18.  
  19. # Add some attributes
  20. server.Cytoscape.addNodeAttributes("type", "STRING", 
  21.         {'a':'aa', 'b':'aa', 'c':'bb', 'd':'bb', 'e':'cc'}, True)
  22.  
  23. # Create VisMapper based on these attributes
  24. server.Cytoscape.setDiscreteNodeShapeMapper(networkid, 'default', 
  25.         'type', 'diamond', {'aa':'ellipse', 'bb':'octagon', 'cc':'round_rect'}, True)
  26.  
  27. # Perform default layout (usually grid layout)
  28. server.Cytoscape.performDefaultLayout(networkid)
  29.  
  30. # Select some nodes
  31. server.Cytoscape.setSelectedNodes(networkid, ['a', 'b', 'c'], True)
  32.  
  33. # Change the colour of some nodes
  34. server.Cytoscape.setNodeFillColor(networkid, ['a', 'b', 'e'], 123, 0, 255)
  35.  
  36. # Change the shape of some other nodes
  37. server.Cytoscape.setNodeShape(networkid, ['c', 'd'], "triangle")
CytoscapeRPC python example.png