Search in sources :

Example 1 with TaskMonitor

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

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

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

Example 4 with TaskMonitor

use of org.cytoscape.work.TaskMonitor in project cytoscape-api by cytoscape.

the class AbstractPartitionLayoutTask method doLayout.

/**
	 * AbstractGraphPartitionLayout implements the doLayout method
	 * of AbstractBasicLayout in which it calls the layoutParition
	 * method on each LayoutPartition object created for the network.
	 * @param taskMonitor the TaskMonitor provided by the run() method
	 * of the Task.
	 */
@Override
public void doLayout(final TaskMonitor taskMonitor) {
    final CyNetwork network = networkView.getModel();
    if (edgeWeighter != null)
        edgeWeighter.reset();
    this.taskMonitor = taskMonitor;
    long visibleNodeCount = networkView.getNodeViews().stream().filter(view -> view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)).count();
    boolean useAllNodes = nodesToLayOut.size() == visibleNodeCount;
    // to lay out selected nodes, partitioning becomes a very bad idea!
    if (singlePartition || !useAllNodes) {
        // We still use the partition abstraction, even if we're
        // not partitioning.  This makes the code further down
        // much cleaner
        LayoutPartition partition = new LayoutPartition(networkView, nodesToLayOut, edgeWeighter);
        partitionList = new ArrayList<LayoutPartition>(1);
        partitionList.add(partition);
    } else {
        Set<CyNode> nodes = nodesToLayOut.stream().map(nv -> nv.getModel()).collect(Collectors.toSet());
        partitionList = PartitionUtil.partition(networkView, nodes, edgeWeighter);
    }
    total_nodes = network.getNodeCount();
    current_start = 0;
    // Set up offsets -- we start with the overall min and max
    double xStart = (partitionList.get(0)).getMinX();
    double yStart = (partitionList.get(0)).getMinY();
    for (LayoutPartition part : partitionList) {
        xStart = Math.min(xStart, part.getMinX());
        yStart = Math.min(yStart, part.getMinY());
    }
    double next_x_start = xStart;
    double next_y_start = yStart;
    double current_max_y = 0;
    double max_dimensions = Math.sqrt((double) network.getNodeCount());
    // give each node room
    max_dimensions *= incr;
    max_dimensions += xStart;
    for (LayoutPartition partition : partitionList) {
        if (cancelled)
            break;
        // get the partition
        current_size = (double) partition.size();
        // System.out.println("Partition #"+partition.getPartitionNumber()+" has "+current_size+" nodes");
        setTaskStatus(1);
        // Partitions Requiring Layout
        if (partition.nodeCount() > 1) {
            try {
                layoutPartition(partition);
            } catch (Throwable _e) {
                _e.printStackTrace();
                return;
            }
            if (useAllNodes && !singlePartition) {
                // System.out.println("Offsetting partition #"+partition.getPartitionNumber()+" to "+next_x_start+", "+next_y_start);
                // OFFSET
                partition.offset(next_x_start, next_y_start);
            }
        // single nodes
        } else if (partition.nodeCount() == 1) {
            // Reset our bounds
            partition.resetNodes();
            // Single node -- get it
            LayoutNode node = (LayoutNode) partition.getNodeList().get(0);
            node.setLocation(next_x_start, next_y_start);
            partition.moveNodeToLocation(node);
        } else {
            continue;
        }
        double last_max_x = partition.getMaxX();
        double last_max_y = partition.getMaxY();
        if (last_max_y > current_max_y) {
            current_max_y = last_max_y;
        }
        if (last_max_x > max_dimensions) {
            next_x_start = xStart;
            next_y_start = current_max_y;
            next_y_start += incr;
        } else {
            next_x_start = last_max_x;
            next_x_start += incr;
        }
        setTaskStatus(100);
        current_start += current_size;
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) Logger(org.slf4j.Logger) CyNode(org.cytoscape.model.CyNode) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) UndoSupport(org.cytoscape.work.undo.UndoSupport) Collectors(java.util.stream.Collectors) View(org.cytoscape.view.model.View) ArrayList(java.util.ArrayList) List(java.util.List) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode)

Example 5 with TaskMonitor

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

the class MasterDetailDialogPage method finish.

@Override
public void finish() {
    if (!validateInput())
        return;
    String prefix = legacySupport.getNextAttributePrefix();
    SimilarityMetric similarityMetric = cutoffPanel.getSimilarityMetric();
    double pvalue = cutoffPanel.getPValue();
    double qvalue = cutoffPanel.getQValue();
    NESFilter nesFilter = cutoffPanel.getNESFilter();
    double cutoff = cutoffPanel.getCutoff();
    double combined = cutoffPanel.getCombinedConstant();
    Optional<Integer> minExperiments = cutoffPanel.getMinimumExperiments();
    EMCreationParameters params = new EMCreationParameters(prefix, pvalue, qvalue, nesFilter, minExperiments, similarityMetric, cutoff, combined);
    params.setCreateDistinctEdges(distinctEdgesCheckbox.isSelected());
    List<DataSetParameters> dataSets = dataSetListModel.toList().stream().map(DataSetListItem::getDetailPanel).map(DetailPanel::createDataSetParameters).filter(x -> x != null).collect(Collectors.toList());
    // Overwrite all the expression files if the common file has been provided
    String exprPath = commonPanel.getExpressionFile();
    if (!isNullOrEmpty(exprPath)) {
        for (DataSetParameters dsp : dataSets) {
            dsp.getFiles().setExpressionFileName(exprPath);
        }
    }
    // Overwrite all the gmt files if a common file has been provided
    String gmtPath = commonPanel.getGmtFile();
    if (!isNullOrEmpty(gmtPath)) {
        for (DataSetParameters dsp : dataSets) {
            dsp.getFiles().setGMTFileName(gmtPath);
        }
    }
    CreateEnrichmentMapTaskFactory taskFactory = taskFactoryFactory.create(params, dataSets);
    TaskIterator tasks = taskFactory.createTaskIterator();
    // Close this dialog after the progress dialog finishes normally
    tasks.append(new AbstractTask() {

        public void run(TaskMonitor taskMonitor) {
            callback.close();
        }
    });
    dialogTaskManager.execute(tasks);
}
Also used : Color(java.awt.Color) CreateEnrichmentMapTaskFactory(org.baderlab.csplugins.enrichmentmap.task.CreateEnrichmentMapTaskFactory) UIManager(javax.swing.UIManager) Inject(com.google.inject.Inject) IterableListModel(org.baderlab.csplugins.enrichmentmap.view.util.IterableListModel) Border(javax.swing.border.Border) IconManager(org.cytoscape.util.swing.IconManager) FileBrowser(org.baderlab.csplugins.enrichmentmap.view.util.FileBrowser) Map(java.util.Map) FinishStatus(org.cytoscape.work.FinishStatus) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ResolverTask(org.baderlab.csplugins.enrichmentmap.resolver.ResolverTask) EMCreationParameters(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters) LegacySupport(org.baderlab.csplugins.enrichmentmap.model.LegacySupport) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Alignment(javax.swing.GroupLayout.Alignment) MessageType(org.baderlab.csplugins.enrichmentmap.view.creation.ErrorMessageDialog.MessageType) SwingUtil(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) TaskObserver(org.cytoscape.work.TaskObserver) JPanel(javax.swing.JPanel) ObservableTask(org.cytoscape.work.ObservableTask) ListSelectionModel(javax.swing.ListSelectionModel) CardDialogPage(org.baderlab.csplugins.enrichmentmap.view.util.CardDialogPage) CardLayout(java.awt.CardLayout) JSplitPane(javax.swing.JSplitPane) DataSetFiles(org.baderlab.csplugins.enrichmentmap.model.DataSetFiles) AbstractTask(org.cytoscape.work.AbstractTask) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Function(java.util.function.Function) SimilarityMetric(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters.SimilarityMetric) TaskIterator(org.cytoscape.work.TaskIterator) ArrayList(java.util.ArrayList) NESFilter(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResultFilterParams.NESFilter) DataSetParameters(org.baderlab.csplugins.enrichmentmap.resolver.DataSetParameters) TaskMonitor(org.cytoscape.work.TaskMonitor) FlowLayout(java.awt.FlowLayout) Method(org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method) JButton(javax.swing.JButton) Iterator(java.util.Iterator) CardDialogCallback(org.baderlab.csplugins.enrichmentmap.view.util.CardDialogCallback) JList(javax.swing.JList) JOptionPane(javax.swing.JOptionPane) File(java.io.File) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) JScrollPane(javax.swing.JScrollPane) LayoutStyle(javax.swing.LayoutStyle) ListCellRenderer(javax.swing.ListCellRenderer) Provider(com.google.inject.Provider) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) ListModel(javax.swing.ListModel) EMCreationParameters(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters) AbstractTask(org.cytoscape.work.AbstractTask) SimilarityMetric(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters.SimilarityMetric) NESFilter(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResultFilterParams.NESFilter) CreateEnrichmentMapTaskFactory(org.baderlab.csplugins.enrichmentmap.task.CreateEnrichmentMapTaskFactory) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) DataSetParameters(org.baderlab.csplugins.enrichmentmap.resolver.DataSetParameters)

Aggregations

TaskMonitor (org.cytoscape.work.TaskMonitor)7 TaskIterator (org.cytoscape.work.TaskIterator)4 AbstractTask (org.cytoscape.work.AbstractTask)3 Task (org.cytoscape.work.Task)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)2 FinishStatus (org.cytoscape.work.FinishStatus)2 ObservableTask (org.cytoscape.work.ObservableTask)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 BorderLayout (java.awt.BorderLayout)1 CardLayout (java.awt.CardLayout)1 Color (java.awt.Color)1 Component (java.awt.Component)1 FlowLayout (java.awt.FlowLayout)1