Search in sources :

Example 61 with CyRootNetwork

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

the class GroupViewCollapseHandler method handleEvent.

@Override
public void handleEvent(GroupCollapsedEvent e) {
    getServices();
    CyNetwork network = e.getNetwork();
    CyGroup group = e.getSource();
    final Collection<CyNetworkView> views = cyNetworkViewManager.getNetworkViews(network);
    CyNetworkView view = null;
    if (views.size() == 0) {
        return;
    }
    for (CyNetworkView v : views) {
        if (v.getRendererId().equals("org.cytoscape.ding")) {
            view = v;
        }
    }
    if (view == null)
        return;
    CyRootNetwork rootNetwork = group.getRootNetwork();
    GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
    if (e.collapsed()) {
        // System.out.println("Got collapse event for "+group);
        // Get the location to move the group node to
        Dimension d = ViewUtils.getLocation(network, group);
        if (d != null) {
            // Move it.
            ViewUtils.moveNode(view, group.getGroupNode(), d);
        }
        View<CyNode> nView = view.getNodeView(group.getGroupNode());
        if (cyGroupSettings.getUseNestedNetworks(group)) {
            // Now, if we're displaying the nested network, create it....
            CyNetwork nn = group.getGroupNetwork();
            CyNetworkView nnView = null;
            // If we've already registered the network, don't do it again
            if (!cyNetworkManager.networkExists(nn.getSUID())) {
                cyNetworkManager.addNetwork(nn, false);
                nnView = cyNetworkViewFactory.createNetworkView(nn);
                cyNetworkViewManager.addNetworkView(nnView, false);
                // Apply our current style to the nested network
                VisualStyle style = cyStyleManager.getVisualStyle(view);
                cyStyleManager.setVisualStyle(style, nnView);
                style.apply(nnView);
            } else if (cyNetworkViewManager.viewExists(nn)) {
                nnView = cyNetworkViewManager.getNetworkViews(nn).iterator().next();
            }
            if (nnView != null) {
                ViewUtils.moveNodes(group, nnView, d);
                nnView.updateView();
                // Allow the nested network image to be displayed
                nView.clearValueLock(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE);
            }
        } else {
            // Make sure the nested network image is not displayed
            nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
        }
        // If we were showing this as a compound node, we need to restyle
        if (groupViewType.equals(GroupViewType.COMPOUND)) {
            deActivateCompoundNode(group, view);
        }
        styleGroupNode(group, view, views);
    } else {
        // System.out.println("Got expand event for "+group);
        CyNode groupNode = group.getGroupNode();
        // Get the location of the group node before it went away
        Dimension center = ViewUtils.getLocation(network, group);
        if (center != null)
            ViewUtils.moveNodes(group, view, center);
        // If we're asked to, show the group node
        if (!groupViewType.equals(GroupViewType.NONE)) {
            CySubNetwork subnet = (CySubNetwork) network;
            // Add the node back
            subnet.addNode(group.getGroupNode());
            // Add the group nodes's edges back
            List<CyEdge> groupNodeEdges = rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY);
            for (CyEdge edge : groupNodeEdges) {
                CyRow row = rootNetwork.getRow(edge, CyNetwork.HIDDEN_ATTRS);
                // Only add non-meta edges
                if (row != null && (!row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) || !row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class))) {
                    subnet.addEdge(edge);
                } else if (subnet.containsEdge(edge) && row != null && row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) && row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class)) {
                    // Edge is a meta edge, but is still in the network.  Remove it
                    subnet.removeEdges(Collections.singletonList(edge));
                }
            }
            if (groupViewType.equals(GroupViewType.SHOWGROUPNODE)) {
                // If this is the first time, we need to add our member
                // edges in.
                addMemberEdges(group, network);
                // Style our member edges
                styleGroupNode(group, view, views);
            }
            // Flush events so that the view hears about it
            final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
            cyEventHelper.flushPayloadEvents();
            // Now, call ourselves as if we had been collapsed
            handleEvent(new GroupCollapsedEvent(group, network, true));
            if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
                // May be redundant, but just to make sure
                ((CyGroupImpl) group).setGroupNodeShown(network, true);
                activateCompoundNode(group, view);
            }
            cyEventHelper.flushPayloadEvents();
            view.updateView();
            return;
        }
        final List<CyNode> nodeList = group.getNodeList();
        // TODO: turn off stupid nested network thing
        for (CyNode node : nodeList) {
            if (!network.containsNode(node))
                continue;
            View<CyNode> nView = view.getNodeView(node);
            if (node.getNetworkPointer() != null && cyGroupManager.isGroup(node, network)) {
                if (!cyGroupSettings.getUseNestedNetworks(cyGroupManager.getGroup(node, network))) {
                    nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
                }
            }
        }
        // Apply visual property to added graph elements
        ViewUtils.applyStyle(nodeList, views, cyStyleManager);
        ViewUtils.applyStyle(group.getInternalEdgeList(), views, cyStyleManager);
        ViewUtils.applyStyle(group.getExternalEdgeList(), views, cyStyleManager);
    }
    view.updateView();
}
Also used : GroupViewType(org.cytoscape.group.CyGroupSettingsManager.GroupViewType) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetwork(org.cytoscape.model.CyNetwork) Dimension(java.awt.Dimension) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyGroup(org.cytoscape.group.CyGroup) CyGroupImpl(org.cytoscape.group.internal.CyGroupImpl) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) GroupCollapsedEvent(org.cytoscape.group.events.GroupCollapsedEvent) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 62 with CyRootNetwork

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

the class NetworkCollectionHelper method getRootNetwork.

// Return the rootNetwork based on user selection, if not existed yet, create a new one
public CyRootNetwork getRootNetwork() {
    final CyRootNetwork rootNetwork;
    final String rootNetName = rootNetworkList.getSelectedValue();
    if (rootNetName == null || rootNetName.equalsIgnoreCase(CREATE_NEW_COLLECTION_STRING)) {
        final CyNetwork newNet = serviceRegistrar.getService(CyNetworkFactory.class).createNetwork();
        rootNetwork = serviceRegistrar.getService(CyRootNetworkManager.class).getRootNetwork(newNet);
    } else {
        rootNetwork = name2RootMap.get(rootNetName);
        if (rootNetwork == null) {
            throw new RuntimeException("Can't find a network collection named '" + rootNetName + "'");
        }
    }
    return rootNetwork;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 63 with CyRootNetwork

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

the class NetworkCollectionHelper method getRootNetworkMap.

private HashMap<String, CyRootNetwork> getRootNetworkMap() {
    final HashMap<String, CyRootNetwork> name2RootMap = new HashMap<>();
    final Set<CyNetwork> networkSet = serviceRegistrar.getService(CyNetworkManager.class).getNetworkSet();
    final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
    for (CyNetwork net : networkSet) {
        final CyRootNetwork rootNet = rootNetworkManager.getRootNetwork(net);
        if (!name2RootMap.containsValue(rootNet))
            name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);
    }
    return name2RootMap;
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 64 with CyRootNetwork

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

the class NetworkCollectionHelper method init.

void init() {
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
    // initialize the network Collection
    name2RootMap = getRootNetworkMap();
    final List<String> rootNames = new ArrayList<>();
    rootNames.addAll(name2RootMap.keySet());
    if (!rootNames.isEmpty()) {
        sort(rootNames);
        rootNames.add(0, CREATE_NEW_COLLECTION_STRING);
    }
    rootNetworkList = new ListSingleSelection<>(rootNames);
    final CyNetwork net = appMgr != null ? appMgr.getCurrentNetwork() : null;
    final CyRootNetwork rootNet = net != null ? rootNetMgr.getRootNetwork(net) : null;
    final String rootNetName = rootNet != null ? rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class) : CREATE_NEW_COLLECTION_STRING;
    if (rootNames.contains(rootNetName))
        rootNetworkList.setSelectedValue(rootNetName);
    else if (rootNames.contains(CREATE_NEW_COLLECTION_STRING))
        rootNetworkList.setSelectedValue(CREATE_NEW_COLLECTION_STRING);
    if (rootNet != null)
        targetColumnList = getTargetColumns(rootNet);
    else
        targetColumnList = new ListSingleSelection<>();
    // initialize renderer list
    final List<NetworkViewRenderer> renderers = new ArrayList<>();
    final Set<NetworkViewRenderer> rendererSet = appMgr.getNetworkViewRendererSet();
    // so the combo-box does not appear to the user, since there is nothing to select anyway.
    if (rendererSet.size() > 1) {
        renderers.addAll(rendererSet);
        Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {

            @Override
            public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
                return r1.toString().compareToIgnoreCase(r2.toString());
            }
        });
    }
    rendererList = new ListSingleSelection<>(renderers);
    final NetworkViewRenderer defViewRenderer = appMgr.getDefaultNetworkViewRenderer();
    if (defViewRenderer != null && renderers.contains(defViewRenderer))
        rendererList.setSelectedValue(defViewRenderer);
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 65 with CyRootNetwork

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

the class SIFNetworkReader method readInput.

private void readInput(TaskMonitor tm) throws IOException {
    this.parentTaskMonitor = tm;
    tm.setProgress(0.0);
    String line;
    final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8").newDecoder()), 128 * 1024);
    CyRootNetwork root = getRootNetwork();
    final CySubNetwork newNetwork;
    if (root != null)
        newNetwork = root.addSubNetwork();
    else
        // Need to create new network with new root.
        newNetwork = (CySubNetwork) cyNetworkFactory.createNetwork();
    Map<Object, CyNode> nMap = getNodeMap();
    tm.setProgress(0.1);
    final String firstLine = br.readLine();
    if (firstLine.contains(TAB))
        delimiter = TAB;
    createEdge(new Interaction(firstLine.trim(), delimiter), newNetwork, nMap);
    tm.setProgress(0.15);
    tm.setStatusMessage("Processing the interactions...");
    int numInteractionsRead = 0;
    while ((line = br.readLine()) != null) {
        if (cancelled) {
            // Cancel called. Clean up the garbage.
            nMap.clear();
            br.close();
            return;
        }
        if (line.trim().length() <= 0)
            continue;
        try {
            final Interaction itr = new Interaction(line, delimiter);
            createEdge(itr, newNetwork, nMap);
        } catch (Exception e) {
            // Simply ignore invalid lines.
            continue;
        }
        if ((++numInteractionsRead % 1000) == 0)
            tm.setStatusMessage("Processed " + numInteractionsRead + " interactions so far.");
    }
    br.close();
    tm.setStatusMessage("Processed " + numInteractionsRead + " interactions in total.");
    nMap.clear();
    nMap = null;
    this.networks = new CyNetwork[] { newNetwork };
    tm.setProgress(1.0);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) CyNode(org.cytoscape.model.CyNode) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) IOException(java.io.IOException) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)86 CyNetwork (org.cytoscape.model.CyNetwork)39 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)38 CyNode (org.cytoscape.model.CyNode)29 CyEdge (org.cytoscape.model.CyEdge)15 CyRow (org.cytoscape.model.CyRow)15 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)15 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 CyGroup (org.cytoscape.group.CyGroup)7 HashSet (java.util.HashSet)6 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)4 CyNetworkManager (org.cytoscape.model.CyNetworkManager)4 Image (java.awt.Image)3 BufferedImage (java.awt.image.BufferedImage)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3