Search in sources :

Example 6 with CyRootNetworkManager

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

the class AbstractGroupTaskTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    support = new NetworkTestSupport();
    network = support.getNetwork();
    CyRootNetworkManager rootNetworkManager = new CyRootNetworkManagerImpl();
    rootNetwork = rootNetworkManager.getRootNetwork(network);
    when(registrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
    when(registrar.getService(CyNetworkViewManager.class)).thenReturn(netViewMgr);
    when(registrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    final LockedVisualPropertiesManager lvpCache = new LockedVisualPropertiesManager(registrar);
    groupManager = new CyGroupManagerImpl(registrar);
    groupFactory = new CyGroupFactoryImpl(groupManager, lvpCache);
    group1 = groupFactory.createGroup(network, true);
    rootNetwork.getRow(group1.getGroupNode(), CyRootNetwork.SHARED_ATTRS).set(CyRootNetwork.SHARED_NAME, "group1");
    group2 = groupFactory.createGroup(network, true);
    rootNetwork.getRow(group2.getGroupNode(), CyRootNetwork.SHARED_ATTRS).set(CyRootNetwork.SHARED_NAME, "group2");
    task = new AbstractGroupTask() {

        @Override
        public void run(TaskMonitor taskMonitor) throws Exception {
        }
    };
    task.net = network;
    task.groupMgr = groupManager;
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyGroupManagerImpl(org.cytoscape.group.internal.CyGroupManagerImpl) TaskMonitor(org.cytoscape.work.TaskMonitor) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) LockedVisualPropertiesManager(org.cytoscape.group.internal.LockedVisualPropertiesManager) CyGroupFactoryImpl(org.cytoscape.group.internal.CyGroupFactoryImpl) Before(org.junit.Before)

Example 7 with CyRootNetworkManager

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

the class AbstractOpenSessionTask method disposeCancelledSession.

protected void disposeCancelledSession(Exception e, CySessionManager sessionManager) {
    if (reader == null)
        return;
    final CySession newSession = reader.getSession();
    if (newSession != null) {
        // Destroy any new views and networks
        for (CyNetworkView view : newSession.getNetworkViews()) view.dispose();
        CyRootNetworkManager rootNetManager = serviceRegistrar.getService(CyRootNetworkManager.class);
        final Set<CyRootNetwork> rootNetworks = new HashSet<>();
        for (CyNetwork net : newSession.getNetworks()) rootNetworks.add(rootNetManager.getRootNetwork(net));
        for (CyRootNetwork rootNet : rootNetworks) rootNet.dispose();
    }
    // Reset the Group Manager, because groups can be registered by the reader
    // TODO Remove this after groups no longer registered inside the IO bundle.
    serviceRegistrar.getService(CyGroupManager.class).reset();
    // Destroy any global tables registered by the reader
    serviceRegistrar.getService(CyTableManager.class).reset();
    // Set a new, empty session
    sessionManager.setCurrentSession(null, null);
}
Also used : CySession(org.cytoscape.session.CySession) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyTableManager(org.cytoscape.model.CyTableManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) HashSet(java.util.HashSet)

Example 8 with CyRootNetworkManager

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

the class ImportTableDataTask method init.

private final void init() {
    this.name2NetworkMap = new HashMap<>();
    this.name2RootMap = new HashMap<>();
    this.source2targetColumnMap = new HashMap<>();
    this.mappedTables = new ArrayList<>();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    if (netMgr.getNetworkSet().size() > 0) {
        whereImportTable = new ListSingleSelection<>(NETWORK_COLLECTION, NETWORK_SELECTION, UNASSIGNED_TABLE);
        whereImportTable.setSelectedValue(NETWORK_COLLECTION);
        networksPresent = true;
    } else {
        whereImportTable = new ListSingleSelection<>(UNASSIGNED_TABLE);
        whereImportTable.setSelectedValue(UNASSIGNED_TABLE);
    }
    if (byReader) {
        if (reader != null && reader.getTables() != null)
            newTableName = reader.getTables()[0].getTitle();
    } else
        newTableName = globalTable.getTitle();
    if (networksPresent) {
        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 : netMgr.getNetworkSet()) {
            final String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
            name2NetworkMap.put(netName, net);
        }
        final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
        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);
            final CyNetwork currNet = appMgr.getCurrentNetwork();
            if (currNet != null) {
                final String currName = currNet.getRow(currNet).get(CyNetwork.NAME, String.class);
                if (currName != null && targetNetworkList.getPossibleValues().contains(currName))
                    targetNetworkList.setSelectedValues(Collections.singletonList(currName));
            }
            final List<CyNetwork> selectedNetworks = new ArrayList<>();
            for (String netName : targetNetworkList.getSelectedValues()) {
                if (name2NetworkMap.containsKey(netName))
                    selectedNetworks.add(name2NetworkMap.get(netName));
            }
            keyColumnForMappingNetworkList = getColumns(selectedNetworks, dataTypeTargetForNetworkList.getSelectedValue(), CyRootNetwork.DEFAULT_ATTRS);
        }
        final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
        for (CyNetwork net : netMgr.getNetworkSet()) {
            final CyRootNetwork rootNet = rootNetMgr.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));
            final CyNetwork currNet = appMgr.getCurrentNetwork();
            final CyRootNetwork currRootNet = currNet instanceof CySubNetwork ? rootNetMgr.getRootNetwork(currNet) : null;
            if (currRootNet != null) {
                final String currName = currRootNet.getRow(currRootNet).get(CyNetwork.NAME, String.class);
                if (currName != null && targetNetworkCollection.getPossibleValues().contains(currName))
                    targetNetworkCollection.setSelectedValue(currName);
            }
            keyColumnForMapping = getColumns(Collections.singletonList(name2RootMap.get(targetNetworkCollection.getSelectedValue())), dataTypeTargetForNetworkCollection.getSelectedValue(), CyRootNetwork.SHARED_ATTRS);
        }
    }
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 9 with CyRootNetworkManager

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

the class Cy3SessionReaderImplTest method setUp.

@Before
public void setUp() {
    InputStream is = mock(InputStream.class);
    GroupUtil groupUtil = mock(GroupUtil.class);
    SUIDUpdater suidUpdater = mock(SUIDUpdater.class);
    CyNetworkReaderManager netReaderMgr = mock(CyNetworkReaderManager.class);
    CyPropertyReaderManager propReaderMgr = mock(CyPropertyReaderManager.class);
    VizmapReaderManager vizmapReaderMgr = mock(VizmapReaderManager.class);
    CSVCyReaderFactory csvCyReaderFactory = mock(CSVCyReaderFactory.class);
    CyNetworkTableManager netTblMgr = mock(CyNetworkTableManager.class);
    CyRootNetworkManager rootNetMgr = mock(CyRootNetworkManager.class);
    EquationCompiler compiler = mock(EquationCompiler.class);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyNetworkTableManager.class)).thenReturn(netTblMgr);
    when(serviceRegistrar.getService(CyRootNetworkManager.class)).thenReturn(rootNetMgr);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    ReadCache cache = new ReadCache(serviceRegistrar);
    reader = new Cy3SessionReaderImpl(is, cache, groupUtil, suidUpdater, netReaderMgr, propReaderMgr, vizmapReaderMgr, csvCyReaderFactory, serviceRegistrar);
    tblTestSupport = new TableTestSupport();
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) InputStream(java.io.InputStream) CyNetworkReaderManager(org.cytoscape.io.read.CyNetworkReaderManager) ReadCache(org.cytoscape.io.internal.util.ReadCache) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) GroupUtil(org.cytoscape.io.internal.util.GroupUtil) VizmapReaderManager(org.cytoscape.io.read.VizmapReaderManager) CyPropertyReaderManager(org.cytoscape.io.read.CyPropertyReaderManager) TableTestSupport(org.cytoscape.model.TableTestSupport) SUIDUpdater(org.cytoscape.io.internal.util.SUIDUpdater) CSVCyReaderFactory(org.cytoscape.io.internal.read.datatable.CSVCyReaderFactory) EquationCompiler(org.cytoscape.equations.EquationCompiler) Before(org.junit.Before)

Example 10 with CyRootNetworkManager

use of org.cytoscape.model.subnetwork.CyRootNetworkManager 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)

Aggregations

CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)18 CyNetwork (org.cytoscape.model.CyNetwork)13 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)9 CyApplicationManager (org.cytoscape.application.CyApplicationManager)8 CyNetworkManager (org.cytoscape.model.CyNetworkManager)8 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)7 CyGroupManager (org.cytoscape.group.CyGroupManager)6 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)6 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)5 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)5 HashSet (java.util.HashSet)4 CyEventHelper (org.cytoscape.event.CyEventHelper)4 CyTableManager (org.cytoscape.model.CyTableManager)4 CyLayoutAlgorithmManager (org.cytoscape.view.layout.CyLayoutAlgorithmManager)4 TaskIterator (org.cytoscape.work.TaskIterator)4 UndoSupport (org.cytoscape.work.undo.UndoSupport)4 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)3 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)3