Search in sources :

Example 1 with SessionXGMMLNetworkReader

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;
}
Also used : CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.session.model.Node) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyTable(org.cytoscape.model.CyTable) SessionXGMMLNetworkReader(org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkReader) Edge(org.cytoscape.io.internal.util.session.model.Edge) CyEdge(org.cytoscape.model.CyEdge) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Aggregations

SessionXGMMLNetworkReader (org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkReader)1 Edge (org.cytoscape.io.internal.util.session.model.Edge)1 Node (org.cytoscape.io.internal.util.session.model.Node)1 CyNetworkReader (org.cytoscape.io.read.CyNetworkReader)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyRow (org.cytoscape.model.CyRow)1 CyTable (org.cytoscape.model.CyTable)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1