Author: clopes
Date: 2012-07-11 11:54:19 -0700 (Wed, 11 Jul 2012)
New Revision: 29837
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
Log:
The XGMML reader now creates a column called "__externalEdges" for Cy2 groups,
so the external edges are not lost (see bug #727).
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
2012-07-11 18:41:28 UTC (rev 29836)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
2012-07-11 18:54:19 UTC (rev 29837)
@@ -27,6 +27,7 @@
*/
package org.cytoscape.io.internal.read.xgmml.handler;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -455,26 +456,54 @@
CyNode actualSrc = net.getNode(source.getSUID());
CyNode actualTgt = net.getNode(target.getSUID());
- if (getDocumentVersion() < 3.0 || !isSessionFormat()) {
- if (actualSrc == null || actualTgt == null) {
- // The nodes might have been added to other
sub-networks, but not to the current one.
- // If that is the case, the root network should
have all both nodes,
- // so let's just add the edge to the root
- logger.warn("Cannot add edge \"" + id
- + "\" to the expected
sub-network, because it does not contain the source or target node." +
- " Will try to add the
edge to the root-network instead.");
-
- net = getRootNetwork();
-
- if (actualSrc == null)
- actualSrc =
net.getNode(source.getSUID());
-
- if (actualTgt == null)
- actualTgt =
net.getNode(target.getSUID());
+ List<String> extEdgeIds = null; // For 2.x groups
+
+ if ( (getDocumentVersion() < 3.0 || !isSessionFormat()) &&
(actualSrc == null || actualTgt == null) ) {
+ // The nodes might have been added to other
sub-networks, but not to the current one.
+ // If that is the case, the root network should have
both nodes,
+ // so let's just add the edge to the root.
+ logger.warn("Cannot add edge \"" + id
+ + "\" to the expected
sub-network, because it does not contain the source or target node." +
+ " Will try to add the edge to
the root-network instead.");
+
+ net = getRootNetwork();
+
+ if (actualSrc == null)
+ actualSrc = net.getNode(source.getSUID());
+ if (actualTgt == null)
+ actualTgt = net.getNode(target.getSUID());
+
+ // Does the current subnetwork belong to a 2.x group?
+ if (getDocumentVersion() < 3.0 &&
!compoundNodeStack.isEmpty() && networkStack.size() > 1) {
+ // Get the current compound node
+ final CyNode grNode = compoundNodeStack.peek();
+ // Get the network of that node (the current
one is its network pointer)
+ final CyNetwork grNet =
cache.getNetwork(networkStack.elementAt(networkStack.size() - 2));
+
+ // Check for the group's metadata attribute
+ final CyRow grhRow = grNet.getRow(grNode,
CyNetwork.HIDDEN_ATTRS);
+
+ if (grhRow.isSet("__groupState")) { // It's a
group!
+ // Add extra metadata for external
edges, so that the information is not lost
+ final CyRow rnRow =
getRootNetwork().getRow(grNode, CyNetwork.HIDDEN_ATTRS);
+
+ if
(rnRow.getTable().getColumn("__externalEdges") == null)
+
rnRow.getTable().createListColumn("__externalEdges", String.class, false);
+
+ extEdgeIds =
rnRow.getList("__externalEdges", String.class);
+
+ if (extEdgeIds == null) {
+ extEdgeIds = new
ArrayList<String>();
+ rnRow.set("__externalEdges",
extEdgeIds);
+ }
+ }
}
}
edge = net.addEdge(actualSrc, actualTgt, directed);
+
+ if (extEdgeIds != null)
+ extEdgeIds.add(id.toString());
}
// Add to internal cache:
Modified:
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
2012-07-11 18:41:28 UTC (rev 29836)
+++
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
2012-07-11 18:54:19 UTC (rev 29837)
@@ -26,6 +26,7 @@
import org.cytoscape.model.CyTableManager;
import org.cytoscape.model.NetworkTestSupport;
import org.cytoscape.model.TableTestSupport;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
import org.cytoscape.model.subnetwork.CyRootNetworkManager;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.CyNetworkViewFactory;
@@ -115,29 +116,7 @@
// The group network should not be registered, so the network
list must contain only the base network
assertEquals(1, reader.getNetworks().length);
CyNetwork net = checkSingleNetwork(views, 4, 2);
-
- // Test 2.x group parsed as network pointer
- CyNode gn = null;
- int npCount = 0;
-
- for (CyNode n : net.getNodeList()) {
- if (net.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet("__groupState")) {
- gn = n;
- if (++npCount > 1) fail("There should be only
one group node!");
- } else { // The other nodes have no network pointer!
- assertNull(n.getNetworkPointer());
- }
- }
-
- assertNotNull("The group node cannot be found", gn);
- CyNetwork np = gn.getNetworkPointer();
- assertNotNull(np);
- assertEquals(2, np.getNodeCount());
- assertEquals(1, np.getEdgeCount());
-
- // Check if the nested graph's attribute was imported to the
network pointer
- CyRow grNetrow = np.getRow(np);
- assertEquals("Lorem Ipsum", grNetrow.get("gr_att_1",
String.class));
+ check2xGroupMetadata(net);
}
@Test
@@ -146,29 +125,7 @@
// The group network should not be registered, so the network
list must contain only the base network
assertEquals(1, reader.getNetworks().length);
CyNetwork net = checkSingleNetwork(views, 2, 1);
-
- // Test 2.x group parsed as network pointer
- CyNode gn = null;
- int npCount = 0;
-
- for (CyNode n : net.getNodeList()) {
- if (net.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet("__groupState")) {
- gn = n;
- if (++npCount > 1) fail("There should be only
one group node!");
- } else { // The other nodes have no network pointer!
- assertNull(n.getNetworkPointer());
- }
- }
-
- assertNotNull("The group node cannot be found", gn);
- CyNetwork np = gn.getNetworkPointer();
- assertNotNull(np);
- assertEquals(2, np.getNodeCount());
- assertEquals(1, np.getEdgeCount());
-
- // Check if the nested graph's attribute was imported to the
network pointer
- CyRow grNetrow = np.getRow(np);
- assertEquals("Lorem Ipsum", grNetrow.get("gr_att_1",
String.class));
+ check2xGroupMetadata(net);
}
@Test
@@ -243,6 +200,40 @@
assertEquals("SansSerif,bold,12",
GenericXGMMLReader.convertOldFontValue("SansSerif,bold,12"));
}
+ private void check2xGroupMetadata(final CyNetwork net) {
+ // Test 2.x group parsed as network pointer
+ CyNode gn = null;
+ int npCount = 0;
+
+ for (CyNode n : net.getNodeList()) {
+ if (net.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet("__groupState")) {
+ gn = n;
+ if (++npCount > 1) fail("There should be only
one group node!");
+ } else { // The other nodes have no network pointer!
+ assertNull(n.getNetworkPointer());
+ }
+ }
+
+ assertNotNull("The group node cannot be found", gn);
+ CyNetwork np = gn.getNetworkPointer();
+ assertNotNull(np);
+ assertEquals(2, np.getNodeCount());
+ assertEquals(1, np.getEdgeCount());
+
+ // Check if the nested graph's attribute was imported to the
network pointer
+ CyRow grNetrow = np.getRow(np);
+ assertEquals("Lorem Ipsum", grNetrow.get("gr_att_1",
String.class));
+
+ // Check external edges metadata (must be added by the reader!)
+ CyRootNetwork rootNet = rootNetworkMgr.getRootNetwork(np);
+ CyRow rnRow = rootNet.getRow(gn, CyNetwork.HIDDEN_ATTRS);
+ List<String> extEdgeIds = rnRow.getList("__externalEdges",
String.class);
+
+ assertNotNull(extEdgeIds);
+ assertEquals(1, extEdgeIds.size());
+ assertEquals("node1 (DirectedEdge) node2", extEdgeIds.get(0));
+ }
+
private List<CyNetworkView> getViews(String file) throws Exception {
File f = new File("./src/test/resources/testData/xgmml/" +
file);
reader = new GenericXGMMLReader(new FileInputStream(f),
viewFactory, netFactory,
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.