Search in sources :

Example 16 with TaskIterator

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

Example 17 with TaskIterator

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

the class MasterDetailDialogPage method scan.

private void scan() {
    Optional<File> rootFolder = fileBrowser.browseForRootFolder(jframeProvider.get());
    if (rootFolder.isPresent()) {
        scanButton.setEnabled(false);
        ResolverTask task = new ResolverTask(rootFolder.get());
        dialogTaskManager.execute(new TaskIterator(task), new TaskObserver() {

            @Override
            public void taskFinished(ObservableTask task) {
                @SuppressWarnings("unchecked") List<DataSetParameters> datasets = task.getResults(List.class);
                if (!datasets.isEmpty()) {
                    datasets.forEach(MasterDetailDialogPage.this::addDataSetToList);
                    dataSetList.setSelectedValue(datasets.get(0), true);
                }
            }

            @Override
            public void allFinished(FinishStatus finishStatus) {
                scanButton.setEnabled(true);
                updateButtonEnablement();
            }
        });
    }
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) FinishStatus(org.cytoscape.work.FinishStatus) ResolverTask(org.baderlab.csplugins.enrichmentmap.resolver.ResolverTask) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) File(java.io.File)

Example 18 with TaskIterator

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

the class AddRanksDialog method loadRanksAndClose.

private void loadRanksAndClose() {
    String rankFileName = ranksFileText.getText();
    String ranksName = getRanksName();
    EMDataSet dataset = getDataSet();
    RanksFileReaderTask task = new RanksFileReaderTask(rankFileName, dataset, ranksName, true);
    dialogTaskManager.execute(new TaskIterator(task), new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            resultRanksName = ranksName;
            dispose();
        }
    });
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) RanksFileReaderTask(org.baderlab.csplugins.enrichmentmap.parsers.RanksFileReaderTask) FinishStatus(org.cytoscape.work.FinishStatus) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet)

Example 19 with TaskIterator

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

the class PostAnalysisPanelMediator method addGeneSets.

private void addGeneSets(CyNetworkView netView, PostAnalysisParameters params) {
    CreateDiseaseSignatureTaskFactory taskFactory = signatureTaskFactoryFactory.create(netView, params);
    TaskIterator tasks = taskFactory.createTaskIterator();
    String errors = taskFactory.getErrors();
    if (errors.isEmpty()) {
        taskManager.execute(tasks, new DialogObserver());
    } else {
        JOptionPane.showMessageDialog(swingApplication.getJFrame(), errors, "Invalid Input", JOptionPane.WARNING_MESSAGE);
    }
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CreateDiseaseSignatureTaskFactory(org.baderlab.csplugins.enrichmentmap.task.postanalysis.CreateDiseaseSignatureTaskFactory)

Example 20 with TaskIterator

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

the class ClusterRankingOption method computeRanking.

@Override
public CompletableFuture<Optional<Map<Integer, RankValue>>> computeRanking(Collection<Integer> genes) {
    if (genes.size() < 2) {
        // The HierarchicalClusterTask requires at least 2 genes
        return CompletableFuture.completedFuture(Optional.of(Collections.emptyMap()));
    }
    HierarchicalClusterTask task = new HierarchicalClusterTask(map, genes, distance.getMetric());
    CompletableFuture<Optional<Map<Integer, RankValue>>> future = new CompletableFuture<>();
    taskManager.execute(new TaskIterator(task), new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
            if (task instanceof HierarchicalClusterTask) {
                HierarchicalClusterTask clusterTask = (HierarchicalClusterTask) task;
                Optional<Map<Integer, RankValue>> ranking = clusterTask.getActualResults();
                future.complete(ranking);
            }
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            // Don't see why this would ever happen
            if (!future.isDone()) {
                future.completeExceptionally(new RuntimeException("Failed"));
            }
        }
    });
    return future;
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) CompletableFuture(java.util.concurrent.CompletableFuture) TaskIterator(org.cytoscape.work.TaskIterator) Optional(java.util.Optional) FinishStatus(org.cytoscape.work.FinishStatus) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) HierarchicalClusterTask(org.baderlab.csplugins.enrichmentmap.task.cluster.HierarchicalClusterTask)

Aggregations

TaskIterator (org.cytoscape.work.TaskIterator)23 File (java.io.File)7 FinishStatus (org.cytoscape.work.FinishStatus)7 ObservableTask (org.cytoscape.work.ObservableTask)7 TaskObserver (org.cytoscape.work.TaskObserver)7 DataSetParameters (org.baderlab.csplugins.enrichmentmap.resolver.DataSetParameters)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)4 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)4 CyNetwork (org.cytoscape.model.CyNetwork)4 AbstractTask (org.cytoscape.work.AbstractTask)4 ResolverTask (org.baderlab.csplugins.enrichmentmap.resolver.ResolverTask)3 CreateEnrichmentMapTaskFactory (org.baderlab.csplugins.enrichmentmap.task.CreateEnrichmentMapTaskFactory)3 TaskMonitor (org.cytoscape.work.TaskMonitor)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 JButton (javax.swing.JButton)2 JList (javax.swing.JList)2 SerialTestTaskManager (org.baderlab.csplugins.enrichmentmap.SerialTestTaskManager)2