← Revision 5 as of 2013-12-11 18:38:34
Size: 2727
Comment:
|
← Revision 6 as of 2013-12-11 18:43:03 →
Size: 2972
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 76: | Line 76: |
This script is available here: https://gist.github.com/keiono/7915968 |
|
Line 77: | Line 79: |
=== Other Languages === Support for other languages can be added as Apps. More languages, including clojure, python, ruby, and groovy, will be supported in future. |
Scripting in Cytoscape 3
Scripting language support is an experimental feature in Cytoscape 3. Java runtime environment comes with built-in scripting language support and Cytoscape uses it to execute tasks written in standard languages such as JavaScript.
This feature is for advanced users. If you just want to automate some basic tasks, such as loading network, you can use Command instead.
Run Cytoscape from Command Line
To use Scripting feature, you need to start Cytoscape from console. In Cytoscape application directory, you can find cytoscape.sh (for Windows, cytoscape.bat). This is a shell script to start Cytoscape from command line.
Once you run Cytoscape from command line, you can use Apache GOGO OSGi Shell. If you type:
help cytoscape:script
the shell displays help message how to use script files in Cytoscape.
JavaScript
JavaScript is supported by default. To run your script, type:
cytoscape:script javascript SCRIPT_FILE_NAME
also, you can pass optional command line arguments.
Sample Script: Create complete graph
// Generate a complete graph // Extract command-line arguments var numberOfNodes = args[0]; if(numberOfNodes == null) numberOfNodes = 10; // Create new network var newNetwork = cyAppAdapter.getCyNetworkFactory().createNetwork(); newNetwork.getRow(newNetwork).set("name", "Complete Graph with " + numberOfNodes + " Nodes"); // Register the new network to Network Manager cyAppAdapter.getCyNetworkManager().addNetwork(newNetwork); // Add nodes var nodes = []; for( i = 0; i < numberOfNodes; i++) { var nodeName = "Node " + i; var node = newNetwork.addNode(); newNetwork.getRow(node).set("name", nodeName); nodes[i] = node; } // Add edges var edgeCount = 0; for( i = 0; i < numberOfNodes; i++) { var source = nodes[i]; for( j = 0; j < numberOfNodes; j++) { var target = nodes[j]; if(newNetwork.containsEdge(source, target) == false && newNetwork.containsEdge(target, source) == false && j != i) { var edge = newNetwork.addEdge(source, target, true); newNetwork.getRow(edge).set("name", "Edge " + edgeCount++); newNetwork.getRow(edge).set("interaction", "interacts_with"); } } }
This script is available here: https://gist.github.com/keiono/7915968
By default, cyAppAdapter object will be injected, just like Simple Apps. You can access basic functions from this object. For more information, please read Cytoscape API document.
Other Languages
Support for other languages can be added as Apps. More languages, including clojure, python, ruby, and groovy, will be supported in future.