Search in sources :

Example 1 with Task

use of org.cytoscape.work.Task 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 2 with Task

use of org.cytoscape.work.Task 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 3 with Task

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

the class CreateDiseaseSignatureTaskParallel method run.

@Override
public void run(TaskMonitor tm) throws InterruptedException {
    int cpus = Runtime.getRuntime().availableProcessors();
    ExecutorService executor = Executors.newFixedThreadPool(cpus);
    // Compare enrichment gene sets to signature gene sets
    Set<String> enrichmentGeneSetNames = getEnrichmentGeneSetNames();
    Map<String, GeneSet> signatureGeneSets = getSignatureGeneSets();
    handleDuplicateNames(enrichmentGeneSetNames, signatureGeneSets);
    Map<SimilarityKey, GenesetSimilarity> geneSetSimilarities = startBuildDiseaseSignatureParallel(tm, executor, enrichmentGeneSetNames, signatureGeneSets);
    // Support cancellation
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            if (cancelled) {
                executor.shutdownNow();
            }
        }
    }, 0, 1000);
    executor.shutdown();
    executor.awaitTermination(3, TimeUnit.HOURS);
    timer.cancel();
    // create the network here
    if (!cancelled) {
        Task networkTask = networkTaskFactory.create(map, params, signatureGeneSets, geneSetSimilarities);
        insertTasksAfterCurrentTask(networkTask);
    }
}
Also used : Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) TimerTask(java.util.TimerTask) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ExecutorService(java.util.concurrent.ExecutorService) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet)

Example 4 with Task

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

the class CreateEMViewTask method visualizeMap.

private void visualizeMap() {
    CyNetwork network = networkManager.getNetwork(map.getNetworkID());
    CyNetworkView view = networkViewFactory.createNetworkView(network);
    networkViewManager.addNetworkView(view);
    //apply force directed layout
    CyLayoutAlgorithm layout = layoutManager.getLayout("force-directed");
    if (layout == null)
        layout = layoutManager.getDefaultLayout();
    Task styleTask = applyStyleTaskFactory.create(new EMStyleOptions(view, map), null, false);
    TaskIterator layoutTasks = layout.createTaskIterator(view, layout.createLayoutContext(), CyLayoutAlgorithm.ALL_NODE_VIEWS, null);
    TaskIterator moreTasks = new TaskIterator();
    moreTasks.append(styleTask);
    moreTasks.append(layoutTasks);
    insertTasksAfterCurrentTask(moreTasks);
}
Also used : EMStyleOptions(org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions) Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) TaskIterator(org.cytoscape.work.TaskIterator) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 5 with Task

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

the class EdgeWidthDialog method createButtonPanel.

private JPanel createButtonPanel() {
    JButton restoreDefaultsButton = new JButton("Restore Defaults");
    restoreDefaultsButton.addActionListener(e -> {
        setTextFieldValues(EdgeWidthParams.defaultValues());
    });
    JButton cancelButton = new JButton(new AbstractAction("Cancel") {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    JButton okButton = new JButton(new AbstractAction("OK") {

        @Override
        public void actionPerformed(ActionEvent e) {
            double emLowerWidth = ((Number) emLowerWidthText.getValue()).doubleValue();
            double emUpperWidth = ((Number) emUpperWidthText.getValue()).doubleValue();
            double lessThan100 = ((Number) lessThan100Text.getValue()).doubleValue();
            double lessThan10 = ((Number) lessThan10Text.getValue()).doubleValue();
            double greaterThan = ((Number) greaterThanText.getValue()).doubleValue();
            EdgeWidthParams params = new EdgeWidthParams(emLowerWidth, emUpperWidth, lessThan100, lessThan10, greaterThan);
            params.save(network);
            Task task = new Task() {

                public void run(TaskMonitor taskMonitor) throws Exception {
                    taskMonitor.setTitle("EnrichmentMap");
                    taskMonitor.setStatusMessage("Calculating Post-Analysis Edge Widths");
                    WidthFunction widthFunction = widthFunctionProvider.get();
                    widthFunction.setEdgeWidths(network, prefix, taskMonitor);
                }

                public void cancel() {
                }
            };
            taskManager.execute(new TaskIterator(task));
            dispose();
        }
    });
    JPanel bottomPanel = LookAndFeelUtil.createOkCancelPanel(okButton, cancelButton, restoreDefaultsButton);
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), okButton.getAction(), cancelButton.getAction());
    getRootPane().setDefaultButton(okButton);
    return bottomPanel;
}
Also used : JPanel(javax.swing.JPanel) Task(org.cytoscape.work.Task) TaskIterator(org.cytoscape.work.TaskIterator) ActionEvent(java.awt.event.ActionEvent) TaskMonitor(org.cytoscape.work.TaskMonitor) WidthFunction(org.baderlab.csplugins.enrichmentmap.style.WidthFunction) EdgeWidthParams(org.baderlab.csplugins.enrichmentmap.style.WidthFunction.EdgeWidthParams) JButton(javax.swing.JButton) AbstractAction(javax.swing.AbstractAction)

Aggregations

Task (org.cytoscape.work.Task)6 TaskMonitor (org.cytoscape.work.TaskMonitor)4 AbstractTask (org.cytoscape.work.AbstractTask)3 TaskIterator (org.cytoscape.work.TaskIterator)3 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 FinishStatus (org.cytoscape.work.FinishStatus)2 ObservableTask (org.cytoscape.work.ObservableTask)2 ActionEvent (java.awt.event.ActionEvent)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 ExecutorService (java.util.concurrent.ExecutorService)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)1 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)1 GenesetSimilarity (org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)1 PostAnalysisFilterParameters (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters)1 PostAnalysisFilterType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)1