Search in sources :

Example 1 with FinishStatus

use of org.cytoscape.work.FinishStatus 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 FinishStatus

use of org.cytoscape.work.FinishStatus 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 FinishStatus

use of org.cytoscape.work.FinishStatus 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 FinishStatus

use of org.cytoscape.work.FinishStatus 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 FinishStatus

use of org.cytoscape.work.FinishStatus 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

FinishStatus (org.cytoscape.work.FinishStatus)9 ObservableTask (org.cytoscape.work.ObservableTask)9 TaskObserver (org.cytoscape.work.TaskObserver)7 TaskIterator (org.cytoscape.work.TaskIterator)6 Task (org.cytoscape.work.Task)2 TaskMonitor (org.cytoscape.work.TaskMonitor)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 JList (javax.swing.JList)1 SerialTestTaskManager (org.baderlab.csplugins.enrichmentmap.SerialTestTaskManager)1 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)1 EMSignatureDataSet (org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet)1 SetOfGeneSets (org.baderlab.csplugins.enrichmentmap.model.SetOfGeneSets)1 RanksFileReaderTask (org.baderlab.csplugins.enrichmentmap.parsers.RanksFileReaderTask)1 DataSetParameters (org.baderlab.csplugins.enrichmentmap.resolver.DataSetParameters)1 ResolverTask (org.baderlab.csplugins.enrichmentmap.resolver.ResolverTask)1