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;
}
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);
}
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);
}
}
}
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();
}
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;
}
}
Aggregations