use of org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkReader in project cytoscape-impl by cytoscape.
the class Cy2SessionReaderImpl method extractNetworksAndViews.
/**
* @param is
* @param entryName
* @param parent
* @param createView
* @return The top-level network that was extracted from the XGMML file.
* @throws Exception
*/
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 SessionXGMMLNetworkReader) {
((SessionXGMMLNetworkReader) reader).setParent(parent);
} else {
logger.error("CyNetworkReader should be an instance of XGMMLNetworkReader. " + "Cannot extract network as sub-nertwork of: " + entryName);
}
}
reader.run(taskMonitor);
final CyNetwork[] netArray = reader.getNetworks();
if (netArray != null && netArray.length > 0) {
topNetwork = netArray[0];
for (int i = 0; i < netArray.length; i++) {
// Process each CyNetwork
final CyNetwork net = netArray[i];
final String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
networkLookup.put(netName, net);
// Add parent network attribute to a column in the hidden table,
// to preserve the network hierarchy info from Cytoscape 2.x
final CyRow hRow = net.getRow(net, CyNetwork.HIDDEN_ATTRS);
final CyTable hTbl = hRow.getTable();
if (parent instanceof CySubNetwork) {
if (hTbl.getColumn(CY3_PARENT_NETWORK_COLUMN) == null)
hTbl.createColumn(CY3_PARENT_NETWORK_COLUMN, Long.class, false);
hRow.set(CY3_PARENT_NETWORK_COLUMN, parent.getSUID());
}
final CyTable tbl = net.getRow(net, CyNetwork.LOCAL_ATTRS).getTable();
// (e.g. the user imported a Cy3 XGMML that contains this attribute into Cy2)
if (tbl.getColumn(CY2_PARENT_NETWORK_COLUMN) != null && parent instanceof CySubNetwork == false)
tbl.deleteColumn(CY2_PARENT_NETWORK_COLUMN);
// Restore node/edge selection
List<Node> selNodes = nodeSelectionLookup.get(netName);
List<Edge> selEdges = edgeSelectionLookup.get(netName);
if (selNodes != null)
setBooleanNodeAttr(net, selNodes, SELECTED, DEFAULT_ATTRS);
if (selEdges != null)
setBooleanEdgeAttr(net, selEdges, SELECTED, DEFAULT_ATTRS);
networks.add(net);
if (!cancelled && i == 0 && createView) {
// Create a network view for the first network only,
// which is supposed to be the top-level one
final CyNetworkView view = reader.buildCyNetworkView(net);
networkViewLookup.put(netName, view);
networkViews.add(view);
cache.cache(netName, view);
}
}
}
return topNetwork;
}
Aggregations