Some tips here were extracted from the cytoscape-discuss list.
Getting information about neighbors
If you are working with a undirected network, you can use the neighborsList() method from GraphPerspective.
For directed networks, you can use GraphPerspective.getAdjacentEdgeIndicesArray. Here an example (as used in the ShortestPathPlugin).
First, create some methods to set if your network is directed or not:
1 public void setUndirected() {
2 undirected = true;
3 incoming = true;
4 outcoming = true;
5 }
6
7 public void setDirected() {
8 undirected = false;
9 incoming = false;
10 outcoming = true;
11 }
12
Then, you can call them from your main code:
1 if (directed) {
2 setDirected();
3 }
4 else {
5 setUndirected();
6 }
7
Now, all you need to get the neighbors is:
(obs: nodeIndex is the node index of the node you want to find the neighbors)
1 int[] adjEdges = network.getAdjacentEdgeIndicesArray(nodeIndex,undirected,incoming,outcoming);
2 int[] adjNodes = new int[adjEdges.length];
3 for (int i = 0; i < adjNodes.length; i++) {
4 int node = network.getEdgeSourceIndex(adjEdges[i]);
5 if (node == nodeIndex)
6 node = network.getEdgeTargetIndex(adjEdges[i]);
7 adjNodes[i] = node;
8 }
9
Getting information about inner nodes in a MetaNode
(from a post from Iliana):
For every node in a CyNetwork, there is a method called getGraphPerspective(). This GraphPerspective is the graph inside the node (if any).
1 GraphPerspective insideGraph = metaNode.getGraphPerspective();
2 if(insideGraph != null){
3 int numNodes = insideGraph.getNodeCount();
4
5 }
6