Skip to content

Instantly share code, notes, and snippets.

@keiono
Created December 11, 2013 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keiono/7919559 to your computer and use it in GitHub Desktop.
Save keiono/7919559 to your computer and use it in GitHub Desktop.
Sample script for Python: Generating complete graph
#
# Python Script to generate complete graph
#
NUM_NODES = 20
print "Creating complete graph with " + str(NUM_NODES) + " nodes..."
new_network = cyAppAdapter.getCyNetworkFactory().createNetwork()
new_network.getRow(new_network).set("name", "Complete Graph Created by Python Script")
cyAppAdapter.getCyNetworkManager().addNetwork(new_network);
# Add nodes
nodes = [];
for i in range (NUM_NODES):
node_name = "Node " + str(i)
node = new_network.addNode()
new_network.getRow(node).set("name", node_name)
nodes.append(node)
# Add edges
edge_count = 0;
for source in nodes:
for target in nodes:
if new_network.containsEdge(source, target) is False \
and new_network.containsEdge(target, source) is False \
and source is not target:
edge = new_network.addEdge(source, target, True)
edge_count = edge_count + 1
new_network.getRow(edge).set("name", "Edge " + str(edge_count))
new_network.getRow(edge).set("interaction", "interacts_with")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment