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);
}
}
}
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);
}
}
}
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;
}
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;
}
}
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);
}
Aggregations