Search in sources :

Example 1 with Child

use of org.cytoscape.io.internal.util.session.model.Child in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method walkNetworkTree.

private void walkNetworkTree(final Network net, CyNetwork parent, final Map<String, Network> netMap, final TaskMonitor tm, final CyRootNetworkManager rootNetworkManager) {
    // Get the list of children under this root
    final List<Child> children = net.getChild();
    // Traverse using recursive call
    final int numChildren = children.size();
    Child child = null;
    Network childNet = null;
    for (int i = 0; i < numChildren; i++) {
        if (cancelled)
            return;
        child = children.get(i);
        childNet = netMap.get(child.getId());
        String entryName = xgmmlEntries.get(childNet.getFilename());
        InputStream is = null;
        // This is the original Cytoscape 2 parent.
        CyNetwork cy2Parent = null;
        try {
            is = findEntry(entryName);
            if (is != null) {
                tm.setStatusMessage("Extracting network: " + entryName);
                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 + "\": ");
            }
        } catch (final Exception e) {
            final String message = "Unable to read XGMML file \"" + childNet.getFilename() + "\": " + e.getMessage();
            logger.error(message, e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (final Exception ex) {
                    logger.error("Unable to close XGMML input stream.", ex);
                }
                is = null;
            }
            // Always try to load child networks, even if the parent network is bad
            if (!cancelled && childNet.getChild().size() != 0)
                walkNetworkTree(childNet, cy2Parent, netMap, tm, rootNetworkManager);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CyNetwork(org.cytoscape.model.CyNetwork) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) Network(org.cytoscape.io.internal.util.session.model.Network) CyNetwork(org.cytoscape.model.CyNetwork) Child(org.cytoscape.io.internal.util.session.model.Child) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JAXBException (javax.xml.bind.JAXBException)1 Child (org.cytoscape.io.internal.util.session.model.Child)1 Network (org.cytoscape.io.internal.util.session.model.Network)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1