use of org.cytoscape.application.CyApplicationManager 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.application.CyApplicationManager in project clusterMaker2 by RBVI.
the class CyActivator method start.
public void start(BundleContext bc) {
// See if we have a graphics console or not
boolean haveGUI = true;
CySwingApplication swingAppRef = getService(bc, CySwingApplication.class);
if (swingAppRef == null) {
// if haveGUI is false, we don't want to provide any hooks to the treeview
haveGUI = false;
}
CyApplicationManager appRef = getService(bc, CyApplicationManager.class);
CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
CyGroupManager groupManager = getService(bc, CyGroupManager.class);
CyGroupFactory groupFactory = getService(bc, CyGroupFactory.class);
CyTableFactory tableFactory = getService(bc, CyTableFactory.class);
CyTableManager tableManager = getService(bc, CyTableManager.class);
// Create our context object. This will probably keep track of all of the
// registered clustering algorithms, settings, etc.
ClusterManagerImpl clusterManager = new ClusterManagerImpl(appRef, serviceRegistrar, groupFactory, groupManager, tableFactory, tableManager);
registerServiceListener(bc, clusterManager, "addClusterAlgorithm", "removeClusterAlgorithm", ClusterTaskFactory.class);
registerServiceListener(bc, clusterManager, "addClusterVisualizer", "removeClusterVisualizer", ClusterVizFactory.class);
registerServiceListener(bc, clusterManager, "addRankingAlgorithm", "removeRankingAlgorithm", RankFactory.class);
// Register each of our algorithms
// Attribute clusterers
registerService(bc, new AttributeClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new AutoSOMETaskFactory(clusterManager, true), ClusterTaskFactory.class, new Properties());
registerService(bc, new FeatureVectorTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new HierarchicalTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new KMeansTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new KMedoidTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new HopachPAMTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new PAMTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// FIXME: FFT is seriously broken!
registerService(bc, new FFTTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new DBSCANTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
/*
* Hold off on these until we get improve the performance sufficiently
* to allow them to be useful
*/
// registerService(bc, new BicFinderTaskFactory(clusterManager),
// ClusterTaskFactory.class, new Properties());
// registerService(bc, new BiMineTaskFactory(clusterManager),
// ClusterTaskFactory.class, new Properties());
registerService(bc, new ChengChurchTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// Network clusterers
registerService(bc, new NetworkClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new APClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new AutoSOMETaskFactory(clusterManager, false), ClusterTaskFactory.class, new Properties());
registerService(bc, new FuzzifierTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new GLayClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new ConnectedComponentsTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new FCMClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new MCLClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new MCODEClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new SCPSClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new TransClustClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// Cluster ranking
registerService(bc, new MAATaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new MAMTaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new PRWPTaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new PRTaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new HITSTaskFactory(clusterManager), RankFactory.class, new Properties());
// Filters
registerService(bc, new FilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new BestNeighborFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new CuttingEdgeFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new DensityFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new HairCutFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// registerService(bc, new UITaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// Visualizations
registerService(bc, new NewNetworkViewFactory(clusterManager, false), ClusterVizFactory.class, new Properties());
registerService(bc, new NewNetworkViewFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new HeatMapViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new KnnViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new BiclusterViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new TreeViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new CreateResultsPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new CreateRankingPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new DestroyResultsPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new DestroyRankingPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
// Dimensionality Reduction
// registerService(bc, new PCAMenuTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new PCATaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new PCoATaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new tSNETaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
{
// Link Network Selections
LinkSelectionTaskFactory linkTaskFactory = new LinkSelectionTaskFactory(clusterManager);
Properties linkSelectionProps = new Properties();
linkSelectionProps.setProperty(INSERT_SEPARATOR_BEFORE, "true");
linkSelectionProps.setProperty(PREFERRED_MENU, "Apps.clusterMaker Visualizations");
linkSelectionProps.setProperty(TITLE, "Link selection across networks");
linkSelectionProps.setProperty(COMMAND, "linkSelection");
linkSelectionProps.setProperty(COMMAND_NAMESPACE, "clusterviz");
linkSelectionProps.setProperty(ENABLE_FOR, "networkAndView");
linkSelectionProps.setProperty(IN_MENU_BAR, "true");
linkSelectionProps.setProperty(MENU_GRAVITY, "100.0");
registerService(bc, linkTaskFactory, NetworkTaskFactory.class, linkSelectionProps);
}
{
// UnLink Network Selections
UnlinkSelectionTaskFactory unlinkTaskFactory = new UnlinkSelectionTaskFactory(clusterManager);
Properties unlinkSelectionProps = new Properties();
unlinkSelectionProps.setProperty(PREFERRED_MENU, "Apps.clusterMaker Visualizations");
unlinkSelectionProps.setProperty(TITLE, "Unlink selection across networks");
unlinkSelectionProps.setProperty(COMMAND, "unlinkSelection");
unlinkSelectionProps.setProperty(COMMAND_NAMESPACE, "clusterviz");
unlinkSelectionProps.setProperty(ENABLE_FOR, "networkAndView");
unlinkSelectionProps.setProperty(IN_MENU_BAR, "true");
unlinkSelectionProps.setProperty(MENU_GRAVITY, "100.0");
registerService(bc, unlinkTaskFactory, NetworkTaskFactory.class, unlinkSelectionProps);
}
// Commands
// These task factories provide useful commands that only make sense in the context of REST or
// the command interface
{
TaskFactory commandTaskFactory = new CommandTaskFactory(clusterManager, "hascluster");
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "cluster");
props.setProperty(COMMAND, CommandTaskFactory.HASCLUSTER);
props.setProperty(COMMAND_DESCRIPTION, "Test to see if this network has a cluster of the requested type");
registerService(bc, commandTaskFactory, TaskFactory.class, props);
}
{
TaskFactory commandTaskFactory = new CommandTaskFactory(clusterManager, "getnetworkcluster");
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "cluster");
props.setProperty(COMMAND, CommandTaskFactory.GETNETWORKCLUSTER);
props.setProperty(COMMAND_DESCRIPTION, "Get a cluster network cluster result");
registerService(bc, commandTaskFactory, TaskFactory.class, props);
}
{
TaskFactory commandTaskFactory = new CommandTaskFactory(clusterManager, "getcluster");
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "cluster");
props.setProperty(COMMAND, CommandTaskFactory.GETCLUSTER);
props.setProperty(COMMAND_DESCRIPTION, "Get an attribute cluster result");
registerService(bc, commandTaskFactory, TaskFactory.class, props);
}
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-api by cytoscape.
the class SetCurrentNetworkViewEventTest method testGoodGetNetworkView.
@Test
public void testGoodGetNetworkView() {
CyApplicationManager source = mock(CyApplicationManager.class);
CyNetworkView n = mock(CyNetworkView.class);
SetCurrentNetworkViewEvent e = new SetCurrentNetworkViewEvent(source, n);
assertNotNull(e.getNetworkView());
assertEquals(n, e.getNetworkView());
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method restoreNetworkViews.
private void restoreNetworkViews(final CySession sess, List<CyNetwork> selectedNetworks) {
logger.debug("Restoring network views...");
Set<CyNetworkView> netViews = sess.getNetworkViews();
List<CyNetworkView> selectedViews = new ArrayList<>();
for (CyNetworkView nv : netViews) {
CyNetwork network = nv.getModel();
if (selectedNetworks.contains(network)) {
selectedViews.add(nv);
}
}
Map<CyNetworkView, Map<VisualProperty<?>, Object>> viewVPMap = new HashMap<>();
if (netViews != null) {
final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
for (CyNetworkView nv : netViews) {
if (nv != null) {
// Save the original values of these visual properties,
// because we will have to set them again after the views are rendered
Map<VisualProperty<?>, Object> vpMap = new HashMap<>();
viewVPMap.put(nv, vpMap);
vpMap.put(BasicVisualLexicon.NETWORK_HEIGHT, nv.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT));
vpMap.put(BasicVisualLexicon.NETWORK_WIDTH, nv.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH));
nvMgr.addNetworkView(nv, false);
}
}
}
// Let's guarantee the network views are rendered
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
// Set the saved visual properties again, because the renderer may have overwritten the original values
for (Entry<CyNetworkView, Map<VisualProperty<?>, Object>> entry1 : viewVPMap.entrySet()) {
CyNetworkView nv = entry1.getKey();
for (Entry<VisualProperty<?>, Object> entry2 : entry1.getValue().entrySet()) nv.setVisualProperty(entry2.getKey(), entry2.getValue());
}
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
if (!selectedViews.isEmpty())
appMgr.setCurrentNetworkView(selectedViews.get(0));
appMgr.setSelectedNetworkViews(selectedViews);
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class CyNetworkManagerImpl method addNetwork.
@Override
public void addNetwork(final CyNetwork network, final boolean setCurrent) {
if (network == null)
throw new NullPointerException("Network is null");
synchronized (lock) {
logger.debug("Adding new Network Model: Model ID = " + network.getSUID());
// Make sure the network has a name
final CyRow row = network.getRow(network);
final String name = row.get(CyNetwork.NAME, String.class);
final String sharedName = row.get(CyRootNetwork.SHARED_NAME, String.class);
if (name != null && !name.trim().isEmpty() && (sharedName == null || sharedName.trim().isEmpty())) {
row.set(CyRootNetwork.SHARED_NAME, name);
} else if (sharedName != null && !sharedName.trim().isEmpty() && (name == null || name.trim().isEmpty())) {
row.set(CyNetwork.NAME, sharedName);
} else if ((sharedName == null || sharedName.trim().isEmpty()) && (name == null || name.trim().isEmpty())) {
final CyNetworkNaming namingUtil = serviceRegistrar.getService(CyNetworkNaming.class);
final String newName = namingUtil.getSuggestedNetworkTitle("Network");
row.set(CyNetwork.NAME, newName);
row.set(CyRootNetwork.SHARED_NAME, newName);
}
// Add the new network to the internal map
networkMap.put(network.getSUID(), network);
}
final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
cyEventHelper.fireEvent(new NetworkAddedEvent(CyNetworkManagerImpl.this, network));
if (setCurrent) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
if (// It may be null when running unit tests
applicationManager != null)
applicationManager.setCurrentNetwork(network);
}
}
Aggregations