use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class TMACommands method promptToRelabelTMAGrid.
/**
* Prompt to relabel the core names within a TMA grid.
* @param imageData image containing the TMA grid
*/
public static void promptToRelabelTMAGrid(ImageData<?> imageData) {
String title = "Relabel TMA grid";
if (imageData == null) {
Dialogs.showNoImageError(title);
return;
}
if (imageData.getHierarchy().getTMAGrid() == null) {
Dialogs.showErrorMessage(title, "No TMA grid selected!");
return;
}
ParameterList params = new ParameterList();
params.addStringParameter("labelsHorizontal", "Column labels", columnLabelsProperty.get(), "Enter column labels.\nThis can be a continuous range of letters or numbers (e.g. 1-10 or A-J),\nor a discontinuous list separated by spaces (e.g. A B C E F G).");
params.addStringParameter("labelsVertical", "Row labels", rowLabelsProperty.get(), "Enter row labels.\nThis can be a continuous range of letters or numbers (e.g. 1-10 or A-J),\nor a discontinuous list separated by spaces (e.g. A B C E F G).");
params.addChoiceParameter("labelOrder", "Label order", rowFirstProperty.get() ? "Row first" : "Column first", Arrays.asList("Column first", "Row first"), "Create TMA labels either in the form Row-Column or Column-Row");
if (!Dialogs.showParameterDialog(title, params))
return;
// Parse the arguments
String labelsHorizontal = params.getStringParameterValue("labelsHorizontal");
String labelsVertical = params.getStringParameterValue("labelsVertical");
boolean rowFirst = "Row first".equals(params.getChoiceParameterValue("labelOrder"));
// Figure out if this will work
TMAGrid grid = imageData.getHierarchy().getTMAGrid();
String[] columnLabels = PathObjectTools.parseTMALabelString(labelsHorizontal);
String[] rowLabels = PathObjectTools.parseTMALabelString(labelsVertical);
if (columnLabels.length < grid.getGridWidth()) {
Dialogs.showErrorMessage(title, "Not enough column labels specified!");
return;
}
if (rowLabels.length < grid.getGridHeight()) {
Dialogs.showErrorMessage(title, "Not enough row labels specified!");
return;
}
// Apply the labels
QP.relabelTMAGrid(imageData.getHierarchy(), labelsHorizontal, labelsVertical, rowFirst);
// Add to workflow history
imageData.getHistoryWorkflow().addStep(new DefaultScriptableWorkflowStep("Relabel TMA grid", String.format("relabelTMAGrid(\"%s\", \"%s\", %s)", GeneralTools.escapeFilePath(labelsHorizontal), GeneralTools.escapeFilePath(labelsVertical), Boolean.toString(rowFirst))));
// Store values
rowLabelsProperty.set(labelsVertical);
columnLabelsProperty.set(labelsHorizontal);
rowFirstProperty.set(rowFirst);
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class TMACommands method promptToExportTMAData.
/**
* Prompt to export summary TMA data for a specific image to a directory.
* @param qupath
* @param imageData
*/
public static void promptToExportTMAData(QuPathGUI qupath, ImageData<BufferedImage> imageData) {
String title = "Export TMA data";
if (imageData == null) {
Dialogs.showNoImageError(title);
return;
}
PathObjectHierarchy hierarchy = imageData == null ? null : imageData.getHierarchy();
if (hierarchy == null || hierarchy.isEmpty() || hierarchy.getTMAGrid() == null || hierarchy.getTMAGrid().nCores() == 0) {
Dialogs.showErrorMessage(title, "No TMA data available!");
return;
}
var overlayOptions = qupath.getViewers().stream().filter(v -> v.getImageData() == imageData).map(v -> v.getOverlayOptions()).findFirst().orElse(qupath.getOverlayOptions());
String defaultName = ServerTools.getDisplayableImageName(imageData.getServer());
File file = Dialogs.promptToSaveFile(null, null, defaultName, "TMA data", ".qptma");
if (file != null) {
if (!file.getName().endsWith(".qptma"))
file = new File(file.getParentFile(), file.getName() + ".qptma");
double downsample = PathPrefs.tmaExportDownsampleProperty().get();
TMADataIO.writeTMAData(file, imageData, overlayOptions, downsample);
WorkflowStep step = new DefaultScriptableWorkflowStep("Export TMA data", "exportTMAData(\"" + GeneralTools.escapeFilePath(file.getParentFile().getAbsolutePath()) + "\", " + downsample + ")");
imageData.getHistoryWorkflow().addStep(step);
// PathAwtIO.writeTMAData(file, imageData, viewer.getOverlayOptions(), Double.NaN);
}
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class Commands method resetSelection.
/**
* Reset the selection for an image.
* @param imageData
*/
public static void resetSelection(final ImageData<?> imageData) {
if (imageData == null) {
logger.warn("No image available!");
return;
}
// Do the action reset
imageData.getHierarchy().getSelectionModel().clearSelection();
// Log the appropriate command
String method = "resetSelection();";
WorkflowStep newStep = new DefaultScriptableWorkflowStep("Reset selection", method);
WorkflowStep lastStep = imageData.getHistoryWorkflow().getLastStep();
if (newStep.equals(lastStep))
imageData.getHistoryWorkflow().replaceLastStep(newStep);
else
imageData.getHistoryWorkflow().addStep(newStep);
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class Commands method makeInverseAnnotation.
/**
* Make an inverse annotation for the selected objects, storing the command in the history workflow.
* @param imageData
* @see QP#makeInverseAnnotation(ImageData)
*/
public static void makeInverseAnnotation(ImageData<?> imageData) {
if (imageData == null)
return;
logger.debug("Make inverse annotation");
QP.makeInverseAnnotation(imageData);
imageData.getHistoryWorkflow().addStep(new DefaultScriptableWorkflowStep("Invert selected annotation", "makeInverseAnnotation()"));
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class MeasurementManager method promptToRemoveAllMeasurements.
private boolean promptToRemoveAllMeasurements() {
var selectedClass = comboBox.getSelectionModel().getSelectedItem();
var selectedItems = new ArrayList<>(measurementList);
if (selectedClass == null || selectedItems.isEmpty()) {
Dialogs.showErrorMessage("Remove measurements", "No measurements selected!");
return false;
}
String number = selectedItems.size() == 1 ? String.format("'%s'", selectedItems.iterator().next()) : selectedItems.size() + " measurements";
if (!Dialogs.showConfirmDialog("Remove measurements", "Are you sure you want to permanently remove " + number + "?"))
return false;
logger.info("Removing all measurements for ", PathObjectTools.getSuitableName(selectedClass, true));
Class<? extends PathObject> cls = comboBox.getSelectionModel().getSelectedItem();
String script;
var hierarchy = imageData.getHierarchy();
if (cls == PathAnnotationObject.class) {
script = "clearAnnotationMeasurements()";
QP.clearAnnotationMeasurements(hierarchy);
} else if (cls == PathCellObject.class) {
script = "clearCellMeasurements()";
QP.clearCellMeasurements(hierarchy);
} else if (cls == PathTileObject.class) {
script = "clearTileMeasurements()";
QP.clearTileMeasurements(hierarchy);
} else if (cls == PathRootObject.class) {
script = "clearRootMeasurements()";
QP.clearRootMeasurements(hierarchy);
} else if (cls == TMACoreObject.class) {
script = "clearTMACoreMeasurements()";
QP.clearTMACoreMeasurements(hierarchy);
} else {
script = "clearMeasurements(" + cls.getName() + ")";
QP.clearMeasurements(hierarchy, cls);
}
// Keep for scripting
WorkflowStep step = new DefaultScriptableWorkflowStep("Clear all measurements", script);
imageData.getHistoryWorkflow().addStep(step);
// Update
refreshMeasurements();
updateCurrentList();
filterText.set("");
return true;
}
Aggregations