Search in sources :

Example 31 with CyRootNetwork

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

the class GroupUtil method getGroupNodeEdges.

public List<CyEdge> getGroupNodeEdges(final CyNetwork network) {
    CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
    // Don't need to worry about this for collapsed groups
    List<CyNode> groupNodes = getExpandedGroups(network);
    List<CyEdge> groupNodeEdges = new ArrayList<>();
    for (CyNode groupNode : groupNodes) {
        groupNodeEdges.addAll(rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY));
    }
    return groupNodeEdges;
}
Also used : ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 32 with CyRootNetwork

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

the class GenericXGMMLWriter method getRowFromNetOrRoot.

protected CyRow getRowFromNetOrRoot(final CyNetwork network, final CyIdentifiable entry, String namespace) {
    CyRow row = null;
    try {
        row = namespace == null ? network.getRow(entry) : network.getRow(entry, namespace);
    } catch (final IllegalArgumentException e) {
    // Ignore this exception
    } catch (final RuntimeException e) {
        logger.error("Cannot get \"" + namespace + "\" row for entry \"" + entry + "\" in network \"" + network + "\".", e);
    }
    if (row == null && network instanceof CySubNetwork) {
        // Doesn't exist in subnetwork? Try to get it from the root network.
        final CyRootNetwork root = ((CySubNetwork) network).getRootNetwork();
        row = namespace == null ? root.getRow(entry) : root.getRow(entry, namespace);
    }
    return row;
}
Also used : CyRow(org.cytoscape.model.CyRow) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 33 with CyRootNetwork

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

the class GenericXGMMLWriter method writeSubGraph.

protected void writeSubGraph(final CyNetwork net) throws IOException {
    if (net == null)
        return;
    if (writtenNetMap.containsKey(net)) {
        // This sub-network has already been written
        writeSubGraphReference(net);
    } else {
        // Check if this network is from the same root network as the base network
        final CyRootNetwork otherRoot = serviceRegistrar.getService(CyRootNetworkManager.class).getRootNetwork(net);
        boolean sameRoot = rootNetwork.equals(otherRoot);
        if (sameRoot) {
            // Write it for the first time
            writtenNetMap.put(net, net);
            writeElement("<att>\n");
            depth++;
            writeElement("<graph");
            // Always write the network ID
            writeAttributePair("id", net.getSUID());
            // Save the label to make it more human readable
            writeAttributePair("label", getLabel(net, net));
            writeAttributePair("cy:registered", ObjectTypeMap.toXGMMLBoolean(isRegistered(net)));
            write(">\n");
            depth++;
            writeAttributes(net.getRow(net));
            writeAttributes(net.getRow(net, CyNetwork.HIDDEN_ATTRS));
            for (CyNode childNode : net.getNodeList()) writeNode(net, childNode);
            for (CyEdge childEdge : net.getEdgeList()) writeEdge(net, childEdge);
            depth--;
            writeElement("</graph>\n");
            depth--;
            writeElement("</att>\n");
        }
    }
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 34 with CyRootNetwork

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

the class SessionWriterImpl method zipNetworks.

/**
 * Writes network files to the session zip.
 * @throws Exception
 */
private void zipNetworks() throws Exception {
    final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
    final Set<CyNetwork> networks = session.getNetworks();
    final Set<CyRootNetwork> rootNetworks = new HashSet<>();
    // Zip only root-networks, because sub-networks should be automatically saved with them.
    for (final CyNetwork n : networks) {
        final CyRootNetwork rn = rootNetworkManager.getRootNetwork(n);
        if (rn.getSavePolicy() == SavePolicy.SESSION_FILE)
            rootNetworks.add(rn);
    }
    for (CyRootNetwork rn : rootNetworks) {
        if (cancelled)
            return;
        String xgmmlFile = SessionUtil.getXGMMLFilename(rn);
        if (xgmmlFile.contains("_ERROR"))
            throw new Exception("Simulating exception...");
        zos.putNextEntry(new ZipEntry(sessionDir + NETWORKS_FOLDER + xgmmlFile));
        CyWriter writer = networkViewWriterFactory.createWriter(zos, rn);
        writer.run(taskMonitor);
        zos.closeEntry();
        writer = null;
    }
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) ZipEntry(java.util.zip.ZipEntry) CyWriter(org.cytoscape.io.write.CyWriter) CyNetwork(org.cytoscape.model.CyNetwork) IOException(java.io.IOException) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) HashSet(java.util.HashSet)

Example 35 with CyRootNetwork

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

the class NetworkCollectionHelper method initNodeMap.

// Build the key-node map for the entire root network
// Note: The keyColName should start with "shared name"
protected void initNodeMap() {
    final String rootNetName = rootNetworkList.getSelectedValue();
    if (rootNetName == null || rootNetName.equalsIgnoreCase(CREATE_NEW_COLLECTION_STRING))
        return;
    String targetKeyColName = targetColumnList.getSelectedValue();
    if (targetKeyColName == null)
        targetKeyColName = CyRootNetwork.SHARED_NAME;
    final CyRootNetwork rootNetwork = name2RootMap.get(rootNetName);
    if (rootNetwork == null)
        return;
    final Iterator<CyNode> it = rootNetwork.getNodeList().iterator();
    while (it.hasNext()) {
        CyNode node = it.next();
        Object keyValue = rootNetwork.getRow(node).getRaw(targetKeyColName);
        if (keyValue != null)
            nMap.put(keyValue.toString(), node);
    }
}
Also used : CyNode(org.cytoscape.model.CyNode) 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