Search in sources :

Example 1 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class LoadSignatureSetsActionListener method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    // make sure that the minimum information is set in the current set of parameters
    if (file.canRead()) {
        // MKTODO warning LoadSignatureGMTFilesTask is side-effecting, it pulls the loaded genes into the EnrichmentMap object
        LoadSignatureGMTFilesTask loadGMTs = new LoadSignatureGMTFilesTask(file, map, filterMetric);
        TaskObserver taskObserver = new ResultTaskObserver() {

            private SetOfGeneSets resultGeneSets;

            private Set<String> filteredSignatureSets;

            @Override
            public void taskFinished(ObservableTask task) {
                if (task instanceof FilterSignatureGSTask) {
                    resultGeneSets = task.getResults(SetOfGeneSets.class);
                    filteredSignatureSets = task.getResults(Set.class);
                }
            }

            @Override
            public void allFinished(FinishStatus finishStatus) {
                geneSetCallback.accept(resultGeneSets);
                filteredSignatureSetsCallback.accept(filteredSignatureSets);
            }
        };
        taskManager.execute(loadGMTs.createTaskIterator(), taskObserver);
    } else {
        JOptionPane.showMessageDialog(application.getJFrame(), "Signature GMT file name not valid.\n", "Invalid File", JOptionPane.WARNING_MESSAGE);
    }
}
Also used : ResultTaskObserver(org.baderlab.csplugins.enrichmentmap.util.ResultTaskObserver) TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) ResultTaskObserver(org.baderlab.csplugins.enrichmentmap.util.ResultTaskObserver) FilterSignatureGSTask(org.baderlab.csplugins.enrichmentmap.task.postanalysis.FilterSignatureGSTask) LoadSignatureGMTFilesTask(org.baderlab.csplugins.enrichmentmap.task.postanalysis.LoadSignatureGMTFilesTask) Set(java.util.Set) FinishStatus(org.cytoscape.work.FinishStatus) SetOfGeneSets(org.baderlab.csplugins.enrichmentmap.model.SetOfGeneSets)

Example 2 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class SerialTestTaskManager method execute.

@Override
public void execute(TaskIterator iterator, TaskObserver observer) {
    TaskMonitor monitor = mock(TaskMonitor.class);
    FinishStatus finishStatus = null;
    Task task = null;
    try {
        while (iterator.hasNext()) {
            task = iterator.next();
            if (tasksToIgnore.contains(task.getClass())) {
                //System.out.println("Task Ignored: " + task.getClass());
                continue;
            }
            task.run(monitor);
            if (task instanceof ObservableTask && observer != null) {
                observer.taskFinished((ObservableTask) task);
            }
        }
        finishStatus = FinishStatus.getSucceeded();
    } catch (Exception e) {
        finishStatus = FinishStatus.newFailed(task, e);
        throw new AssertionError("Task failed", e);
    } finally {
        if (observer != null) {
            observer.allFinished(finishStatus);
        }
    }
}
Also used : ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) TaskMonitor(org.cytoscape.work.TaskMonitor) FinishStatus(org.cytoscape.work.FinishStatus)

Example 3 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class BaseNetworkTest method buildEnrichmentMap.

protected void buildEnrichmentMap(EMCreationParameters params, DataSetFiles datasetFiles, Method method, String datasetName) {
    List<DataSetParameters> dataSets = Arrays.asList(new DataSetParameters(datasetName, method, datasetFiles));
    CreateEnrichmentMapTaskFactory taskFactory = masterMapTaskFactoryFactory.create(params, dataSets);
    TaskIterator taskIterator = taskFactory.createTaskIterator();
    // make sure the task iterator completes
    TaskObserver observer = new TaskObserver() {

        public void taskFinished(ObservableTask task) {
        }

        public void allFinished(FinishStatus finishStatus) {
            if (finishStatus == null)
                fail();
            if (finishStatus.getType() != FinishStatus.Type.SUCCEEDED)
                throw new AssertionError("TaskIterator Failed", finishStatus.getException());
        }
    };
    SerialTestTaskManager testTaskManager = new SerialTestTaskManager();
    testTaskManager.ignoreTask(CreateEMViewTask.class);
    testTaskManager.execute(taskIterator, observer);
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) SerialTestTaskManager(org.baderlab.csplugins.enrichmentmap.SerialTestTaskManager) TaskIterator(org.cytoscape.work.TaskIterator) DataSetParameters(org.baderlab.csplugins.enrichmentmap.resolver.DataSetParameters) FinishStatus(org.cytoscape.work.FinishStatus)

Example 4 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class SerialTestTaskManager method execute.

@Override
public void execute(TaskIterator iterator, TaskObserver observer) {
    TaskMonitor monitor = new NullTaskMonitor();
    FinishStatus finishStatus = null;
    Task task = null;
    try {
        while (iterator.hasNext()) {
            task = iterator.next();
            if (tasksToIgnore.contains(task.getClass())) {
                //System.out.println("Task Ignored: " + task.getClass());
                continue;
            }
            task.run(monitor);
            if (task instanceof ObservableTask && observer != null) {
                observer.taskFinished((ObservableTask) task);
            }
        }
        finishStatus = FinishStatus.getSucceeded();
    } catch (Exception e) {
        finishStatus = FinishStatus.newFailed(task, e);
        throw new AssertionError("Task failed", e);
    } finally {
        if (observer != null) {
            observer.allFinished(finishStatus);
        }
    }
}
Also used : ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) TaskMonitor(org.cytoscape.work.TaskMonitor) FinishStatus(org.cytoscape.work.FinishStatus)

Example 5 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class ControlPanelMediator method removeSignatureDataSets.

private void removeSignatureDataSets(EnrichmentMap map, EMViewControlPanel viewPanel) {
    Set<EMSignatureDataSet> dataSets = viewPanel.getSelectedSignatureDataSets();
    if (!dataSets.isEmpty()) {
        if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(getControlPanel(), "Are you sure you want to remove the selected Signature Gene Sets\nand associated nodes?", "Remove Signature Gene Sets", JOptionPane.YES_NO_OPTION))
            return;
        RemoveSignatureDataSetsTask task = removeDataSetsTaskFactory.create(dataSets, map);
        dialogTaskManager.execute(new TaskIterator(task), new TaskObserver() {

            @Override
            public void taskFinished(ObservableTask task) {
            }

            @Override
            public void allFinished(FinishStatus finishStatus) {
                viewPanel.updateDataSetSelector();
                updateLegends(viewPanel);
                viewPanel.getNetworkView().updateView();
            }
        });
    }
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) TaskIterator(org.cytoscape.work.TaskIterator) FinishStatus(org.cytoscape.work.FinishStatus) RemoveSignatureDataSetsTask(org.baderlab.csplugins.enrichmentmap.task.postanalysis.RemoveSignatureDataSetsTask)

Aggregations

ObservableTask (org.cytoscape.work.ObservableTask)22 TaskIterator (org.cytoscape.work.TaskIterator)17 TaskObserver (org.cytoscape.work.TaskObserver)16 Task (org.cytoscape.work.Task)13 FinishStatus (org.cytoscape.work.FinishStatus)12 TaskMonitor (org.cytoscape.work.TaskMonitor)11 Test (org.junit.Test)6 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)5 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)4 File (java.io.File)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)3 CyGroupManager (org.cytoscape.group.CyGroupManager)3 CyNetwork (org.cytoscape.model.CyNetwork)3 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)3 CyNetworkManager (org.cytoscape.model.CyNetworkManager)3 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)3 CyRootNetworkManagerImpl (org.cytoscape.model.internal.CyRootNetworkManagerImpl)3 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)3 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)3