Author: scooter
Date: 2012-08-29 23:17:33 -0700 (Wed, 29 Aug 2012)
New Revision: 30293
Removed:
core3/impl/trunk/group-session-restore-shim/
Modified:
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/SessionXGMMLNetworkWriter.java
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/write/xgmml/AbstractXGMMLWriterTest.java
Log:
Changes to support group serialization with standalone XGMML
Modified:
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
===================================================================
---
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
2012-08-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupImpl.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -63,7 +63,6 @@
class CyGroupImpl implements CyGroup {
final private static String CHILDREN_ATTR = "NumChildren";
final private static String DESCENDENTS_ATTR = "NumDescendents";
- final private static String GROUP_COLLAPSED_ATTR = "__groupCollapsed";
final private static String ISMETA_EDGE_ATTR = "__isMetaEdge";
final private CyEventHelper cyEventHelper;
@@ -74,7 +73,7 @@
private Set<CyEdge> metaEdges;
private CyRootNetwork rootNetwork = null;
private Set<CyNetwork> networkSet = null;
- private Set<CyNetwork> collapseSet = null;
+ private Set<Long> collapseSet = null;
private boolean nodeProvided = false; // We'll need this when we
destroy ourselves
CyGroupImpl(final CyEventHelper eventHelper,
@@ -94,7 +93,7 @@
this.externalEdges = new HashSet<CyEdge>();
this.metaEdges = new HashSet<CyEdge>();
this.networkSet = new HashSet<CyNetwork>();
- this.collapseSet = new HashSet<CyNetwork>();
+ this.collapseSet = new HashSet<Long>();
networkSet.add(rootNetwork);
networkSet.add(network);
@@ -146,9 +145,9 @@
CySubNetwork groupNet = np;
// See if we're already collapsed
- if (getGroupCollapsedAttribute(network)) {
- // Yes, reflect it...
- collapseSet.add(network);
+ if (network.containsNode(groupNode)) {
+ // Yes, note it
+ collapseSet.add(network.getSUID());
}
} else {
// Create the subnetwork
@@ -161,7 +160,6 @@
// Initialize our attributes
updateCountAttributes(rootNetwork);
- setGroupCollapsedAttribute(network, false);
}
/**
@@ -254,7 +252,7 @@
}
}
updateMetaEdges(false);
- for (CyNetwork net: collapseSet) {
+ for (CyNetwork net: networkSet) {
updateCountAttributes(net);
}
cyEventHelper.fireEvent(new
GroupNodesAddedEvent(CyGroupImpl.this, nodes));
@@ -298,7 +296,7 @@
getGroupNetwork().removeEdges(netEdges);
getGroupNetwork().removeNodes(nodes);
updateMetaEdges(false);
- for (CyNetwork net: collapseSet) {
+ for (CyNetwork net: networkSet) {
updateCountAttributes(net);
}
cyEventHelper.fireEvent(new
GroupNodesRemovedEvent(CyGroupImpl.this, nodes));
@@ -416,10 +414,9 @@
subnet.addEdge(e);
}
- collapseSet.add(net);
+ collapseSet.add(net.getSUID());
// Update attributes?
- setGroupCollapsedAttribute(net, true);
updateCountAttributes(net);
// OK, all done
@@ -464,11 +461,8 @@
}
}
- collapseSet.remove(net);
+ collapseSet.remove(net.getSUID());
- // Update attributes
- setGroupCollapsedAttribute(net, false);
-
// Finish up
cyEventHelper.fireEvent(new
GroupCollapsedEvent(CyGroupImpl.this, net, false));
}
@@ -478,7 +472,7 @@
*/
@Override
public boolean isCollapsed(CyNetwork net) {
- return collapseSet.contains(net);
+ return collapseSet.contains(net.getSUID());
}
/**
@@ -721,48 +715,6 @@
return;
}
- /**
- * Set the state attribute for this group. The problem is that a group
might be in
- * different states in different networks, so this is a list of the
form:
- * [network1:state,network2:state,...]
- */
- private void setGroupCollapsedAttribute(CyNetwork net, boolean
collapsed) {
- String netName =
net.getDefaultNetworkTable().getRow(net.getSUID()).get(CyNetwork.NAME,
String.class);
- if (netName == null) netName = "(null)"; // Handle the unnamed
network
- CyRow groupRow = rootNetwork.getRow(groupNode,
CyNetwork.HIDDEN_ATTRS);
- if (groupRow == null) return;
-
- CyTable hiddenTable = groupRow.getTable();
-
- CyColumn stateColumn =
hiddenTable.getColumn(GROUP_COLLAPSED_ATTR);
-
- List<String> newList = new ArrayList<String>();
- if (stateColumn == null) {
- hiddenTable.createColumn(GROUP_COLLAPSED_ATTR,
Boolean.class, false, Boolean.FALSE);
- }
-
- groupRow.set(GROUP_COLLAPSED_ATTR, collapsed);
- return;
- }
-
- // This is public so we can call it from our session loaded events
- public boolean getGroupCollapsedAttribute(CyNetwork net) {
- String netName =
net.getDefaultNetworkTable().getRow(net.getSUID()).get(net.NAME, String.class);
- if (netName == null) netName = "(null)";
- CyRow groupRow = rootNetwork.getRow(groupNode,
CyNetwork.HIDDEN_ATTRS);
- if (groupRow == null) return false;
-
- CyTable hiddenTable = groupRow.getTable();
-
- CyColumn stateColumn =
hiddenTable.getColumn(GROUP_COLLAPSED_ATTR);
-
- if (stateColumn == null) {
- return false;
- }
-
- return groupRow.get(GROUP_COLLAPSED_ATTR, Boolean.class);
- }
-
public void updateCountAttributes(CyNetwork net) {
CyTable nodeTable = net.getDefaultNodeTable();
CyColumn childrenColumn = nodeTable.getColumn(CHILDREN_ATTR);
@@ -792,5 +744,4 @@
}
groupRow.set(DESCENDENTS_ATTR, nDescendents);
}
-
}
Modified:
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
===================================================================
---
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
2012-08-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/group-impl/src/main/java/org/cytoscape/group/internal/CyGroupManagerImpl.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -30,8 +30,10 @@
package org.cytoscape.group.internal;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.cytoscape.event.CyEventHelper;
@@ -42,6 +44,8 @@
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,12 +56,15 @@
private final CyEventHelper cyEventHelper;
private Set<CyGroup> groupSet;
+ private Map<CyRootNetwork, Set<CyGroup>> rootMap;
+ private static final String GROUP_LIST_ATTRIBUTE = "__groupList.SUID";
/**
*
* @param cyEventHelper
*/
public CyGroupManagerImpl(final CyEventHelper cyEventHelper) {
this.groupSet = new HashSet<CyGroup>();
+ this.rootMap = new HashMap<CyRootNetwork, Set<CyGroup>>();
this.cyEventHelper = cyEventHelper;
}
@@ -75,6 +82,8 @@
public synchronized void addGroup(final CyGroup group) {
if (!groupSet.contains(group)) {
groupSet.add(group);
+ addGroupToRootMap(group);
+ // updateGroupAttribute(group);
cyEventHelper.fireEvent(new
GroupAddedEvent(CyGroupManagerImpl.this, group));
}
}
@@ -84,6 +93,8 @@
for (CyGroup group: groups) {
if (!groupSet.contains(group)) {
groupSet.add(group);
+ addGroupToRootMap(group);
+ // updateGroupAttribute(group);
}
}
// Fire GroupsAddedEvent?
@@ -140,7 +151,10 @@
cyEventHelper.fireEvent(new
GroupAboutToBeDestroyedEvent(CyGroupManagerImpl.this, group));
((CyGroupImpl)group).destroyGroup();
+ if (rootMap.containsKey(group.getRootNetwork()))
+ rootMap.get(group.getRootNetwork()).remove(group);
groupSet.remove(group);
+ // updateGroupAttribute(group);
}
@Override
@@ -148,4 +162,49 @@
this.groupSet = new HashSet<CyGroup>();
}
+ public Set<CyGroup> getAllGroups() {
+ return groupSet;
+ }
+
+ public Set<CyGroup> getGroupSet(CyRootNetwork root) {
+ if (rootMap.containsKey(root))
+ return rootMap.get(root);
+ return null;
+ }
+
+ /**
+ * Get the SUIDs for all group nodes in this root network. This is
public so that
+ * we can call it from our network added listener.
+ */
+ public List<Long> getGroupAttribute(CyRootNetwork rootNet) {
+ CyRow rhRow = rootNet.getRow(rootNet, CyNetwork.HIDDEN_ATTRS);
// Get the network row
+ if (rhRow.getTable().getColumn(GROUP_LIST_ATTRIBUTE) == null) {
+ return null;
+ }
+ return rhRow.getList(GROUP_LIST_ATTRIBUTE, Long.class);
+ }
+
+ private void addGroupToRootMap(CyGroup group) {
+ if (rootMap.containsKey(group.getRootNetwork()))
+ rootMap.get(group.getRootNetwork()).add(group);
+ else {
+ Set<CyGroup>groupNetSet = new HashSet<CyGroup>();
+ groupNetSet.add(group);
+ rootMap.put(group.getRootNetwork(),groupNetSet);
+ }
+ }
+
+ private void updateGroupAttribute(CyGroup group) {
+ CyRootNetwork rootNet = group.getRootNetwork();
+ CyRow rhRow = rootNet.getRow(rootNet, CyNetwork.HIDDEN_ATTRS);
// Get the network row
+ if (rhRow.getTable().getColumn(GROUP_LIST_ATTRIBUTE) == null) {
+ rhRow.getTable().createListColumn(GROUP_LIST_ATTRIBUTE,
Long.class, false);
+ }
+
+ List<Long> groupSUIDs = new ArrayList<Long>();
+ for (CyGroup g: getGroupSet(rootNet)) {
+ groupSUIDs.add(g.getGroupNode().getSUID());
+ }
+ rhRow.set(GROUP_LIST_ATTRIBUTE, groupSUIDs);
+ }
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
2012-08-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -1,6 +1,7 @@
package org.cytoscape.io.internal.util;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -24,7 +25,8 @@
// 3.x group attributes
private final String EXTERNAL_EDGE_ATTRIBUTE="__externalEdges.SUID";
- private final String GROUP_COLLAPSED_ATTRIBUTE="__groupCollapsed";
+ private final String GROUP_COLLAPSED_ATTRIBUTE="__groupCollapsed.SUID";
+ private final String GROUP_ATTRIBUTE="__isGroup";
// 2.x group attributes
private final String GROUP_STATE_ATTRIBUTE="__groupState";
private final String GROUP_ISLOCAL_ATTRIBUTE="__groupIsLocal";
@@ -61,31 +63,53 @@
// For each group, save the list of external edges
for (CyGroup group: groupSet) {
- // Get the group node
- CyNode groupNode = group.getGroupNode();
+ updateExternalEdgeAttribute(group);
+ updateCollapsedGroupsAttribute(group);
+ updateGroupAttribute(net, group);
+ }
+ }
+ }
- // Get the list of external edges
- Set<CyEdge> externalEdges =
group.getExternalEdgeList();
+ public List<CyNode> getExpandedGroups(final CyNetwork network) {
+ // Get all of our groups in this network
+ Set<CyGroup> groupSet = groupMgr.getGroupSet(network);
- // Save the SUIDs for each edge
- List<Long> externalEdgeSUIDs = new
ArrayList<Long>();
- for (CyEdge edge: externalEdges) {
- externalEdgeSUIDs.add(edge.getSUID());
+ // For each group see if it's expanded, but present
+ List<CyNode> groupNodes = new ArrayList<CyNode>();
+ for (CyGroup group: groupSet) {
+ if (!group.isCollapsed(network)) {
+ if (network.containsNode(group.getGroupNode()))
{
+ // We're expanded, but present in the
network. Remove ourselves
+ groupNodes.add(group.getGroupNode());
}
+ }
+ }
+ return groupNodes;
+ }
- // We need to use the sub network to get the
row because the group might be expanded
- final CyNetwork netPointer =
groupNode.getNetworkPointer();
- final CyRow snRow =
netPointer.getRow(netPointer, CyNetwork.HIDDEN_ATTRS);
+ public List<CyEdge> getGroupNodeEdges(final CyNetwork network) {
+ CyRootNetwork rootNetwork =
((CySubNetwork)network).getRootNetwork();
+ // Don't need to worry about this for collapsed groups
+ List<CyNode> groupNodes = getExpandedGroups(network);
+ List<CyEdge> groupNodeEdges = new ArrayList<CyEdge>();
+ for (CyNode groupNode : groupNodes) {
+
groupNodeEdges.addAll(rootNetwork.getAdjacentEdgeList(groupNode,
CyEdge.Type.ANY));
+ }
+ return groupNodeEdges;
+ }
- // Make sure our column exists
- CyTable groupNetTable = snRow.getTable();
- if
(groupNetTable.getColumn(EXTERNAL_EDGE_ATTRIBUTE) == null) {
-
groupNetTable.createListColumn(EXTERNAL_EDGE_ATTRIBUTE, Long.class, false);
- }
+ public List<CyEdge> getExternalEdges(final CyNetwork network) {
+ // Get all of our groups in this network
+ Set<CyGroup> groupSet = groupMgr.getGroupSet(network);
- snRow.set(EXTERNAL_EDGE_ATTRIBUTE,
externalEdgeSUIDs);
+ List<CyEdge> externalEdges = new ArrayList<CyEdge>();
+ for (CyGroup group: groupSet) {
+ // Don't need to worry about this for expanded groups
+ if (group.isCollapsed(network)) {
+
externalEdges.addAll(group.getExternalEdgeList());
}
}
+ return externalEdges;
}
/**
@@ -116,7 +140,7 @@
final CyRow hnRow = net.getRow(n,
CyNetwork.HIDDEN_ATTRS);
final CyRow snRow = netPointer.getRow(netPointer,
CyNetwork.HIDDEN_ATTRS);
if (!dnRow.isSet(GROUP_STATE_ATTRIBUTE) &&
!hnRow.isSet(GROUP_STATE_ATTRIBUTE)
- && !snRow.isSet(GROUP_COLLAPSED_ATTRIBUTE))
+ && !hnRow.isSet(GROUP_ATTRIBUTE))
return;
boolean collapsed = false;
@@ -130,24 +154,41 @@
Integer grState =
dnRow.get(GROUP_STATE_ATTRIBUTE, Integer.class); // 2.x metadata
cy2group = true;
if (grState.intValue() == 2) collapsed = true;
- }
-
- // Check to make sure the column exists
- if
(snRow.getTable().getColumn(GROUP_COLLAPSED_ATTRIBUTE) == null) {
- CyTable snTable = snRow.getTable();
-
snTable.createListColumn(GROUP_COLLAPSED_ATTRIBUTE, String.class, false);
+ } else {
+ List<Long> collapsedList =
snRow.getList(GROUP_COLLAPSED_ATTRIBUTE, Long.class);
+ if (collapsedList != null) {
+ // Are we collapsed in this network?
+ for (Long suid: collapsedList) {
+ if (suid.equals(net.getSUID()))
{
+ collapsed = true;
+ break;
+ }
+ }
+ }
}
- // If we're a Cy2 import, create the Cy3 structure
- if (cy2group) {
- String netName = net.getRow(net).get(CyNetwork.NAME,
String.class);
- if (netName == null) netName = "(null)"; // Handle the
unnamed network
+ // If we're not collapsed, remove the group node from
the network before
+ // we create the group
+ if (!collapsed) {
+ net.removeNodes(Collections.singletonList(n));
- List<String> list = new ArrayList<String>();
- list.add(netName+":"+collapsed);
- snRow.set(GROUP_COLLAPSED_ATTRIBUTE, list);
+ // Add our internal edges into the network (if
they aren't already)
+ for (CyEdge edge: netPointer.getEdgeList()) {
+ if (net.containsEdge(edge))
+ continue;
+ net.addEdge(edge);
+ }
+
+ // If we're a cy2 group, remember our state
+ if (cy2group) {
+ CyTable hnTable =
rootNet.getTable(CyNode.class, CyNetwork.HIDDEN_ATTRS);
+ if
(hnTable.getColumn(GROUP_STATE_ATTRIBUTE) == null) {
+
hnTable.createColumn(GROUP_STATE_ATTRIBUTE, Integer.class, false);
+ }
+
hnTable.getRow(n.getSUID()).set(GROUP_STATE_ATTRIBUTE, 1);
+ }
}
-
+
// Create the group
final CyGroup group = groupFactory.createGroup(net, n,
true);
@@ -212,6 +253,68 @@
updateGroupNodeLocation(view,
group.getGroupNode());
}
}
+
+ private void updateExternalEdgeAttribute(final CyGroup group) {
+ // Get the group node
+ CyNode groupNode = group.getGroupNode();
+
+ // Get the list of external edges
+ Set<CyEdge> externalEdges = group.getExternalEdgeList();
+
+ // Save the SUIDs for each edge
+ List<Long> externalEdgeSUIDs = new ArrayList<Long>();
+ for (CyEdge edge: externalEdges) {
+ externalEdgeSUIDs.add(edge.getSUID());
+ }
+
+ // We need to use the sub network to get the row because the
group might be expanded
+ final CyNetwork netPointer = groupNode.getNetworkPointer();
+ final CyRow snRow = netPointer.getRow(netPointer,
CyNetwork.HIDDEN_ATTRS);
+
+ // Make sure our column exists
+ CyTable groupNetTable = snRow.getTable();
+ if (groupNetTable.getColumn(EXTERNAL_EDGE_ATTRIBUTE) == null) {
+ groupNetTable.createListColumn(EXTERNAL_EDGE_ATTRIBUTE,
Long.class, false);
+ }
+
+ snRow.set(EXTERNAL_EDGE_ATTRIBUTE, externalEdgeSUIDs);
+ return;
+ }
+
+ private void updateCollapsedGroupsAttribute(final CyGroup group) {
+ // Get our subnetwork
+ CySubNetwork np =
(CySubNetwork)group.getGroupNode().getNetworkPointer();
+ CyTable hiddenTable = np.getTable(CyNetwork.class,
CyNetwork.HIDDEN_ATTRS);
+ CyRow netRow = hiddenTable.getRow(np.getSUID()); // We use our
embedded network table for this
+ CyColumn stateColumn =
hiddenTable.getColumn(GROUP_COLLAPSED_ATTRIBUTE);
+ if (stateColumn == null)
+ hiddenTable.createListColumn(GROUP_COLLAPSED_ATTRIBUTE,
Long.class, true);
+
+ List<Long> collapsedList = new ArrayList<Long>();
+ for (CyNetwork net: group.getNetworkSet()) {
+ if(group.isCollapsed(net))
+ collapsedList.add(net.getSUID());
+ }
+ netRow.set(GROUP_COLLAPSED_ATTRIBUTE, collapsedList);
+ return;
+ }
+
+ private void updateGroupAttribute(final CyNetwork net, final CyGroup
group) {
+ CyNode node = group.getGroupNode();
+
+ // Expanded groups won't show in the network. If it's not
there, we need
+ // to add it so that it will get serialized
+ if (!net.containsNode(node)) {
+ // Node not in this network. Add it and mark it....
+ CySubNetwork subNet = (CySubNetwork)net;
+ subNet.addNode(node); // Temporarily add this to the
network so we can serialize it
+ }
+
+ CyTable hiddenTable = net.getTable(CyNode.class,
CyNetwork.HIDDEN_ATTRS);
+ if (hiddenTable.getColumn(GROUP_ATTRIBUTE) == null)
+ hiddenTable.createColumn(GROUP_ATTRIBUTE,
Boolean.class, false);
+ hiddenTable.getRow(node.getSUID()).set(GROUP_ATTRIBUTE,
Boolean.TRUE);
+ }
private void copyTables(CyNetwork netPointer, CyNetwork net, CyNode
groupNode) {
// Copy the tables from the subnetwork
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
2012-08-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -390,11 +390,34 @@
* @throws IOException
*/
protected void writeNodes() throws IOException {
+ List<CyNode> pointerNodes = new ArrayList<CyNode>();
+
for (CyNode node : network.getNodeList()) {
+ // Save all of the nodes with network pointers until
last
+ // this allows us to have embedded networks...
+ if (node.getNetworkPointer() != null) {
+ pointerNodes.add(node);
+ continue;
+ }
+
// Only if not already written inside a nested graph
if (!writtenNodeMap.containsKey(node))
writeNode(network, node);
}
+
+ for (CyNode node : pointerNodes) {
+ if (!writtenNodeMap.containsKey(node))
+ writeNode(network, node);
+ }
+
+ // Now, output nodes for expanded groups. We'll clean
+ // these up on import...
+ if (groupUtil != null) {
+ for (CyNode node :
groupUtil.getExpandedGroups(network)) {
+ if (!writtenNodeMap.containsKey(node))
+ writeNode(network, node);
+ }
+ }
}
/**
@@ -406,7 +429,23 @@
// Only if not already written inside a nested graph
if (!writtenEdgeMap.containsKey(edge))
writeEdge(network, edge);
- }
+ }
+
+ // Now, output hidden edges groups.
+ // For collapsed groups, we need to output external edges,
+ // for expanded groups, we need to output edges to the group
node
+ if (groupUtil != null) {
+ // Handle edges to the group node
+ for (CyEdge edge :
groupUtil.getGroupNodeEdges(network)) {
+ if (!writtenEdgeMap.containsKey(edge))
+ writeEdge(network, edge);
+ }
+ // Now handle external edges
+ for (CyEdge edge : groupUtil.getExternalEdges(network))
{
+ if (!writtenEdgeMap.containsKey(edge))
+ writeEdge(network, edge);
+ }
+ }
}
/**
@@ -482,8 +521,8 @@
depth++;
// Write the edge attributes
- writeAttributes(net.getRow(edge));
- writeAttributes(net.getRow(edge,
CyNetwork.HIDDEN_ATTRS));
+ writeAttributes(getRowFromNetOrRoot(net, edge, null));
+ writeAttributes(getRowFromNetOrRoot(net, edge,
CyNetwork.HIDDEN_ATTRS));
// Write the edge graphics
if (networkView != null)
@@ -847,7 +886,7 @@
}
protected String getLabel(CyNetwork network, CyIdentifiable entry) {
- String label = encode(network.getRow(entry).get(CyNetwork.NAME,
String.class));
+ String label =
encode(getRowFromNetOrRoot(network,entry,null).get(CyNetwork.NAME,
String.class));
if (label == null || label.isEmpty())
label = Long.toString(entry.getSUID());
@@ -864,6 +903,24 @@
return label;
}
+ protected CyRow getRowFromNetOrRoot(CyNetwork network, CyIdentifiable
entry, String namespace) {
+ CyRow row = null;
+ try {
+ if (namespace == null)
+ row = network.getRow(entry);
+ else
+ row = network.getRow(entry, namespace);
+ } catch (IllegalArgumentException e) {
+ // Doesn't exist in network. Try to get it from the
root
+ CyRootNetwork root =
((CySubNetwork)network).getRootNetwork();
+ if (namespace == null)
+ row = root.getRow(entry);
+ else
+ row = root.getRow(entry, namespace);
+ }
+ return row;
+ }
+
/**
* encode returns a quoted string appropriate for use as an XML attribute
*
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/SessionXGMMLNetworkWriter.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/SessionXGMMLNetworkWriter.java
2012-08-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/SessionXGMMLNetworkWriter.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -60,6 +60,15 @@
}
}
}
+
+ @Override
+ protected void writeNodes() throws IOException {
+ for (CyNode node : network.getNodeList()) {
+ // Only if not already written inside a nested graph
+ if (!writtenNodeMap.containsKey(node))
+ writeNode(network, node);
+ }
+ }
@Override
protected void writeNode(final CyNetwork net, final CyNode node) throws
IOException {
@@ -103,6 +112,15 @@
}
}
}
+
+ @Override
+ protected void writeEdges() throws IOException {
+ for (CyEdge edge : network.getEdgeList()) {
+ // Only if not already written inside a nested graph
+ if (!writtenEdgeMap.containsKey(edge))
+ writeEdge(network, edge);
+ }
+ }
@Override
protected void writeEdge(final CyNetwork net, final CyEdge edge) throws
IOException {
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-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -41,6 +41,7 @@
import org.cytoscape.model.TableTestSupport;
import org.cytoscape.model.subnetwork.CyRootNetwork;
import org.cytoscape.model.subnetwork.CyRootNetworkManager;
+import org.cytoscape.model.subnetwork.CySubNetwork;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.presentation.RenderingEngineManager;
@@ -236,8 +237,8 @@
List<CyNetworkView> views = getViews("group_2x_expanded.xgmml");
// 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);
- CyNode grNode = check2xGroupMetadata(net);
+ CyNetwork net = checkSingleNetwork(views, 3, 2);
+ CyNode grNode = check2xGroupMetadata(net, true);
assertCustomColumnsAreMutable(rootNetworkMgr.getRootNetwork(net));
assertCustomColumnsAreMutable(net);
assertCustomColumnsAreMutable(grNode.getNetworkPointer());
@@ -249,7 +250,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);
- CyNode grNode = check2xGroupMetadata(net);
+ CyNode grNode = check2xGroupMetadata(net, false);
// Check group network data
CyNetwork grNet = grNode.getNetworkPointer();
for (CyNode n : grNet.getNodeList()) {
@@ -383,18 +384,31 @@
}
}
- private CyNode check2xGroupMetadata(final CyNetwork net) {
+ private CyNode check2xGroupMetadata(final CyNetwork net, final boolean
expanded) {
// 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(ReadDataManager.GROUP_STATE_ATTRIBUTE)) {
- gn = n;
- if (++npCount > 1) fail("There should be only
one group node!");
- } else { // The other nodes have no network pointer!
- assertNull(n.getNetworkPointer());
+ if (!expanded) {
+ int npCount = 0;
+ for (CyNode n : net.getNodeList()) {
+ if (net.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet(ReadDataManager.GROUP_STATE_ATTRIBUTE)) {
+ gn = n;
+ if (++npCount > 1) fail("There should
be only one group node!");
+ } else { // The other nodes have no network
pointer!
+ assertNull(n.getNetworkPointer());
+ }
}
+ } else {
+ int npCount = 0;
+ CyRootNetwork rootNet =
((CySubNetwork)net).getRootNetwork();
+ for (CyNode n : rootNet.getNodeList()) {
+ if (rootNet.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet(ReadDataManager.GROUP_STATE_ATTRIBUTE)) {
+ 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);
Modified:
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/xgmml/AbstractXGMMLWriterTest.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/xgmml/AbstractXGMMLWriterTest.java
2012-08-30 01:28:46 UTC (rev 30292)
+++
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/xgmml/AbstractXGMMLWriterTest.java
2012-08-30 06:17:33 UTC (rev 30293)
@@ -181,6 +181,7 @@
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
+ e.printStackTrace();
throw new RuntimeException(e);
}
}
@@ -190,7 +191,7 @@
if (netOrView instanceof CyNetworkView)
writer = new GenericXGMMLWriter(out,
renderingEngineMgr, (CyNetworkView) netOrView, unrecogVisPropMgr,
- netMgr, rootNetMgr, vmMgr, null);
+ netMgr, rootNetMgr, vmMgr, groupUtil);
else if (netOrView instanceof CyNetwork)
writer = new GenericXGMMLWriter(out,
renderingEngineMgr, (CyNetwork) netOrView, unrecogVisPropMgr, netMgr,
rootNetMgr, groupUtil);
@@ -227,4 +228,4 @@
when(this.netMgr.networkExists(net.getSUID())).thenReturn(registered);
}
-}
\ 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.