diff --git a/org.openbel.cytoscape.navigator/src/org/openbel/cytoscape/navigator/task/AssociateToKamTask.java b/org.openbel.cytoscape.navigator/src/org/openbel/cytoscape/navigator/task/AssociateToKamTask.java index 0eb26b1..934fb25 100644 --- a/org.openbel.cytoscape.navigator/src/org/openbel/cytoscape/navigator/task/AssociateToKamTask.java +++ b/org.openbel.cytoscape.navigator/src/org/openbel/cytoscape/navigator/task/AssociateToKamTask.java @@ -99,6 +99,7 @@ public void run() { int nodeCount = network.getNodeCount(); int[] nodes = network.getNodeIndicesArray(); List wsNodes = new ArrayList(nodeCount); + List cyNodes = new ArrayList<>(nodes.length); for (int idx : nodes) { CyNode node = (CyNode) network.getNode(idx); String nodeId = node.getIdentifier(); @@ -119,6 +120,10 @@ public void run() { continue; } + // track queryable cytoscape node + cyNodes.add(node); + + // build up WebAPI Node objects for query Node wsNode = new Node(); wsNode.setFunction(fx); wsNode.setLabel(nodeId); @@ -133,22 +138,25 @@ public void run() { m.setPercentCompleted(60); + // hard assertion; resolveNodes web operation should be congruent + if (cyNodes.size() != resolvedNodes.size()) + throw new AssertionError("len(cyNodes) != len(resolvedNodes)"); + // update non-null nodes; index to ease resolve edges int nc = resolvedNodes.size(); Map cyNodeResolveMap = new HashMap(nc); - Iterator nit = resolvedNodes.iterator(); - for (int idx : nodes) { - CyNode node = (CyNode) network.getNode(idx); + for (int i = 0; i < nc; i++) { + CyNode node = cyNodes.get(i); + if (node == null) continue; - if (nit.hasNext()) { - KamNode resolved = nit.next(); - if (resolved != null) { - updateNode(node, kamId, resolved); - cyNodeResolveMap.put(node.getIdentifier(), resolved); - } else { - disassociate(node); - } + KamNode resolved = resolvedNodes.get(i); + if (resolved == null) { + disassociate(node); + continue; } + + updateNode(node, kamId, resolved); + cyNodeResolveMap.put(node.getIdentifier(), resolved); } // resolve edges