use of org.cytoscape.view.layout.CyLayoutAlgorithmManager in project cytoscape-impl by cytoscape.
the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.
@Test
public void testObserver() throws Exception {
NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
NetworkTestSupport networkSupport = new NetworkTestSupport();
CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
UndoSupport undoSupport = mock(UndoSupport.class);
CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
CyNetworkManager netmgr = mock(CyNetworkManager.class);
CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
CyNetworkNaming naming = mock(CyNetworkNaming.class);
VisualMappingManager vmm = mock(VisualMappingManager.class);
CyApplicationManager appManager = mock(CyApplicationManager.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
CyGroupManager groupMgr = mock(CyGroupManager.class);
RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
CyNetwork network = networkFactory.createNetwork();
CyNode node = network.addNode();
network.getRow(node).set(CyNetwork.SELECTED, true);
TaskObserver observer = mock(TaskObserver.class);
TaskMonitor taskMonitor = mock(TaskMonitor.class);
TaskIterator iterator = factory.createTaskIterator(network);
while (iterator.hasNext()) {
Task t = iterator.next();
t.run(taskMonitor);
if (t instanceof ObservableTask)
observer.taskFinished((ObservableTask) t);
}
verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
use of org.cytoscape.view.layout.CyLayoutAlgorithmManager in project cytoscape-impl by cytoscape.
the class CyActivator method start.
@Override
public void start(BundleContext bc) {
CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
CyApplicationConfiguration cyApplicationConfigurationRef = getService(bc, CyApplicationConfiguration.class);
CyApplicationManager cyApplicationManagerRef = getService(bc, CyApplicationManager.class);
CyEventHelper cyEventHelperRef = getService(bc, CyEventHelper.class);
CyGroupAggregationManager cyGroupAggregationManagerRef = getService(bc, CyGroupAggregationManager.class);
CyGroupFactory cyGroupFactoryRef = getService(bc, CyGroupFactory.class);
CyGroupManager cyGroupManagerRef = getService(bc, CyGroupManager.class);
CyLayoutAlgorithmManager cyLayoutAlgorithmManagerRef = getService(bc, CyLayoutAlgorithmManager.class);
CyNetworkFactory cyNetworkFactoryRef = getService(bc, CyNetworkFactory.class);
CyNetworkManager cyNetworkManagerRef = getService(bc, CyNetworkManager.class);
CyNetworkViewFactory cyNetworkViewFactoryRef = getService(bc, CyNetworkViewFactory.class);
CyNetworkViewManager cyNetworkViewManagerRef = getService(bc, CyNetworkViewManager.class);
CyNetworkReaderManager cyNetworkViewReaderManagerRef = getService(bc, CyNetworkReaderManager.class);
CyNetworkViewWriterManager cyNetworkViewWriterManagerRef = getService(bc, CyNetworkViewWriterManager.class);
CyProperty<Properties> cyPropertyRef = getService(bc, CyProperty.class, "(cyPropertyName=cytoscape3.props)");
CyPropertyReaderManager cyPropertyReaderManagerRef = getService(bc, CyPropertyReaderManager.class);
CyPropertyWriterManager cyPropertyWriterManagerRef = getService(bc, CyPropertyWriterManager.class);
CyRootNetworkManager cyRootNetworkFactoryRef = getService(bc, CyRootNetworkManager.class);
CySessionManager cySessionManagerRef = getService(bc, CySessionManager.class);
CySessionReaderManager cySessionReaderManagerRef = getService(bc, CySessionReaderManager.class);
CySessionWriterManager cySessionWriterManagerRef = getService(bc, CySessionWriterManager.class);
CySwingApplication cySwingApplicationRef = getService(bc, CySwingApplication.class);
CyTableFactory cyTableFactoryRef = getService(bc, CyTableFactory.class);
CyTableManager cyTableManagerRef = getService(bc, CyTableManager.class);
CyTableReaderManager cyTableReaderManagerRef = getService(bc, CyTableReaderManager.class);
CyTableWriterManager cyTableWriterManagerRef = getService(bc, CyTableWriterManager.class);
PanelTaskManager panelTaskManagerRef = getService(bc, PanelTaskManager.class);
DialogTaskManager dialogTaskManagerRef = getService(bc, DialogTaskManager.class);
PresentationWriterManager presentationWriterManagerRef = getService(bc, PresentationWriterManager.class);
RenderingEngineManager renderingEngineManagerRef = getService(bc, RenderingEngineManager.class);
TaskManager taskManagerRef = getService(bc, TaskManager.class);
UndoSupport undoSupportRef = getService(bc, UndoSupport.class);
TunablePropertySerializerFactory tunablePropertySerializerFactoryRef = getService(bc, TunablePropertySerializerFactory.class);
VisualMappingManager visualMappingManagerRef = getService(bc, VisualMappingManager.class);
VisualStyleFactory visualStyleFactoryRef = getService(bc, VisualStyleFactory.class);
CyVersion cytoscapeVersionService = getService(bc, CyVersion.class);
CyApplicationConfiguration cyApplicationConfigurationServiceRef = getService(bc, CyApplicationConfiguration.class);
VisualMappingFunctionFactory vmfFactoryC = getService(bc, VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
VisualMappingFunctionFactory vmfFactoryD = getService(bc, VisualMappingFunctionFactory.class, "(mapping.type=discrete)");
VisualMappingFunctionFactory vmfFactoryP = getService(bc, VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
DataSourceManager dataSourceManager = getService(bc, DataSourceManager.class);
// Start of core-task services
LoadVizmapFileTaskFactory loadVizmapFileTaskFactory = getService(bc, LoadVizmapFileTaskFactory.class);
LoadNetworkFileTaskFactory loadNetworkFileTaskFactory = getService(bc, LoadNetworkFileTaskFactory.class);
LoadNetworkURLTaskFactory loadNetworkURLTaskFactory = getService(bc, LoadNetworkURLTaskFactory.class);
DeleteSelectedNodesAndEdgesTaskFactory deleteSelectedNodesAndEdgesTaskFactory = getService(bc, DeleteSelectedNodesAndEdgesTaskFactory.class);
SelectAllTaskFactory selectAllTaskFactory = getService(bc, SelectAllTaskFactory.class);
SelectAllEdgesTaskFactory selectAllEdgesTaskFactory = getService(bc, SelectAllEdgesTaskFactory.class);
SelectAllNodesTaskFactory selectAllNodesTaskFactory = getService(bc, SelectAllNodesTaskFactory.class);
SelectAdjacentEdgesTaskFactory selectAdjacentEdgesTaskFactory = getService(bc, SelectAdjacentEdgesTaskFactory.class);
SelectConnectedNodesTaskFactory selectConnectedNodesTaskFactory = getService(bc, SelectConnectedNodesTaskFactory.class);
SelectFirstNeighborsTaskFactory selectFirstNeighborsTaskFactory = getService(bc, SelectFirstNeighborsTaskFactory.class, "(title=Undirected)");
SelectFirstNeighborsTaskFactory selectFirstNeighborsTaskFactoryInEdge = getService(bc, SelectFirstNeighborsTaskFactory.class, "(title=Directed: Incoming)");
SelectFirstNeighborsTaskFactory selectFirstNeighborsTaskFactoryOutEdge = getService(bc, SelectFirstNeighborsTaskFactory.class, "(title=Directed: Outgoing)");
DeselectAllTaskFactory deselectAllTaskFactory = getService(bc, DeselectAllTaskFactory.class);
DeselectAllEdgesTaskFactory deselectAllEdgesTaskFactory = getService(bc, DeselectAllEdgesTaskFactory.class);
DeselectAllNodesTaskFactory deselectAllNodesTaskFactory = getService(bc, DeselectAllNodesTaskFactory.class);
InvertSelectedEdgesTaskFactory invertSelectedEdgesTaskFactory = getService(bc, InvertSelectedEdgesTaskFactory.class);
InvertSelectedNodesTaskFactory invertSelectedNodesTaskFactory = getService(bc, InvertSelectedNodesTaskFactory.class);
SelectFromFileListTaskFactory selectFromFileListTaskFactory = getService(bc, SelectFromFileListTaskFactory.class);
SelectFirstNeighborsNodeViewTaskFactory selectFirstNeighborsNodeViewTaskFactory = getService(bc, SelectFirstNeighborsNodeViewTaskFactory.class);
HideSelectedTaskFactory hideSelectedTaskFactory = getService(bc, HideSelectedTaskFactory.class);
HideSelectedNodesTaskFactory hideSelectedNodesTaskFactory = getService(bc, HideSelectedNodesTaskFactory.class);
HideSelectedEdgesTaskFactory hideSelectedEdgesTaskFactory = getService(bc, HideSelectedEdgesTaskFactory.class);
UnHideAllTaskFactory unHideAllTaskFactory = getService(bc, UnHideAllTaskFactory.class);
UnHideAllNodesTaskFactory unHideAllNodesTaskFactory = getService(bc, UnHideAllNodesTaskFactory.class);
UnHideAllEdgesTaskFactory unHideAllEdgesTaskFactory = getService(bc, UnHideAllEdgesTaskFactory.class);
NewEmptyNetworkViewFactory newEmptyNetworkTaskFactory = getService(bc, NewEmptyNetworkViewFactory.class);
CloneNetworkTaskFactory cloneNetworkTaskFactory = getService(bc, CloneNetworkTaskFactory.class);
NewNetworkSelectedNodesAndEdgesTaskFactory newNetworkSelectedNodesEdgesTaskFactory = getService(bc, NewNetworkSelectedNodesAndEdgesTaskFactory.class);
NewNetworkSelectedNodesOnlyTaskFactory newNetworkSelectedNodesOnlyTaskFactory = getService(bc, NewNetworkSelectedNodesOnlyTaskFactory.class);
DestroyNetworkTaskFactory destroyNetworkTaskFactory = getService(bc, DestroyNetworkTaskFactory.class);
DestroyNetworkViewTaskFactory destroyNetworkViewTaskFactory = getService(bc, DestroyNetworkViewTaskFactory.class);
NewSessionTaskFactory newSessionTaskFactory = getService(bc, NewSessionTaskFactory.class);
OpenSessionTaskFactory openSessionTaskFactory = getService(bc, OpenSessionTaskFactory.class);
SaveSessionAsTaskFactory saveSessionAsTaskFactory = getService(bc, SaveSessionAsTaskFactory.class);
EditNetworkTitleTaskFactory editNetworkTitleTaskFactory = getService(bc, EditNetworkTitleTaskFactory.class);
CreateNetworkViewTaskFactory createNetworkViewTaskFactory = getService(bc, CreateNetworkViewTaskFactory.class);
ExportNetworkImageTaskFactory exportNetworkImageTaskFactory = getService(bc, ExportNetworkImageTaskFactory.class);
ExportNetworkViewTaskFactory exportNetworkViewTaskFactory = getService(bc, ExportNetworkViewTaskFactory.class);
ExportSelectedTableTaskFactory exportSelectedTableTaskFactory = getService(bc, ExportSelectedTableTaskFactory.class);
ExportTableTaskFactory exportTableTaskFactory = getService(bc, ExportTableTaskFactory.class);
ApplyPreferredLayoutTaskFactory applyPreferredLayoutTaskFactory = getService(bc, ApplyPreferredLayoutTaskFactory.class);
DeleteColumnTaskFactory deleteColumnTaskFactory = getService(bc, DeleteColumnTaskFactory.class);
RenameColumnTaskFactory renameColumnTaskFactory = getService(bc, RenameColumnTaskFactory.class);
DeleteTableTaskFactory deleteTableTaskFactory = getService(bc, DeleteTableTaskFactory.class);
ExportVizmapTaskFactory exportVizmapTaskFactory = getService(bc, ExportVizmapTaskFactory.class);
ConnectSelectedNodesTaskFactory connectSelectedNodesTaskFactory = getService(bc, ConnectSelectedNodesTaskFactory.class);
MapGlobalToLocalTableTaskFactory mapGlobal = getService(bc, MapGlobalToLocalTableTaskFactory.class);
ApplyVisualStyleTaskFactory applyVisualStyleTaskFactory = getService(bc, ApplyVisualStyleTaskFactory.class);
MapTableToNetworkTablesTaskFactory mapNetworkAttrTaskFactory = getService(bc, MapTableToNetworkTablesTaskFactory.class);
GroupNodesTaskFactory groupNodesTaskFactory = getService(bc, GroupNodesTaskFactory.class);
UnGroupTaskFactory unGroupTaskFactory = getService(bc, UnGroupTaskFactory.class);
CollapseGroupTaskFactory collapseGroupTaskFactory = getService(bc, CollapseGroupTaskFactory.class);
ExpandGroupTaskFactory expandGroupTaskFactory = getService(bc, ExpandGroupTaskFactory.class);
UnGroupNodesTaskFactory unGroupNodesTaskFactory = getService(bc, UnGroupNodesTaskFactory.class);
// End of core-task services
// Command execution services
CommandExecutorTaskFactory cyCommandExecutorTaskFactory = getService(bc, CommandExecutorTaskFactory.class);
AvailableCommands availableCommands = getService(bc, AvailableCommands.class);
StreamUtil streamUtilServiceRef = getService(bc, StreamUtil.class);
FileUtil fileUtilServiceRef = getService(bc, FileUtil.class);
CySwingAppAdapter cyAppAdapter = new CyAppAdapterImpl(cyApplicationConfigurationRef, cyApplicationManagerRef, cyEventHelperRef, cyGroupAggregationManagerRef, cyGroupFactoryRef, cyGroupManagerRef, cyLayoutAlgorithmManagerRef, cyNetworkFactoryRef, cyNetworkManagerRef, cyNetworkViewFactoryRef, cyNetworkViewManagerRef, cyNetworkViewReaderManagerRef, cyNetworkViewWriterManagerRef, cyPropertyRef, cyPropertyReaderManagerRef, cyPropertyWriterManagerRef, cyRootNetworkFactoryRef, serviceRegistrar, cySessionManagerRef, cySessionReaderManagerRef, cySessionWriterManagerRef, cySwingApplicationRef, cyTableFactoryRef, cyTableManagerRef, cyTableReaderManagerRef, cyTableWriterManagerRef, cytoscapeVersionService, dialogTaskManagerRef, panelTaskManagerRef, presentationWriterManagerRef, renderingEngineManagerRef, taskManagerRef, undoSupportRef, tunablePropertySerializerFactoryRef, vmfFactoryC, vmfFactoryD, vmfFactoryP, visualMappingManagerRef, visualStyleFactoryRef, dataSourceManager, // from core-task-api
loadVizmapFileTaskFactory, loadNetworkFileTaskFactory, loadNetworkURLTaskFactory, deleteSelectedNodesAndEdgesTaskFactory, selectAllTaskFactory, selectAllEdgesTaskFactory, selectAllNodesTaskFactory, selectAdjacentEdgesTaskFactory, selectConnectedNodesTaskFactory, selectFirstNeighborsTaskFactory, selectFirstNeighborsTaskFactoryInEdge, selectFirstNeighborsTaskFactoryOutEdge, deselectAllTaskFactory, deselectAllEdgesTaskFactory, deselectAllNodesTaskFactory, invertSelectedEdgesTaskFactory, invertSelectedNodesTaskFactory, selectFromFileListTaskFactory, selectFirstNeighborsNodeViewTaskFactory, hideSelectedTaskFactory, hideSelectedNodesTaskFactory, hideSelectedEdgesTaskFactory, unHideAllTaskFactory, unHideAllNodesTaskFactory, unHideAllEdgesTaskFactory, newEmptyNetworkTaskFactory, cloneNetworkTaskFactory, newNetworkSelectedNodesEdgesTaskFactory, newNetworkSelectedNodesOnlyTaskFactory, destroyNetworkTaskFactory, destroyNetworkViewTaskFactory, newSessionTaskFactory, openSessionTaskFactory, saveSessionAsTaskFactory, editNetworkTitleTaskFactory, createNetworkViewTaskFactory, exportNetworkImageTaskFactory, exportNetworkViewTaskFactory, exportSelectedTableTaskFactory, exportTableTaskFactory, applyPreferredLayoutTaskFactory, deleteColumnTaskFactory, renameColumnTaskFactory, deleteTableTaskFactory, exportVizmapTaskFactory, connectSelectedNodesTaskFactory, mapGlobal, applyVisualStyleTaskFactory, mapNetworkAttrTaskFactory, groupNodesTaskFactory, unGroupTaskFactory, collapseGroupTaskFactory, expandGroupTaskFactory, unGroupNodesTaskFactory, cyCommandExecutorTaskFactory, availableCommands);
registerService(bc, cyAppAdapter, CyAppAdapter.class);
registerService(bc, cyAppAdapter, CySwingAppAdapter.class);
WebQuerier webQuerier = new WebQuerier(streamUtilServiceRef, cytoscapeVersionService);
registerService(bc, webQuerier, WebQuerier.class);
StartLevel startLevel = getService(bc, StartLevel.class);
// Instantiate new manager
final AppManager appManager = new AppManager(cyAppAdapter, cyApplicationConfigurationServiceRef, cytoscapeVersionService, cyEventHelperRef, webQuerier, startLevel, bc);
registerService(bc, appManager, AppManager.class);
bc.addFrameworkListener(appManager);
final DownloadSitesManager downloadSitesManager = new DownloadSitesManager(cyPropertyRef);
final UpdateManager updateManager = new UpdateManager(appManager, downloadSitesManager);
registerService(bc, updateManager, AppsFinishedStartingListener.class);
final AppConflictHandlerFactory appConflictHandlerFactory = new AppConflictHandlerFactory();
registerService(bc, appConflictHandlerFactory, GUITunableHandlerFactory.class);
// AbstractCyAction implementation for updated app manager
AppManagerAction appManagerAction = new AppManagerAction(appManager, downloadSitesManager, updateManager, cySwingApplicationRef, fileUtilServiceRef, dialogTaskManagerRef, serviceRegistrar);
registerService(bc, appManagerAction, CyAction.class);
// Show citations dialog
final CitationsAction citationsAction = new CitationsAction(webQuerier, appManager, serviceRegistrar);
registerService(bc, citationsAction, CyAction.class);
// Start local server that reports app installation status to the app store when requested,
// also able to install an app when told by the app store
final AppGetResponder appGetResponder = new AppGetResponder(appManager, cytoscapeVersionService);
final CyHttpd httpd = (new CyHttpdFactoryImpl()).createHttpd(new LocalhostServerSocketFactory(2607));
httpd.addBeforeResponse(new ScreenOriginsBeforeResponse(WebQuerier.DEFAULT_APP_STORE_URL));
httpd.addBeforeResponse(new OriginOptionsBeforeResponse("x-csrftoken"));
httpd.addAfterResponse(new AddAllowOriginHeader());
httpd.addResponder(appGetResponder.new StatusResponder());
httpd.addResponder(appGetResponder.new InstallResponder());
httpd.start();
// Special case: handle yFiles app options
final OpenBrowser openBrowser = getService(bc, OpenBrowser.class);
YFilesChecker checker = new YFilesChecker(appManager, serviceRegistrar, openBrowser);
bc.addBundleListener(checker);
registerAllServices(bc, checker, new Properties());
{
AppStoreTaskFactory factory = new AppStoreTaskFactory(appManager, serviceRegistrar);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "open appstore");
props.setProperty(COMMAND_DESCRIPTION, "Open the app store page for an app");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Open the app store page for an app.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{}");
registerService(bc, factory, TaskFactory.class, props);
}
{
DisableTaskFactory factory = new DisableTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "disable");
props.setProperty(COMMAND_DESCRIPTION, "Disable an app");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Disable a currently installed app.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{\"appName\": \"appname\"}");
registerService(bc, factory, TaskFactory.class, props);
}
{
EnableTaskFactory factory = new EnableTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "enable");
props.setProperty(COMMAND_DESCRIPTION, "Enable a disabled app");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Enable a currently disabled app.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{\"appName\": \"appname\"}");
registerService(bc, factory, TaskFactory.class, props);
}
{
InformationTaskFactory factory = new InformationTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "information");
props.setProperty(COMMAND_DESCRIPTION, "Get app information");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Get information about an app.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{\"appName\": \"appname\"" + ", \"description\": \"App description\"" + ", \"version\": \"1.2.2\"}");
registerService(bc, factory, TaskFactory.class, props);
}
{
InstallTaskFactory factory = new InstallTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "install");
props.setProperty(COMMAND_DESCRIPTION, "Install an app");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Install an app given an app name or file.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{}");
registerService(bc, factory, TaskFactory.class, props);
}
{
ListAvailableTaskFactory factory = new ListAvailableTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "list available");
props.setProperty(COMMAND_DESCRIPTION, "List the available apps");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Return a list of the available apps in the app store");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "[{\"appName\":\"name\", " + "\"description\":\"descriptions\", " + "\"details\":\"app details\"}]");
registerService(bc, factory, TaskFactory.class, props);
}
{
ListAppsTaskFactory factory = new ListAppsTaskFactory(appManager, AppStatus.DISABLED);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "list disabled");
props.setProperty(COMMAND_DESCRIPTION, "List the disabled apps");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Return a list of the disabled apps in the current installation.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "[{ \"appName\": \"appname\"," + "\"version\": \"1.1.0\"," + "\"description\": \"descriptions\"," + "\"status\": \"Disabled\"}]");
registerService(bc, factory, TaskFactory.class, props);
}
{
ListAppsTaskFactory factory = new ListAppsTaskFactory(appManager, AppStatus.INSTALLED);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "list installed");
props.setProperty(COMMAND_DESCRIPTION, "List the installed apps");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Return a list of the installed apps in the current installation.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "[{\"appName\": \"appname\"," + "\"version\": \"1.1.0\"," + "\"description\": \"descriptions\"," + "\"status\": \"Installed\"}]");
registerService(bc, factory, TaskFactory.class, props);
}
{
ListAppsTaskFactory factory = new ListAppsTaskFactory(appManager, AppStatus.UNINSTALLED);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "list uninstalled");
props.setProperty(COMMAND_DESCRIPTION, "List the uninstalled apps");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Return a list of the uninstalled apps in the current installation.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "[{ \"appName\": \"appname\"," + "\"version\": \"1.1.0\"," + "\"description\": \"descriptions\"," + "\"status\": \"Uninstalled\"}]");
registerService(bc, factory, TaskFactory.class, props);
}
{
ListUpdatesTaskFactory factory = new ListUpdatesTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "list updates");
props.setProperty(COMMAND_DESCRIPTION, "List the apps available for updates");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Return a list of the apps that have updates in the app store.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "[{ \"appName\": \"appname\"," + "\"version\": \"1.1.10\"," + "\"information\": \"app information\"}]");
registerService(bc, factory, TaskFactory.class, props);
}
{
StatusTaskFactory factory = new StatusTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "status");
props.setProperty(COMMAND_DESCRIPTION, "Get the status of an app");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Get the status of an app.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{\"appName\": \"appname\", \"status\": \"Installed\"}");
registerService(bc, factory, TaskFactory.class, props);
}
{
UninstallTaskFactory factory = new UninstallTaskFactory(appManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "uninstall");
props.setProperty(COMMAND_DESCRIPTION, "Uninstall an app");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Uninstall a currently installed app.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{\"appName\": \"appname\"}");
registerService(bc, factory, TaskFactory.class, props);
}
{
UpdateTaskFactory factory = new UpdateTaskFactory(appManager, updateManager);
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "apps");
props.setProperty(COMMAND, "update");
props.setProperty(COMMAND_DESCRIPTION, "Update an app or all apps");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Update an app or all apps.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "{}");
registerService(bc, factory, TaskFactory.class, props);
}
}
use of org.cytoscape.view.layout.CyLayoutAlgorithmManager in project PhenomeScape by soulj.
the class PhenomeExpress method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
taskMonitor.setTitle("Running PhenomeExpress");
taskMonitor.setStatusMessage("Preparing Networks");
long time = System.currentTimeMillis();
inputCheck();
setUpNetworks();
double[] relativeWeighting = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };
double[] alphas = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };
double[] piValues = proteinNetwork.getPivalues();
Map<String, Integer> phenotypeMap = phenomeNetwork.getName2IndexMap();
double[] phenoArray = new double[phenomeNetwork.getName2IndexMap().size()];
selectedPhenotypes = new ArrayList<Phenotype>();
boolean first = true;
for (Phenotype phenotype : phenotypes) {
if (phenotype.getSelected()) {
if (first) {
phenotypeSelected = phenotype.getID();
phenotypeNamesSelected = phenotype.getName();
selectedPhenotypes.add(phenotype);
phenoArray[phenotypeMap.get(phenotype.getID())] = 1.0;
first = false;
} else {
phenotypeSelected = phenotypeSelected + " ," + phenotype.getID();
phenotypeNamesSelected = phenotypeNamesSelected + " ," + phenotype.getName();
phenoArray[phenotypeMap.get(phenotype.getID())] = 1.0;
selectedPhenotypes.add(phenotype);
}
}
}
Map<CyNode, Integer> map = proteinNetwork.getNode2IndexMap();
int size = proteinNetwork.getNetwork().getNodeCount();
int[] occuranceArray = new int[size];
HashMap<CyNode, Protein> node2Protein = new HashMap<CyNode, Protein>();
if (cancelled) {
return;
}
taskMonitor.setStatusMessage("Calculating Activity Scores");
taskMonitor.setProgress(0.0);
double progress = 0.0;
SparseRowMatrix adjMatrix = SparseRowMatrix.create(size, size);
double[] transitionProbs = { 0.5, 0.6, 0.7, 0.8 };
for (double transitionProb : transitionProbs) {
TransitionMatrix transitionMatrix = new TransitionMatrix(phenomeNetwork.normalise(transitionProb, phenoGeneNetwork), proteinNetwork.normalise(transitionProb, phenoGeneNetwork), phenoGeneNetwork.normaliseT(transitionProb), phenoGeneNetwork.normalise(transitionProb));
for (double weighting : relativeWeighting) {
if (cancelled) {
return;
}
transitionMatrix.prepareVector(piValues, phenoArray, weighting);
for (double alpha : alphas) {
progress += 0.0051;
taskMonitor.setProgress(progress);
double[] pageRankResults = transitionMatrix.pageRank(alpha);
HashMap<Integer, Protein> index2ProteinMap = proteinNetwork.getIndex2ProteinMap();
for (int i = 0; i < index2ProteinMap.size(); i++) {
Protein protein = index2ProteinMap.get(i);
protein.setValue(pageRankResults[i]);
}
List<Protein> proteinList = new ArrayList<Protein>(index2ProteinMap.values());
Collections.sort(proteinList, new DescendingScoreComparator());
int rank = 0;
for (Protein protein : proteinList) {
rank++;
protein.setRank(rank);
node2Protein.put(protein.getNode(), protein);
}
Collections.sort(proteinList, new DescendingScoreComparator());
GIGA giga = new GIGA(proteinList, node2Protein, proteinNetwork, maxNetworkSize);
giga.compute();
for (GIGACluster cluster : giga.getClusters()) {
for (CyNode node : cluster.getCluster()) {
Integer index = map.get(node);
AVector row = adjMatrix.getRow(index);
if (!row.isMutable()) {
row = row.mutable();
}
for (CyNode node2 : cluster.getCluster()) {
Integer index2 = map.get(node2);
row.set(index2, row.get(index2) + 1.0);
occuranceArray[index2]++;
}
adjMatrix.replaceRow(index, row);
}
}
}
}
}
if (cancelled) {
return;
}
taskMonitor.setProgress(1.0);
taskMonitor.setStatusMessage("Creating Consensus Subnetworks");
AMatrix cooccuranceMat = adjMatrix.transposeInnerProduct(adjMatrix);
for (int i = 0; i < size; i++) {
AVector row = cooccuranceMat.getRow(i);
if (row.elementSum() > 0) {
row.divide(occuranceArray[i]);
Index nonSparse = row.nonSparseIndex();
for (int j = 0; j < nonSparse.length(); j++) {
if (row.get(nonSparse.get(j)) < 1.0) {
row.set(nonSparse.get(j), 0.0);
}
}
cooccuranceMat.replaceRow(i, row.sparse());
}
}
ConnectedComponentAnalyser CCA = new ConnectedComponentAnalyser(node2Protein);
ArrayList<PhenomeExpressSubnetwork> subnetworks = CCA.ccFromAdjMatrix(adjMatrix, proteinNetwork);
Iterator<PhenomeExpressSubnetwork> it = subnetworks.iterator();
while (it.hasNext()) {
PhenomeExpressSubnetwork subnetwork = it.next();
if (subnetwork.getNodeList().size() < this.minNetSize) {
it.remove();
}
}
if (cancelled) {
return;
}
taskMonitor.setStatusMessage("Calculating Subnetwork Significance");
subnetworksSignificance(subnetworks);
taskMonitor.setStatusMessage("Visualising Subnetworks");
List<Double> foldChangeValues = proteinNetwork.getNodeTable().getColumn(foldChange).getValues(Double.class);
double fcMax = Collections.max(foldChangeValues);
double fcMin = Collections.min(foldChangeValues);
// Apply the visual style to a NetworkView
VizStyle vizStyle = new VizStyle();
VisualStyle vs = vizStyle.createVizStyle(cyServiceRegistrar, geneName, foldChange, fcMax, fcMin);
this.property = getNodeLabelPositionProperty();
vs.setDefaultValue(property, property.parseSerializableString("N,S,c,0.0,0.0"));
VisualMappingManager visualMappingManager = cyServiceRegistrar.getService(VisualMappingManager.class);
visualMappingManager.setCurrentVisualStyle(vs);
ArrayList<CyNetworkView> networkViewList = new ArrayList<CyNetworkView>();
Iterator<PhenomeExpressSubnetwork> it2 = subnetworks.iterator();
CyNetworkManager networkManager = cyServiceRegistrar.getService(CyNetworkManager.class);
CyNetworkViewFactory networkViewFactory = cyServiceRegistrar.getService(CyNetworkViewFactory.class);
CyLayoutAlgorithmManager layoutManager = cyServiceRegistrar.getService(CyLayoutAlgorithmManager.class);
CyApplicationManager cyApplicationManager = cyServiceRegistrar.getService(CyApplicationManager.class);
CyLayoutAlgorithm layout = layoutManager.getLayout("force-directed");
Map<String, Object> settings = new HashMap<String, Object>();
settings.put("defaultSpringLength", 5.0);
settings.put("defaultSpringNodeMass", 2.0);
TunableSetter setter = cyServiceRegistrar.getService(TunableSetter.class);
Object context = layout.createLayoutContext();
setter.applyTunables(context, settings);
GOTermAnalyser2 goTermAnalyser = new GOTermAnalyser2(proteinNetwork, species);
while (it2.hasNext()) {
PhenomeExpressSubnetwork subnet = it2.next();
if (subnet.getPvalue() > this.threshold) {
it2.remove();
} else {
goTermAnalyser.calculateGOTermPValues(subnet, proteinNetwork);
String subnetworkName = NetworkUtils.getUniqueNetworkName(cyServiceRegistrar, networkName + "_" + subnet.getBestGOTerm());
subnet.setName(subnetworkName);
CySubNetwork subnetwork = NetworkUtils.createSubNetwork(((CySubNetwork) proteinNetwork.getNetwork()).getRootNetwork(), subnet.getNodeList());
subnetwork.getRow(subnetwork).set(CyNetwork.NAME, subnetworkName);
addSeedPhenotypes(subnetwork);
networkManager.addNetwork(subnetwork);
CyNetworkViewManager viewManager = cyServiceRegistrar.getService(CyNetworkViewManager.class);
CyNetworkView nv = networkViewFactory.createNetworkView(subnetwork);
viewManager.addNetworkView(nv);
cyApplicationManager.setCurrentNetworkView(nv);
for (CyNode phenoNode : phenotypesAdded) {
View<CyNode> nodeView = nv.getNodeView(phenoNode);
nodeView.setLockedValue(BasicVisualLexicon.NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
nodeView.setLockedValue(BasicVisualLexicon.NODE_FILL_COLOR, Color.BLUE);
}
for (CyEdge phenoEdge : phenoEdges) {
View<CyEdge> edgeView = nv.getEdgeView(phenoEdge);
edgeView.setLockedValue(BasicVisualLexicon.EDGE_LINE_TYPE, LineTypeVisualProperty.DOT);
edgeView.setLockedValue(BasicVisualLexicon.EDGE_PAINT, Color.BLUE);
}
networkViewList.add(nv);
Set<View<CyNode>> nodeSet = Collections.emptySet();
cyServiceRegistrar.getService(TaskManager.class).execute(layout.createTaskIterator(nv, context, nodeSet, null));
}
}
CyEventHelper cyEventHelper = cyServiceRegistrar.getService(CyEventHelper.class);
for (CyNetworkView nv : networkViewList) {
visualMappingManager.setVisualStyle(vs, nv);
vs.apply(nv);
cyEventHelper.flushPayloadEvents();
cyApplicationManager.setCurrentNetworkView(nv);
nv.updateView();
}
phenomeNetwork = null;
proteinNetwork = null;
ResultsPanel resultsPanel = (ResultsPanel) CytoPanelUtils.getCytoPanel(cyServiceRegistrar, ResultsPanel.class, CytoPanelName.EAST);
resultsPanel.newTableData(getResultsSummary(subnetworks), getParameterList());
CytoPanelUtils.showCytoPanel(cyServiceRegistrar, CytoPanelName.EAST);
}
Aggregations