Author: clopes
Date: 2012-08-10 10:41:41 -0700 (Fri, 10 Aug 2012)
New Revision: 30157
Added:
core3/impl/trunk/io-impl/impl/src/test/resources/testData/xgmml/simple.xgmml
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
Log:
Fixes #1347 (Cy2 attributes imported as local table CyColumns):
Custom node/edge attributes are created in the shared tables, but network
attributes are always created in the LOCAL network table.
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
2012-08-10 15:09:13 UTC (rev 30156)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
2012-08-10 17:41:41 UTC (rev 30157)
@@ -178,7 +178,6 @@
final String hiddenStr = atts.getValue("cy:hidden");
final boolean isHidden = hiddenStr != null ?
Boolean.parseBoolean(hiddenStr) : false;
- final String tableName = isHidden ? CyNetwork.HIDDEN_ATTRS :
CyNetwork.DEFAULT_ATTRS;
final CyIdentifiable curElement = manager.getCurrentElement();
CyNetwork curNet = manager.getCurrentNetwork();
@@ -193,12 +192,27 @@
curNet = manager.getRootNetwork();
}
- CyRow row = curNet.getRow(curElement, tableName);
+ CyRow row = null;
+
+ if (isHidden) {
+ row = curNet.getRow(curElement, CyNetwork.HIDDEN_ATTRS);
+ } else {
+ // TODO: What are the rules here?
+ // Node/edge attributes are always shared, except
"selected"?
+ // Network name must be local, right? What about other
network attributes?
+ if (CyNetwork.SELECTED.equals(name) || (curElement
instanceof CyNetwork))
+ row = curNet.getRow(curElement,
CyNetwork.LOCAL_ATTRS);
+ else
+ row = curNet.getRow(curElement,
CyNetwork.DEFAULT_ATTRS); // Will be created in the shared table
+ }
+
CyTable table = row.getTable();
CyColumn column = table.getColumn(name);
if (column != null) {
// Check if it's a virtual column
+ // It's necessary because the source row may not exist yet,
which would throw an exception
+ // when the value is set. Doing this forces the creation of the
source row.
final VirtualColumnInfo info = column.getVirtualColumnInfo();
if (info.isVirtual()) {
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-08-10 15:09:13 UTC (rev 30156)
+++
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
2012-08-10 17:41:41 UTC (rev 30157)
@@ -2,15 +2,11 @@
import static org.cytoscape.model.CyNetwork.DEFAULT_ATTRS;
import static org.cytoscape.model.CyNetwork.HIDDEN_ATTRS;
+import static org.cytoscape.model.CyNetwork.LOCAL_ATTRS;
import static org.cytoscape.model.CyNetwork.NAME;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.cytoscape.model.subnetwork.CyRootNetwork.SHARED_ATTRS;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -105,6 +101,34 @@
}
@Test
+ public void testSharedAndLocalAttributes() throws Exception {
+ List<CyNetworkView> views = getViews("simple.xgmml");
+ CyNetwork net = checkSingleNetwork(views, 1, 1);
+ assertCustomColumnsAreMutable(net);
+
+ CyTable defNodeTbl = net.getDefaultNodeTable();
+ CyTable defEdgeTbl = net.getDefaultEdgeTable();
+ CyTable defNetTbl = net.getDefaultNetworkTable();
+
+ // Assert all custom Node/Edge columns are shared
+
assertTrue(defNodeTbl.getColumn("node_att_1").getVirtualColumnInfo().isVirtual());
+
assertTrue(defNodeTbl.getColumn("node_att_2").getVirtualColumnInfo().isVirtual());
+
assertTrue(defEdgeTbl.getColumn("edge_att_1").getVirtualColumnInfo().isVirtual());
+
assertTrue(defEdgeTbl.getColumn("edge_att_2").getVirtualColumnInfo().isVirtual());
+ // Assert all custom network columns are local
+
assertFalse(defNetTbl.getColumn("net_att_1").getVirtualColumnInfo().isVirtual());
+
assertFalse(defNetTbl.getColumn("net_att_2").getVirtualColumnInfo().isVirtual());
+ // Assert mandatory local attributes
+
assertFalse(defNodeTbl.getColumn(CyNetwork.SELECTED).getVirtualColumnInfo().isVirtual());
+
assertFalse(defNodeTbl.getColumn(CyNetwork.NAME).getVirtualColumnInfo().isVirtual());
+
assertFalse(defEdgeTbl.getColumn(CyNetwork.SELECTED).getVirtualColumnInfo().isVirtual());
+
assertFalse(defEdgeTbl.getColumn(CyNetwork.NAME).getVirtualColumnInfo().isVirtual());
+
assertFalse(defEdgeTbl.getColumn(CyEdge.INTERACTION).getVirtualColumnInfo().isVirtual());
+
assertFalse(defNetTbl.getColumn(CyNetwork.NAME).getVirtualColumnInfo().isVirtual());
+
assertFalse(defNetTbl.getColumn(CyNetwork.SELECTED).getVirtualColumnInfo().isVirtual());
+ }
+
+ @Test
public void testIgnoreEmptyListAtt() throws Exception {
List<CyNetworkView> views = getViews("listAtt.xgmml");
CyNetwork net = checkSingleNetwork(views, 0, 0);
@@ -201,7 +225,10 @@
// 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);
- check2xGroupMetadata(net);
+ CyNode grNode = check2xGroupMetadata(net);
+
assertCustomColumnsAreMutable(rootNetworkMgr.getRootNetwork(net));
+ assertCustomColumnsAreMutable(net);
+ assertCustomColumnsAreMutable(grNode.getNetworkPointer());
}
@Test
@@ -217,6 +244,7 @@
assertNotNull(grNet.getRow(n,
HIDDEN_ATTRS).get("__metanodeHintX", Double.class));
assertNotNull(grNet.getRow(n,
HIDDEN_ATTRS).get("__metanodeHintY", Double.class));
}
+
assertCustomColumnsAreMutable(rootNetworkMgr.getRootNetwork(net));
assertCustomColumnsAreMutable(net);
assertCustomColumnsAreMutable(grNet);
}
@@ -295,20 +323,32 @@
private void assertCustomColumnsAreMutable(CyNetwork net) {
// User or non-default columns should be immutable
- CyTable[] tables = new CyTable[] {
- net.getTable(CyNetwork.class, DEFAULT_ATTRS),
- net.getTable(CyNetwork.class, HIDDEN_ATTRS),
- net.getTable(CyNode.class, DEFAULT_ATTRS),
- net.getTable(CyNode.class, HIDDEN_ATTRS),
- net.getTable(CyEdge.class, DEFAULT_ATTRS),
- net.getTable(CyEdge.class, HIDDEN_ATTRS)
- };
+ List<CyTable> tables = new ArrayList<CyTable>();
+ tables.add(net.getTable(CyNetwork.class, LOCAL_ATTRS));
+ tables.add(net.getTable(CyNetwork.class, HIDDEN_ATTRS));
+ tables.add(net.getTable(CyNetwork.class, DEFAULT_ATTRS));
+ tables.add(net.getTable(CyNode.class, LOCAL_ATTRS));
+ tables.add(net.getTable(CyNode.class, HIDDEN_ATTRS));
+ tables.add(net.getTable(CyNode.class, DEFAULT_ATTRS));
+ tables.add(net.getTable(CyEdge.class, LOCAL_ATTRS));
+ tables.add(net.getTable(CyEdge.class, HIDDEN_ATTRS));
+ tables.add(net.getTable(CyEdge.class, DEFAULT_ATTRS));
+
+ if (net instanceof CyRootNetwork) {
+ tables.add(net.getTable(CyNetwork.class, SHARED_ATTRS));
+ tables.add(net.getTable(CyNode.class, SHARED_ATTRS));
+ tables.add(net.getTable(CyEdge.class, SHARED_ATTRS));
+ }
+
for (CyTable t : tables) {
for (CyColumn c : t.getColumns()) {
String name = c.getName();
- if (!name.equals(CyNetwork.SUID) &&
!name.equals(NAME) &&
- !name.equals(CyNetwork.SELECTED) &&
!name.equals(CyEdge.INTERACTION) &&
- !name.equals(CyRootNetwork.SHARED_NAME)
&& !name.equals(CyRootNetwork.SHARED_INTERACTION)) {
+ if (!name.equals(CyNetwork.SUID)
+ && !name.equals(NAME)
+ &&
!name.equals(CyNetwork.SELECTED)
+ &&
!name.equals(CyEdge.INTERACTION)
+ &&
!name.equals(CyRootNetwork.SHARED_NAME)
+ &&
!name.equals(CyRootNetwork.SHARED_INTERACTION)) {
assertFalse("Column " + c.getName() + "
should NOT be immutable", c.isImmutable());
}
}
Added:
core3/impl/trunk/io-impl/impl/src/test/resources/testData/xgmml/simple.xgmml
===================================================================
---
core3/impl/trunk/io-impl/impl/src/test/resources/testData/xgmml/simple.xgmml
(rev 0)
+++
core3/impl/trunk/io-impl/impl/src/test/resources/testData/xgmml/simple.xgmml
2012-08-10 17:41:41 UTC (rev 30157)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<graph label="Network A" xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:cy="http://www.cytoscape.org" xmlns="http://www.cs.rpi.edu/XGMML"
+ directed="1">
+
+ <att type="boolean" name="net_att_1" value="1" />
+ <att type="list" name="net_att_2">
+ <att type="string" value="a" />
+ </att>
+
+ <node label="node1" id="-1">
+ <att type="string" name="node_att_1" value="node 1" />
+ <att type="list" name="node_att_2">
+ <att type="integer" value="1" />
+ </att>
+ </node>
+ <edge label="node1 (DirectedEdge) node1" source="-1" target="-1">
+ <att type="real" name="edge_att_1" value="2.5" />
+ <att type="list" name="edge_att_2">
+ <att type="string" value="a" />
+ <att type="string" value="b" />
+ </att>
+ </edge>
+</graph>
\ No newline at end of file
--
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.