Search in sources :

Example 1 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class DestroyNetworkTask method destroyNetwork.

private void destroyNetwork(final CyNetwork net, CyNetworkManager netManager) {
    CyRootNetwork rootNet = null;
    CySubNetwork parentNet = null;
    if (net instanceof CySubNetwork) {
        rootNet = ((CySubNetwork) net).getRootNetwork();
        final Long suid = DataUtils.getParentNetworkSUID((CySubNetwork) net);
        if (suid != null && netManager.getNetwork(suid) instanceof CySubNetwork)
            parentNet = (CySubNetwork) netManager.getNetwork(suid);
    }
    netManager.destroyNetwork(net);
    if (net instanceof CySubNetwork)
        updateParentNetworkData(net.getSUID(), rootNet, (parentNet != null ? parentNet.getSUID() : null));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 2 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class AbstractSessionReader method cleanUp.

/**
 * Use this methods to dispose temporary resources.
 * This method must always be invoked, even if this task is cancelled.
 */
protected void cleanUp(TaskMonitor tm) {
    try {
        ((ReusableInputStream) sourceInputStream).reallyClose();
    } catch (Exception e) {
        logger.error("Error closing source input stream.", e);
    }
    if (cancelled) {
        // Destroy groups
        final Set<CyGroup> groups = groupUtil.getGroups(cache.getNetworks());
        groupUtil.destroyGroups(groups);
        // Dispose CyNetworkViews and CyNetworks
        for (final CyNetworkView view : networkViews) view.dispose();
        final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
        final Set<CyRootNetwork> rootNetworks = new HashSet<>();
        // such as group networks.
        for (final CyNetwork net : cache.getNetworks()) {
            net.dispose();
            rootNetworks.add(rootNetworkManager.getRootNetwork(net));
        }
        for (final CyRootNetwork rootNet : rootNetworks) rootNet.dispose();
        networkViews.clear();
        networks.clear();
    }
    cache.dispose();
    SessionUtil.setReadingSessionFile(false);
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) IOException(java.io.IOException) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class HandleGraph method handleCy2ModelAndView.

/**
 * Handles XGMML from Cytoscape 2.x session files only.
 * @param tag
 * @param atts
 * @param current
 * @return
 * @throws SAXException
 */
private ParseState handleCy2ModelAndView(String tag, Attributes atts, ParseState current) throws SAXException {
    final CyRootNetwork parent = manager.getParentNetwork();
    final CyNetwork currentNet;
    if (manager.graphCount == 1) {
        // Root (graph) element...
        if (parent == null) {
            // This is a regular top-level network...
            final CyRootNetwork rootNet = manager.createRootNetwork();
            currentNet = rootNet.getBaseNetwork();
        } else {
            // This is a 2.x "child-network"...
            currentNet = parent.addSubNetwork();
        }
    } else {
        // Nested graph tag...
        final CyRootNetwork rootNet = manager.getRootNetwork();
        currentNet = rootNet.addSubNetwork();
    }
    // This is the network ID in 2.x
    final String id = getLabel(atts);
    addCurrentNetwork(id, currentNet, atts, true);
    return current;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 4 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class HandleGraph method setNetworkName.

/**
 * Should be used when handling 2.x format only or importing the network from a standalone XGMML file.
 */
protected void setNetworkName(CyNetwork net, Attributes atts) {
    String name = getLabel(atts);
    if (name == null || name.trim().isEmpty()) {
        if (net instanceof CyRootNetwork) {
            name = "Root-Network " + net.getSUID();
        } else if (manager.graphCount == 1) {
            name = "Network " + net.getSUID();
        } else {
            CyRootNetwork root = manager.getRootNetwork();
            if (root != null) {
                name = root.getBaseNetwork().getRow(root.getBaseNetwork()).get(CyNetwork.NAME, String.class);
                if (name == null || name.trim().isEmpty())
                    name = root.getRow(root).get(CyNetwork.NAME, String.class);
            }
        }
        if (name == null || name.trim().isEmpty())
            name = "Network " + net.getSUID();
        name += " - " + manager.graphCount;
    }
    if (net != null && name != null) {
        CyRow netRow = net.getRow(net);
        netRow.set(CyNetwork.NAME, name);
    }
}
Also used : CyRow(org.cytoscape.model.CyRow) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 5 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class HandleNodeGraph method handle.

@Override
public ParseState handle(String tag, Attributes atts, ParseState current) throws SAXException {
    manager.graphCount++;
    final CyNode node = manager.getCurrentNode();
    manager.getCompoundNodeStack().push(node);
    final String href = atts.getValue(ReadDataManager.XLINK, "href");
    Object netId = null;
    CyNetwork network = null;
    if (href != null) {
        // The network has already been created
        netId = AttributeValueUtil.getIdFromXLink(href);
        if (netId == null)
            logger.error("The node's network pointer will not be created: " + "the network ID cannot be parsed from the XLink reference.");
        addCurrentNetwork(netId, network, atts, isRegistered(atts));
    } else {
        netId = getId(atts);
        // Create network
        final CyRootNetwork rootNet = manager.getRootNetwork();
        network = rootNet.addSubNetwork();
        netId = addCurrentNetwork(netId, network, atts, isRegistered(atts));
    }
    if (netId != null)
        manager.getCache().addNetworkPointer(node, netId);
    return current;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)80 CyNetwork (org.cytoscape.model.CyNetwork)35 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)35 CyNode (org.cytoscape.model.CyNode)26 CyEdge (org.cytoscape.model.CyEdge)15 CyRow (org.cytoscape.model.CyRow)15 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)13 CyTable (org.cytoscape.model.CyTable)10 CyNetworkView (org.cytoscape.view.model.CyNetworkView)10 CyGroup (org.cytoscape.group.CyGroup)7 HashSet (java.util.HashSet)6 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3 AbstractNetworkReaderTest (org.cytoscape.io.internal.read.AbstractNetworkReaderTest)3 CyColumn (org.cytoscape.model.CyColumn)3 CyNetworkManager (org.cytoscape.model.CyNetworkManager)3