Search in sources :

Example 6 with DefaultScriptableWorkflowStep

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);
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) DefaultTMAGrid(qupath.lib.objects.hierarchy.DefaultTMAGrid) TMAGrid(qupath.lib.objects.hierarchy.TMAGrid) ParameterList(qupath.lib.plugins.parameters.ParameterList)

Example 7 with DefaultScriptableWorkflowStep

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);
    }
}
Also used : Arrays(java.util.Arrays) ServerTools(qupath.lib.images.servers.ServerTools) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) ArrayList(java.util.ArrayList) Dialogs(qupath.lib.gui.dialogs.Dialogs) TMADataIO(qupath.lib.gui.tma.TMADataIO) ParameterList(qupath.lib.plugins.parameters.ParameterList) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) RunningStatistics(qupath.lib.analysis.stats.RunningStatistics) QuPathGUI(qupath.lib.gui.QuPathGUI) ImageData(qupath.lib.images.ImageData) BufferedImage(java.awt.image.BufferedImage) GeneralTools(qupath.lib.common.GeneralTools) PathObjects(qupath.lib.objects.PathObjects) TMACoreObject(qupath.lib.objects.TMACoreObject) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) Collectors(java.util.stream.Collectors) File(java.io.File) PathObjectTools(qupath.lib.objects.PathObjectTools) PathObject(qupath.lib.objects.PathObject) DefaultTMAGrid(qupath.lib.objects.hierarchy.DefaultTMAGrid) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) QP(qupath.lib.scripting.QP) StringProperty(javafx.beans.property.StringProperty) TMAGrid(qupath.lib.objects.hierarchy.TMAGrid) PathPrefs(qupath.lib.gui.prefs.PathPrefs) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) File(java.io.File)

Example 8 with DefaultScriptableWorkflowStep

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);
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)

Example 9 with DefaultScriptableWorkflowStep

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()"));
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)

Example 10 with DefaultScriptableWorkflowStep

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;
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) ArrayList(java.util.ArrayList) PathCellObject(qupath.lib.objects.PathCellObject) PathRootObject(qupath.lib.objects.PathRootObject)

Aggregations

DefaultScriptableWorkflowStep (qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)31 PathObject (qupath.lib.objects.PathObject)12 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)12 WorkflowStep (qupath.lib.plugins.workflow.WorkflowStep)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Map (java.util.Map)10 Dialogs (qupath.lib.gui.dialogs.Dialogs)10 Collectors (java.util.stream.Collectors)9 QuPathGUI (qupath.lib.gui.QuPathGUI)9 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)8 Arrays (java.util.Arrays)8 ImageData (qupath.lib.images.ImageData)8 File (java.io.File)7 StringProperty (javafx.beans.property.StringProperty)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 GeneralTools (qupath.lib.common.GeneralTools)7 Collections (java.util.Collections)6