Search in sources :

Example 16 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class NNFParser method setNestedNetwork.

private void setNestedNetwork(CyNetwork sourceNetwork, CyNode node, CyNetwork targetNetwork) {
    // TODO: We should consider exposing a nested network API so we don't
    // have to do this everywhere we establish this link.
    node.setNetworkPointer(targetNetwork);
    CyTable nodeTable = sourceNetwork.getDefaultNodeTable();
    boolean attributeExists = nodeTable.getColumn(HAS_NESTED_NETWORK_ATTRIBUTE) != null;
    if (targetNetwork == null && attributeExists) {
        nodeTable.getRow(node.getSUID()).set(HAS_NESTED_NETWORK_ATTRIBUTE, false);
    } else if (targetNetwork != null) {
        if (!attributeExists) {
            nodeTable.createColumn(HAS_NESTED_NETWORK_ATTRIBUTE, Boolean.class, false);
        }
        CyRow row = nodeTable.getRow(node.getSUID());
        row.set(HAS_NESTED_NETWORK_ATTRIBUTE, true);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyRow(org.cytoscape.model.CyRow)

Example 17 with CyTable

use of org.cytoscape.model.CyTable 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 18 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class Cy3SessionReaderImpl method mergeNetworkTable.

@SuppressWarnings("unchecked")
private final void mergeNetworkTable(CyNetwork network, CyTableMetadataBuilder builder, CyNetworkTableManager networkTableMgr) {
    final Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) builder.getType();
    final String namespace = builder.getNamespace();
    final CyTable src = builder.getTable();
    final CyTable tgt = networkTableMgr.getTable(network, type, namespace);
    if (tgt == null) {
        // Just use the source table
        networkTableMgr.setTable(network, type, namespace, src);
        builder.setCyTable(src);
        suidUpdater.addTable(src);
    } else {
        mergeTables(src, tgt, type);
        builder.setCyTable(tgt);
        suidUpdater.addTable(tgt);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 19 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class NetworkMediator method handleEvent.

@Override
public void handleEvent(final RowsSetEvent e) {
    if (loadingSession || networkMainPanel.getRootNetworkListPanel().isEmpty())
        return;
    // We only care about network name changes
    final Collection<RowSetRecord> nameRecords = e.getColumnRecords(CyNetwork.NAME);
    if (nameRecords == null || nameRecords.isEmpty())
        return;
    final CyTable tbl = e.getSource();
    final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
    final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
    // And if there is no related network, nothing needs to be done
    if (net != null && tbl.equals(net.getDefaultNetworkTable())) {
        invokeOnEDT(() -> {
            final AbstractNetworkPanel<?> item = networkMainPanel.getNetworkItem(net);
            if (item != null)
                item.update();
        });
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyTable(org.cytoscape.model.CyTable) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) CyNetwork(org.cytoscape.model.CyNetwork)

Example 20 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class DefaultTableBrowser method getPublicTables.

private Set<CyTable> getPublicTables(CyNetwork currentNetwork) {
    final Set<CyTable> tables = new LinkedHashSet<>();
    if (currentNetwork == null)
        return tables;
    final CyNetworkTableManager netTableManager = serviceRegistrar.getService(CyNetworkTableManager.class);
    final Map<String, CyTable> map = netTableManager.getTables(currentNetwork, objType);
    if (showPrivateTables()) {
        tables.addAll(map.values());
    } else {
        for (final CyTable tbl : map.values()) {
            if (tbl.isPublic())
                tables.add(tbl);
        }
    }
    return tables;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CyTable(org.cytoscape.model.CyTable) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager)

Aggregations

CyTable (org.cytoscape.model.CyTable)282 CyNetwork (org.cytoscape.model.CyNetwork)79 CyRow (org.cytoscape.model.CyRow)73 CyColumn (org.cytoscape.model.CyColumn)71 ArrayList (java.util.ArrayList)55 CyNode (org.cytoscape.model.CyNode)43 CyEdge (org.cytoscape.model.CyEdge)35 Test (org.junit.Test)29 List (java.util.List)26 HashMap (java.util.HashMap)24 CyApplicationManager (org.cytoscape.application.CyApplicationManager)19 HashSet (java.util.HashSet)18 CyIdentifiable (org.cytoscape.model.CyIdentifiable)14 CyNetworkView (org.cytoscape.view.model.CyNetworkView)14 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)13 RowSetRecord (org.cytoscape.model.events.RowSetRecord)11 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)11 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)11 CyEventHelper (org.cytoscape.event.CyEventHelper)10 CyTableManager (org.cytoscape.model.CyTableManager)10