Search in sources :

Example 56 with CyRootNetwork

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

the class NetworkMainPanel method removeNetwork.

/**
 * Remove a network from the panel.
 */
protected void removeNetwork(final CySubNetwork network) {
    nameTables.values().removeAll(Collections.singletonList(network));
    nodeEdgeTables.values().removeAll(Collections.singletonList(network));
    invokeOnEDT(() -> {
        final CyRootNetwork rootNet = network.getRootNetwork();
        final RootNetworkPanel item = getRootNetworkPanel(rootNet);
        if (item != null) {
            item.removeItem(network);
            if (item.isEmpty()) {
                getRootNetworkListPanel().removeItem(rootNet);
                nameTables.values().removeAll(Collections.singletonList(rootNet));
                nodeEdgeTables.values().removeAll(Collections.singletonList(rootNet));
            }
            updateNetworkHeader();
        }
    });
}
Also used : CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 57 with CyRootNetwork

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

the class NetworkMediator method handleEvent.

@Override
public void handleEvent(final NetworkAboutToBeDestroyedEvent e) {
    if (e.getNetwork() instanceof CySubNetwork) {
        CySubNetwork network = (CySubNetwork) e.getNetwork();
        networkMainPanel.removeNetwork(network);
        networkMainPanel.updateNodeEdgeCount();
        CyRootNetwork rootNetwork = network.getRootNetwork();
        if (rootNetwork.getSubNetworkList().size() == 1 && rootNetwork.equals(networkMainPanel.getCurrentNetwork())) {
            networkMainPanel.setCurrentNetwork(null);
        }
    }
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 58 with CyRootNetwork

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

the class GenerateNetworkViewsTask method run.

@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
    final CyNetwork[] networks = viewReader.getNetworks();
    if (networks == null || networks.length == 0)
        return;
    taskMonitor.setProgress(0.0);
    final CyNetworkNaming networkNaming = serviceRegistrar.getService(CyNetworkNaming.class);
    double numNets = (double) networks.length;
    int i = 0;
    results = new ArrayList<>();
    largeNetworks = new ArrayList<>();
    for (CyNetwork net : networks) {
        // Use original name if exists
        String networkName = net.getRow(net).get(CyNetwork.NAME, String.class);
        if (networkName == null || networkName.trim().length() == 0)
            networkName = (name != null) ? name : "? (Name is missing)";
        net.getRow(net).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
        serviceRegistrar.getService(CyNetworkManager.class).addNetwork(net, false);
        final int numGraphObjects = net.getNodeCount() + net.getEdgeCount();
        if (numGraphObjects < viewThreshold)
            createNetworkView(net);
        else
            largeNetworks.add(net);
        taskMonitor.setProgress((double) (++i) / numNets);
    }
    // If there is no name yet for the root network, set it the same as its base subnetwork
    if (networks.length == 1) {
        if (networks[0] instanceof CySubNetwork) {
            CySubNetwork subnet = (CySubNetwork) networks[0];
            final CyRootNetwork rootNet = subnet.getRootNetwork();
            String rootNetName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
            if (rootNetName == null || rootNetName.trim().length() == 0) {
                // The root network does not have a name yet, set it the same as the base subnetwork
                rootNet.getRow(rootNet).set(CyNetwork.NAME, networks[0].getRow(networks[0]).get(CyNetwork.NAME, String.class));
            }
        }
    }
    // Make sure rootNetwork has a name
    for (CyNetwork net : networks) {
        if (net instanceof CySubNetwork) {
            CySubNetwork subNet = (CySubNetwork) net;
            CyRootNetwork rootNet = subNet.getRootNetwork();
            String networkName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
            if (networkName == null || networkName.trim().length() == 0) {
                networkName = name;
                if (networkName == null)
                    networkName = "? (Name is missing)";
                rootNet.getRow(rootNet).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
            }
        }
    }
    setCurrentNetworkAndViewTask(networks[0]);
    if (!largeNetworks.isEmpty())
        insertTasksAfterCurrentTask(new ConfirmCreateNetworkViewsTask(largeNetworks));
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetwork(org.cytoscape.model.CyNetwork) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 59 with CyRootNetwork

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

the class MergeTablesTask method initTunable.

private final void initTunable(final CyTableManager tabelMgr, final CyNetworkManager networkManager) {
    final List<CyTable> listOfTables = new ArrayList<>();
    final List<Object> listOfUTables = new ArrayList<>();
    for (CyTable tempTable : tabelMgr.getGlobalTables()) {
        if (tempTable.isPublic()) {
            listOfTables.add(tempTable);
            listOfUTables.add(tempTable);
        }
    }
    final Set<CyNetwork> networkSet = networkManager.getNetworkSet();
    if (!networkSet.isEmpty()) {
        whereMergeTable = new ListSingleSelection<>(NETWORK_COLLECTION, NETWORK_SELECTION, UNASSIGNED_TABLE);
        whereMergeTable.setSelectedValue(NETWORK_COLLECTION);
        final List<TableType> options = new ArrayList<>();
        for (TableType type : TableType.values()) options.add(type);
        dataTypeTargetForNetworkCollection = new ListSingleSelection<>(options);
        dataTypeTargetForNetworkCollection.setSelectedValue(TableType.NODE_ATTR);
        dataTypeTargetForNetworkList = new ListSingleSelection<>(options);
        dataTypeTargetForNetworkList.setSelectedValue(TableType.NODE_ATTR);
        for (CyNetwork net : networkSet) {
            String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
            name2NetworkMap.put(netName, net);
        }
        final List<String> names = new ArrayList<>();
        names.addAll(name2NetworkMap.keySet());
        sort(names);
        if (names.isEmpty())
            targetNetworkList = new ListMultipleSelection<>(NO_NETWORKS);
        else
            targetNetworkList = new ListMultipleSelection<>(names);
        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);
        }
        final List<String> rootNames = new ArrayList<>();
        rootNames.addAll(name2RootMap.keySet());
        sort(rootNames);
        targetNetworkCollection = new ListSingleSelection<>(rootNames);
        if (!rootNames.isEmpty()) {
            targetNetworkCollection.setSelectedValue(rootNames.get(0));
            targetKeyNetworkCollection = getKeyColumnList(name2RootMap.get(targetNetworkCollection.getSelectedValue()), dataTypeTargetForNetworkCollection.getSelectedValue(), CyRootNetwork.SHARED_ATTRS);
        }
        for (CyNetwork network : networkSet) {
            listOfTables.add(network.getDefaultNodeTable());
            listOfTables.add(network.getDefaultEdgeTable());
        }
    } else {
        whereMergeTable = new ListSingleSelection<>(UNASSIGNED_TABLE);
        whereMergeTable.setSelectedValue(UNASSIGNED_TABLE);
    }
    sourceTable = new ListSingleSelection<>(listOfTables);
    if (!isTableGlobal(sourceTable.getSelectedValue())) {
        mergeType = new ListSingleSelection<>(COPY_COLUMNS);
    } else {
        mergeType = new ListSingleSelection<>(COPY_COLUMNS, LINK_COLUMNS);
        mergeType.setSelectedValue(COPY_COLUMNS);
    }
    sourceMergeColumns = getColumnList(sourceTable.getSelectedValue());
    sourceMergeKey = getKeyColumnList(sourceTable.getSelectedValue());
    if (listOfUTables.size() > 1) {
        if (listOfUTables.contains(sourceTable.getSelectedValue()))
            listOfUTables.remove(sourceTable.getSelectedValue());
        unassignedTable = new ListSingleSelection<>(listOfUTables);
        targetMergeKey = getKeyColumnList((CyTable) unassignedTable.getSelectedValue());
    } else {
        listOfUTables.clear();
        listOfUTables.add(NO_TABLES);
        targetMergeKey = new ListSingleSelection<>(NO_TABLES);
        unassignedTable = new ListSingleSelection<>(listOfUTables);
    }
}
Also used : ArrayList(java.util.ArrayList) ListMultipleSelection(org.cytoscape.work.util.ListMultipleSelection) CyNetwork(org.cytoscape.model.CyNetwork) CyTable(org.cytoscape.model.CyTable) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 60 with CyRootNetwork

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

the class GMLNetworkReader method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setProgress(0.0);
    try {
        keyVals = (new GMLParser(inputStream)).parseList();
    } catch (Exception io) {
        io.printStackTrace();
        throw new RuntimeException(io.getMessage());
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
                inputStream = null;
            } catch (Exception e) {
                logger.warn("Cannot close GML input stream", e);
            }
        }
    }
    taskMonitor.setProgress(0.05);
    initializeStructures();
    taskMonitor.setProgress(0.1);
    // read the GML file
    readGML(keyVals, taskMonitor);
    taskMonitor.setProgress(0.3);
    final CyRootNetwork rootNetwork = getRootNetwork();
    if (rootNetwork != null) {
        this.network = rootNetwork.addSubNetwork();
    } else {
        // Need to create new network with new root.
        this.network = (CySubNetwork) cyNetworkFactory.createNetwork();
    }
    createGraph(taskMonitor);
    taskMonitor.setProgress(0.8);
    this.networks = new CyNetwork[] { network };
    taskMonitor.setProgress(1.0);
}
Also used : 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