Search in sources :

Example 56 with CyNetwork

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

the class DetermineDistinctValuesTask method run.

/**
 *  DOCUMENT ME!
 */
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(-1);
    // Obtain distinct attribute values
    CyNetwork network = applicationManager.getCurrentNetwork();
    Iterator<? extends CyIdentifiable> iterator;
    if (parentDialog.getIndexType() == QuickFind.INDEX_NODES) {
        iterator = network.getNodeList().iterator();
    } else {
        iterator = network.getEdgeList().iterator();
    }
    String[] values = CyAttributesUtil.getDistinctAttributeValues(network, iterator, attributeKey, 5);
    if ((values != null) && (values.length > 0)) {
        for (int i = 0; i < values.length; i++) {
            tableModel.setValueAt(values[i], i, 0);
        }
        parentDialog.enableApplyButton(true);
    } else {
        VisualLexicon lexicon = applicationManager.getCurrentRenderingEngine().getVisualLexicon();
        CyNetworkView view = applicationManager.getCurrentNetworkView();
        String title = VisualPropertyUtil.get(lexicon, view, "NETWORK_TITLE", BasicVisualLexicon.NETWORK, String.class);
        tableModel.setValueAt("No values found in network:  " + title + ".  Cannot create index.", 0, 0);
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 57 with CyNetwork

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

the class FilterUtil method isDynamicFilter.

// If a network size (node count and edge count) is less than DYNAMIC_FILTER_THRESHOLD, return true
// Otherwise, return false
public static boolean isDynamicFilter(CompositeFilter pFilter) {
    CyNetwork theNetwork = pFilter.getNetwork();
    if (theNetwork == null) {
        return false;
    }
    int nodeCount = theNetwork.getNodeCount();
    int edgeCount = theNetwork.getEdgeCount();
    int dynamicFilterThresholdValue = -1;
    // // TODO: What do we do about CyInit*?
    // String dynamicFilterThreshold = CytoscapeInit.getProperties().getProperty(DYNAMIC_FILTER_THRESHOLD);
    // if (dynamicFilterThreshold == null) { // threshold not defined, use the default value
    dynamicFilterThresholdValue = DEFAULT_DYNAMIC_FILTER_THRESHOLD;
    if (pFilter.getAdvancedSetting().isNodeChecked() && pFilter.getAdvancedSetting().isEdgeChecked()) {
        // Select both nodes and edges
        if (nodeCount > dynamicFilterThresholdValue || edgeCount > dynamicFilterThresholdValue) {
            return false;
        }
        return true;
    } else if (pFilter.getAdvancedSetting().isNodeChecked()) {
        // Select node only
        if (nodeCount < dynamicFilterThresholdValue) {
            return true;
        }
    } else if (pFilter.getAdvancedSetting().isEdgeChecked()) {
        // select edge only
        if (edgeCount < dynamicFilterThresholdValue) {
            return true;
        }
    }
    return false;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork)

Example 58 with CyNetwork

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

the class CySessionManagerImpl method getCurrentSession.

@Override
public CySession getCurrentSession() {
    // Apps who want to save anything to a session will have to listen for this event
    // and will then be responsible for adding files through SessionAboutToBeSavedEvent.addAppFiles(..)
    final SessionAboutToBeSavedEvent savingEvent = new SessionAboutToBeSavedEvent(this);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(savingEvent);
    final Set<CyNetwork> networks = getSerializableNetworks();
    final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
    // Visual Styles Map
    final Map<CyNetworkView, String> stylesMap = new HashMap<>();
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    if (netViews != null) {
        for (final CyNetworkView nv : netViews) {
            final VisualStyle style = vmMgr.getVisualStyle(nv);
            if (style != null)
                stylesMap.put(nv, style.getTitle());
        }
    }
    final Map<String, List<File>> appMap = savingEvent.getAppFileListMap();
    final Set<CyTableMetadata> metadata = createTablesMetadata(networks);
    final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
    final Set<CyProperty<?>> props = getAllProperties();
    // Build the session
    final CySession sess = new CySession.Builder().properties(props).appFileListMap(appMap).tables(metadata).networks(networks).networkViews(netViews).visualStyles(styles).viewVisualStyleMap(stylesMap).build();
    return sess;
}
Also used : CySession(org.cytoscape.session.CySession) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) SessionAboutToBeSavedEvent(org.cytoscape.session.events.SessionAboutToBeSavedEvent) CyTableMetadata(org.cytoscape.model.CyTableMetadata) ArrayList(java.util.ArrayList) List(java.util.List) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 59 with CyNetwork

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

the class CySessionManagerImpl method restoreNetworkSelection.

private void restoreNetworkSelection(final CySession sess, final List<CyNetwork> selectedNets) {
    // If the current view/network was not set, set the first selected network as current
    if (!selectedNets.isEmpty()) {
        final CyNetwork cn = selectedNets.get(0);
        final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
        appMgr.setCurrentNetwork(cn);
        // Also set the current view, if there is one
        final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
        final Collection<CyNetworkView> cnViews = nvMgr.getNetworkViews(cn);
        final CyNetworkView cv = cnViews.isEmpty() ? null : cnViews.iterator().next();
        appMgr.setCurrentNetworkView(cv);
        // The selected networks must be set after setting the current one!
        appMgr.setSelectedNetworks(selectedNets);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 60 with CyNetwork

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

the class CySessionManagerImpl method restoreNetworks.

private void restoreNetworks(final CySession sess) {
    logger.debug("Restoring networks...");
    Set<CyNetwork> networks = sess.getNetworks();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    for (CyNetwork n : networks) {
        netMgr.addNetwork(n, false);
    }
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)517 CyNode (org.cytoscape.model.CyNode)183 CyNetworkView (org.cytoscape.view.model.CyNetworkView)129 CyEdge (org.cytoscape.model.CyEdge)108 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)87 CyTable (org.cytoscape.model.CyTable)75 CyApplicationManager (org.cytoscape.application.CyApplicationManager)70 CyIdentifiable (org.cytoscape.model.CyIdentifiable)57 CyRow (org.cytoscape.model.CyRow)48 HashSet (java.util.HashSet)45 CyNetworkManager (org.cytoscape.model.CyNetworkManager)40 HashMap (java.util.HashMap)35 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)32 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)31 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)30 AbstractNetworkReaderTest (org.cytoscape.io.internal.read.AbstractNetworkReaderTest)27 TaskIterator (org.cytoscape.work.TaskIterator)27 List (java.util.List)26