diff --git a/README.md b/README.md index ef0685a..1662102 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ An ImageJ plugin to run a script on a batch of images from/to OMERO. 1. Install the [OMERO.insight plugin](https://omero-guides.readthedocs.io/en/latest/fiji/docs/installation.html) (if you haven't already). -2. Download the JAR file for this [library](https://github.com/GReD-Clermont/simple-omero-client/releases/tag/5.12.1/). -3. Download the JAR file ([for this plugin](https://github.com/GReD-Clermont/omero_batch-plugin/releases/tag/1.0.5/)). +2. Download the JAR file for this [library](https://github.com/GReD-Clermont/simple-omero-client/releases/tag/5.16.0/). +3. Download the JAR file ([for this plugin](https://github.com/GReD-Clermont/omero_batch-plugin/releases/tag/2.0.0/)). 4. Place these JAR files in your "plugins" folder. ## How to use diff --git a/src/main/java/fr/igred/ij/gui/OMEROConnectDialog.java b/src/main/java/fr/igred/ij/gui/OMEROConnectDialog.java index 8284683..5729c6a 100644 --- a/src/main/java/fr/igred/ij/gui/OMEROConnectDialog.java +++ b/src/main/java/fr/igred/ij/gui/OMEROConnectDialog.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 MICA & GReD + * Copyright (C) 2021-2023 MICA & GReD * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software diff --git a/src/main/java/fr/igred/ij/io/OMEROBatchImage.java b/src/main/java/fr/igred/ij/io/OMEROBatchImage.java index be4a789..803c216 100644 --- a/src/main/java/fr/igred/ij/io/OMEROBatchImage.java +++ b/src/main/java/fr/igred/ij/io/OMEROBatchImage.java @@ -87,7 +87,9 @@ public ImagePlus getImagePlus(ROIMode mode) { imp = imageWrapper.toImagePlus(client); // Store image "annotate" permissions as a property in the ImagePlus object imp.setProp("Annotatable", String.valueOf(imageWrapper.canAnnotate())); - loadROIs(imp, mode); + if (imp != null) { + loadROIs(imp, mode); + } } catch (ExecutionException | ServiceException | AccessException e) { LOGGER.severe("Could not load image: " + e.getMessage()); } diff --git a/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java b/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java index ab660c1..73090b2 100644 --- a/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java +++ b/src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 MICA & GReD + * Copyright (C) 2021-2023 MICA & GReD * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -97,6 +97,7 @@ public class OMEROBatchRunner extends Thread { private BatchListener listener; + public OMEROBatchRunner(ScriptRunner script, List images, Client client) { this(script, images, client, new ProgressLog(LOGGER)); } @@ -139,7 +140,7 @@ private static String removeExtension(String title) { } else { String afterExt = TITLE_AFTER_EXT.matcher(title.substring(index + 1)).replaceAll("$1"); String beforeExt = title.substring(0, index); - if(beforeExt.toLowerCase().endsWith(".ome") && beforeExt.lastIndexOf('.') > 0) { + if (beforeExt.toLowerCase().endsWith(".ome") && beforeExt.lastIndexOf('.') > 0) { beforeExt = beforeExt.substring(0, beforeExt.lastIndexOf('.')); } return afterExt.isEmpty() ? beforeExt : beforeExt + "_" + afterExt; diff --git a/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java b/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java index e6f8792..90c0ef0 100644 --- a/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java +++ b/src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 MICA & GReD + * Copyright (C) 2021-2023 MICA & GReD * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -18,6 +18,7 @@ import fr.igred.ij.gui.OMEROConnectDialog; import fr.igred.ij.gui.ProgressDialog; +import fr.igred.ij.io.BatchImage; import fr.igred.ij.macro.BatchListener; import fr.igred.ij.macro.OMEROBatchRunner; import fr.igred.ij.macro.ScriptRunner; @@ -58,6 +59,8 @@ import java.util.logging.Logger; import java.util.stream.Collectors; +import static fr.igred.ij.io.LocalBatchImage.listImages; +import static fr.igred.ij.io.OMEROBatchImage.listImages; import static javax.swing.JOptionPane.showMessageDialog; /** @@ -920,43 +923,48 @@ private void previewDataset() { */ public void start(ActionEvent e) { ProgressDialog progress = new ProgressDialog(); - OMEROBatchRunner runner = new OMEROBatchRunner(script, client, progress); - runner.setListener(this); + OMEROBatchRunner runner; - // initiation of success variables + // initialization of success variables boolean checkInput; boolean checkMacro = getMacro(); boolean checkOutput = getOutput(); // input data - if (omero.isSelected()) { - runner.setInputOnOMERO(true); - int index = datasetListIn.getSelectedIndex(); - DatasetWrapper dataset = datasets.get(index); - long inputDatasetId = dataset.getId(); - runner.setInputDatasetId(inputDatasetId); + List images; + long inputDatasetId = -1L; + try { + if (omero.isSelected()) { + int index = datasetListIn.getSelectedIndex(); + DatasetWrapper dataset = datasets.get(index); + inputDatasetId = dataset.getId(); + List imageWrappers = dataset.getImages(client); + images = listImages(client, imageWrappers); + checkInput = true; + } else { // local.isSelected() + checkInput = getLocalInput(); + images = listImages(directoryIn, recursive.isSelected()); + } + runner = new OMEROBatchRunner(script, images, client, progress); runner.setOutputDatasetId(inputDatasetId); - checkInput = true; - } else { // local.isSelected() - runner.setInputOnOMERO(false); - checkInput = getLocalInput(); - runner.setDirectoryIn(directoryIn); - runner.setRecursive(recursive.isSelected()); + runner.setListener(this); + + runner.setSuffix(suffix.getText()); + runner.setLoadROIS(checkLoadROIs.isSelected()); + runner.setClearROIS(checkDelROIs.isSelected()); + runner.setSaveImage(checkImage.isSelected()); + runner.setSaveResults(checkResults.isSelected()); + runner.setSaveROIs(checkROIs.isSelected()); + runner.setSaveLog(checkLog.isSelected()); + } catch (ServiceException | AccessException | ExecutionException | IOException exception) { + IJ.error(exception.getMessage()); + return; } if (!checkInput || !checkMacro || !checkOutput) { return; } - // suffix - runner.setSuffix(suffix.getText()); - - runner.setLoadROIS(checkLoadROIs.isSelected()); - runner.setClearROIS(checkDelROIs.isSelected()); - runner.setSaveImage(checkImage.isSelected()); - runner.setSaveResults(checkResults.isSelected()); - runner.setSaveROIs(checkROIs.isSelected()); - runner.setSaveLog(checkLog.isSelected()); if (onlineOutput.isSelected()) { runner.setOutputOnOMERO(true); if (checkResults.isSelected()) {