Search in sources :

Example 1 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork 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 CySubNetwork

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

the class GroupUtils method addGroupToNetwork.

public static void addGroupToNetwork(CyGroup group, CyNetwork origNet, CyNetwork newNet) {
    CyNetwork groupNetwork = group.getGroupNetwork();
    Dimension d = getPosition(origNet, group, groupNetwork.getSUID(), CyNetwork.class);
    updatePosition(newNet, group, groupNetwork.getSUID(), CyNetwork.class, d);
    for (CyNode node : group.getNodeList()) {
        Long nodeSUID = node.getSUID();
        d = getPosition(origNet, group, nodeSUID, CyNode.class);
        updatePosition(newNet, group, nodeSUID, CyNode.class, d);
        // This helps out collapse
        ((CySubNetwork) newNet).addNode(node);
    }
    for (CyEdge edge : group.getInternalEdgeList()) {
        // This helps out collapse
        ((CySubNetwork) newNet).addEdge(edge);
    }
    for (CyEdge edge : group.getExternalEdgeList()) {
        // This helps out collapse
        ((CySubNetwork) newNet).addEdge(edge);
    }
    group.addGroupToNetwork(newNet);
    group.collapse(newNet);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Dimension(java.awt.Dimension) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 3 with CySubNetwork

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

the class AddTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    network = nodesAndEdges.getNetwork();
    if (network == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
        return;
    }
    nodeList = nodesAndEdges.getNodeList(false);
    edgeList = nodesAndEdges.getEdgeList(false);
    if ((nodeList == null || nodeList.size() == 0) && (edgeList == null || edgeList.size() == 0)) {
        taskMonitor.showMessage(TaskMonitor.Level.WARN, "Nothing to add");
        return;
    }
    int nodeCount = nodeList.size();
    int edgeCount = 0;
    for (CyNode node : nodeList) ((CySubNetwork) network).addNode(node);
    // nodes and "all" edges
    for (CyEdge edge : edgeList) {
        if (network.containsNode(edge.getSource()) && network.containsNode(edge.getTarget())) {
            ((CySubNetwork) network).addEdge(edge);
            edgeCount++;
        }
    }
    eventHelper.flushPayloadEvents();
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added " + nodeCount + " nodes and " + edgeCount + " edges to network " + network.toString());
}
Also used : CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 4 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork 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)

Example 5 with CySubNetwork

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

the class HandleGraphDone method handle.

@Override
public ParseState handle(String tag, Attributes atts, ParseState current) throws SAXException {
    graphDone();
    // End of document?
    if (manager.graphDoneCount != manager.graphCount)
        return current;
    // Resolve any unresolved node and edge references
    Map<CyNetwork, Set<Long>> nodeMap = manager.getCache().getNodeLinks();
    for (Map.Entry<CyNetwork, Set<Long>> entry : nodeMap.entrySet()) {
        CyNetwork net = entry.getKey();
        Set<Long> ids = entry.getValue();
        if (net != null && ids != null && !ids.isEmpty()) {
            if (net instanceof CySubNetwork) {
                final CySubNetwork sn = (CySubNetwork) net;
                for (Long id : ids) {
                    CyNode n = manager.getCache().getNode(id);
                    if (n != null)
                        sn.addNode(n);
                    else
                        logger.error("Cannot find XLink node with id \"" + id + "\".");
                }
            } else {
                logger.error("Cannot add existing nodes \"" + ids.toArray() + "\" to a network which is not a CySubNetwork");
            }
        }
    }
    // TODO: refactor
    Map<CyNetwork, Set<Long>> edgeMap = manager.getCache().getEdgeLinks();
    for (Map.Entry<CyNetwork, Set<Long>> entry : edgeMap.entrySet()) {
        CyNetwork net = entry.getKey();
        Set<Long> ids = entry.getValue();
        if (net != null && ids != null && !ids.isEmpty()) {
            if (net instanceof CySubNetwork) {
                final CySubNetwork sn = (CySubNetwork) net;
                for (Long id : ids) {
                    final CyEdge e = manager.getCache().getEdge(id);
                    if (e != null)
                        sn.addEdge(e);
                    else
                        logger.error("Cannot find XLink edge with id \"" + id + "\".");
                }
            } else {
                logger.error("Cannot add existing edges \"" + ids.toArray() + "\" to a network which is not a CySubNetwork");
            }
        }
    }
    manager.getCache().deleteUnresolvedNodes();
    resolveEquations();
    resolveNetworkPointers();
    updateSUIDAttributes();
    // TODO: we should not create (and specially register) groups here!
    createGroups();
    return ParseState.NONE;
}
Also used : Set(java.util.Set) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Map(java.util.Map) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Aggregations

CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)88 CyNode (org.cytoscape.model.CyNode)44 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CyNetwork (org.cytoscape.model.CyNetwork)31 CyEdge (org.cytoscape.model.CyEdge)28 Test (org.junit.Test)19 CyRow (org.cytoscape.model.CyRow)15 ArrayList (java.util.ArrayList)12 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 HashSet (java.util.HashSet)7 CyGroup (org.cytoscape.group.CyGroup)7 HashMap (java.util.HashMap)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 Dimension (java.awt.Dimension)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)3