Author: clopes
Date: 2012-01-03 12:44:23 -0800 (Tue, 03 Jan 2012)
New Revision: 27904
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkReader.java
Log:
Fixes #545 : Create only one CyRootNetwork when importing a Cy2 session (also
store cy2 parent info as a network attribute)
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
2012-01-03 20:36:14 UTC (rev 27903)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
2012-01-03 20:44:23 UTC (rev 27904)
@@ -89,6 +89,8 @@
*/
public class Cy2SessionReaderImpl extends AbstractSessionReader {
+ public static final String CY2_PARENT_NETWORK_COLUMN = "Cytoscape2
Parent Network";
+
public static final String CY_PROPS = "session_cytoscape.props";
public static final Pattern NETWORK_PATTERN =
Pattern.compile(".*/(([^/]+)[.]xgmml)");
public static final String IGNORED_PROPS =
@@ -192,8 +194,8 @@
walkNetworkTree(netMap.get(NETWORK_ROOT), null, netMap, tm);
}
- private void walkNetworkTree(final Network net, final CyRootNetwork
parent, Map<String, Network> netMap,
- TaskMonitor tm) {
+ private void walkNetworkTree(final Network net, CyNetwork parent, final
Map<String, Network> netMap,
+ final TaskMonitor tm) {
// Get the list of children under this root
final List<Child> children = net.getChild();
@@ -201,21 +203,25 @@
final int numChildren = children.size();
Child child = null;
Network childNet = null;
-
+
for (int i = 0; i < numChildren; i++) {
child = children.get(i);
childNet = netMap.get(child.getId());
String entryName =
xgmmlEntries.get(childNet.getFilename());
- CyRootNetwork rootNetwork = null;
InputStream is = null;
+ CyNetwork cy2Parent = null; // This is the original
Cytoscape 2 parent.
try {
is = findEntry(entryName);
if (is != null) {
tm.setStatusMessage("Extracting
network: " + entryName);
- rootNetwork =
extractNetworksAndViews(is, entryName, parent, childNet.isViewAvailable());
+ cy2Parent = extractNetworksAndViews(is,
entryName, parent, childNet.isViewAvailable());
+
+ // Every 2.x network should be a child
of the same root-network.
+ if (parent == null)
+ parent =
rootNetworkManager.getRootNetwork(cy2Parent);
} else {
logger.error("Cannot find network file
\"" + entryName + "\": ");
}
@@ -235,7 +241,7 @@
// Always try to load child networks, even if
the parent network is bad
if (childNet.getChild().size() != 0)
- walkNetworkTree(childNet, rootNetwork,
netMap, tm);
+ walkNetworkTree(childNet, cy2Parent,
netMap, tm);
}
}
}
@@ -245,13 +251,13 @@
* @param entryName
* @param parent
* @param createView
- * @return The root-network of the extracted networks
+ * @return The top-level network that was extracted from the XGMML file.
* @throws Exception
*/
- private CyRootNetwork extractNetworksAndViews(InputStream is, String
entryName, CyRootNetwork parent,
- boolean createView) throws Exception {
- CyRootNetwork rootNetwork = null;
- CyNetworkReader reader = networkReaderMgr.getReader(is,
entryName);
+ private CyNetwork extractNetworksAndViews(final InputStream is, final
String entryName, final CyNetwork parent,
+ final boolean createView) throws Exception {
+ CyNetwork topNetwork = null;
+ final CyNetworkReader reader = networkReaderMgr.getReader(is,
entryName);
if (parent != null) {
if (reader instanceof XGMMLNetworkReader) {
@@ -267,12 +273,22 @@
final CyNetwork[] netArray = reader.getNetworks();
if (netArray != null && netArray.length > 0) {
- rootNetwork =
rootNetworkManager.getRootNetwork(netArray[0]);
+ topNetwork = netArray[0];
for (int i = 0; i < netArray.length; i++) {
CyNetwork net = netArray[i];
String netName =
net.getRow(net).get(CyNetwork.NAME, String.class);
networkLookup.put(netName, net);
+
+ // Add parent network attribute, to preserve
the network hierarchy info from Cytoscape 2.x
+ if (parent != null && !(parent instanceof
CyRootNetwork)) {
+ CyRow row = net.getRow(net);
+
+ if
(row.getTable().getColumn(CY2_PARENT_NETWORK_COLUMN) == null)
+
row.getTable().createColumn(CY2_PARENT_NETWORK_COLUMN, Long.class, false);
+
+ row.set(CY2_PARENT_NETWORK_COLUMN,
parent.getSUID());
+ }
// TODO: handle 2.x groups
// if (i == 0) {
@@ -281,7 +297,8 @@
networks.add(net);
if (i == 0 && createView) {
- // Create a network view for
the first network only, which is supposed to be the base-network
+ // Create a network view for
the first network only,
+ // which is supposed to be the
top-level one
CyNetworkView view =
reader.buildCyNetworkView(net);
networkViewLookup.put(netName,
view);
networkViews.add(view);
@@ -290,7 +307,7 @@
}
}
- return rootNetwork;
+ return topNetwork;
}
private void extractAppEntry(InputStream is, String entryName) {
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkReader.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkReader.java
2012-01-03 20:36:14 UTC (rev 27903)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkReader.java
2012-01-03 20:44:23 UTC (rev 27904)
@@ -73,11 +73,7 @@
}
public void setParent(CyNetwork n) {
- if (n != null) {
- this.parent = (n instanceof CyRootNetwork) ?
(CyRootNetwork) n : cyRootNetworkManager.getRootNetwork(n);
- } else {
- this.parent = null;
- }
+ this.parent = n != null ?
cyRootNetworkManager.getRootNetwork(n) : null;
}
@Override
--
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.