Search in sources :

Example 6 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)

Example 7 with TaskMonitor

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

the class PAKnownSignatureCommandTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    if (gmtFile == null || !gmtFile.canRead())
        throw new IllegalArgumentException("Signature GMT file name not valid");
    CyNetwork selectedNetwork;
    CyNetworkView selectedView;
    if (network == null) {
        selectedNetwork = applicationManager.getCurrentNetwork();
        selectedView = applicationManager.getCurrentNetworkView();
        if (selectedNetwork == null || selectedView == null) {
            throw new IllegalArgumentException("Current network not available.");
        }
    } else {
        selectedNetwork = network;
        Collection<CyNetworkView> networkViews = networkViewManager.getNetworkViews(network);
        if (networkViews == null || networkViews.isEmpty()) {
            throw new IllegalArgumentException("No network view for: " + network);
        }
        selectedView = networkViews.iterator().next();
    }
    EnrichmentMap map = emManager.getEnrichmentMap(selectedNetwork.getSUID());
    if (map == null)
        throw new IllegalArgumentException("Network is not an Enrichment Map.");
    loadGeneSets(map);
    PostAnalysisFilterType filter = PostAnalysisFilterType.valueOf(filterType.getSelectedValue());
    UniverseType universe = UniverseType.valueOf(hypergeomUniverseType.getSelectedValue());
    PostAnalysisParameters.Builder builder = new PostAnalysisParameters.Builder();
    builder.setAttributePrefix(map.getParams().getAttributePrefix());
    builder.setSignatureGMTFileName(gmtFile.getAbsolutePath());
    builder.setLoadedGMTGeneSets(signatureGenesets);
    builder.addSelectedGeneSetNames(selectedGenesetNames);
    builder.setUniverseType(universe);
    builder.setUserDefinedUniverseSize(userDefinedUniverseSize);
    builder.setRankTestParameters(new PostAnalysisFilterParameters(filter, cutoff));
    builder.setName(name);
    if (isBatch()) {
        // run in batch mode
        builder.setDataSetName(null);
    } else {
        if (map.getDataSet(dataSetName) == null) {
            throw new IllegalArgumentException("Data set name not valid: '" + dataSetName + "'");
        }
        builder.setDataSetName(dataSetName);
    }
    // Mann-Whitney requires ranks
    if (filter.isMannWhitney()) {
        processMannWhitneyArgs(map, builder);
    }
    TaskFactory taskFactory = taskFactoryFactory.create(selectedView, builder.build());
    TaskIterator taskIterator = new TaskIterator();
    taskIterator.append(taskFactory.createTaskIterator());
    Task updatePanelTask = new AbstractTask() {

        @Override
        public void run(TaskMonitor taskMonitor) {
            controlPanelMediatorProvider.get().updateDataSetList(selectedView);
            selectedView.updateView();
        }
    };
    taskIterator.append(updatePanelTask);
    insertTasksAfterCurrentTask(taskIterator);
}
Also used : Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) UniverseType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters.UniverseType) AbstractTask(org.cytoscape.work.AbstractTask) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) CyNetwork(org.cytoscape.model.CyNetwork) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) PostAnalysisParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CreateDiseaseSignatureTaskFactory(org.baderlab.csplugins.enrichmentmap.task.postanalysis.CreateDiseaseSignatureTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

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