Search in sources :

Example 6 with TaskObserver

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

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

FinishStatus (org.cytoscape.work.FinishStatus)7 ObservableTask (org.cytoscape.work.ObservableTask)7 TaskObserver (org.cytoscape.work.TaskObserver)7 TaskIterator (org.cytoscape.work.TaskIterator)6 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 ApplyEMStyleTask (org.baderlab.csplugins.enrichmentmap.task.ApplyEMStyleTask)1 HierarchicalClusterTask (org.baderlab.csplugins.enrichmentmap.task.cluster.HierarchicalClusterTask)1