Skip to content

Commit

Permalink
Add remove rois (#10)
Browse files Browse the repository at this point in the history
* add example script to remove rois
* changes following @ppouchin 's suggestions in PR
* adds me as a contributor
  • Loading branch information
romainGuiet authored Mar 28, 2022
1 parent 6efee9c commit b928ca2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>fr.igred</groupId>
<artifactId>omero_macro-extensions</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>

<name>ImageJ OMERO macro extensions</name>
<description>Plugin providing macro extensions for OMERO.</description>
Expand Down Expand Up @@ -53,6 +53,10 @@
<name>Pierre Pouchin</name>
<email>[email protected]</email>
</contributor>
<contributor>
<name>Romain Guiet</name>
<email>[email protected]</email>
</contributor>
</contributors>

<mailingLists>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.nio.file.Files;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class OMEROMacroExtension implements PlugIn, MacroExtension {
newDescriptor("getImage", this, ARG_NUMBER),
newDescriptor("getROIs", this, ARG_NUMBER, ARG_NUMBER + ARG_OPTIONAL, ARG_STRING + ARG_OPTIONAL),
newDescriptor("saveROIs", this, ARG_NUMBER, ARG_STRING + ARG_OPTIONAL),
newDescriptor("removeROIs", this, ARG_NUMBER, ARG_STRING + ARG_OPTIONAL),
newDescriptor("sudo", this, ARG_STRING),
newDescriptor("endSudo", this),
newDescriptor("disconnect", this),
Expand Down Expand Up @@ -965,6 +967,29 @@ public int saveROIs(ImagePlus imp, long id, String property) {
return result;
}

/**
* removes the ROIs of the image in OMERO.
*
* @param id The image ID on OMERO.
*
* @return The 1 if at least one ROI has been deleted
*/
public int removeROIs(long id) {

int removed = 0;
try {
ImageWrapper image = client.getImage(id);
List<ROIWrapper> rois = image.getROIs(client);
for (ROIWrapper roi : rois) {
client.delete(roi);
removed++;
}
} catch (ServiceException | AccessException | ExecutionException | OMEROServerError | InterruptedException e) {
IJ.error("Could not remove image ROIs: " + e.getMessage());
}
return removed;
}


/**
* Disconnects from OMERO.
Expand All @@ -979,6 +1004,7 @@ public void disconnect() {
public void run(String arg) {
if (!IJ.macroRunning()) {
IJ.error("Cannot install extensions from outside a macro!");
//TODO print API
return;
}
Functions.registerExtensions(this);
Expand Down Expand Up @@ -1162,6 +1188,12 @@ public String handleExtension(String name, Object[] args) {
results = String.valueOf(nROIs);
break;

case "removeROIs":
id = ((Double) args[0]).longValue();
int removed = removeROIs(id);
results = String.valueOf(removed);
break;

case "sudo":
sudo((String) args[0]);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @String(label="Username") USERNAME
// @String(label="Password", style='password') PASSWORD
// @String(label="Host", value='wss://workshop.openmicroscopy.org/omero-ws') HOST
// @Integer(label="Port", value=4064) PORT
// @Integer(label="Dataset ID", value=2331) dataset_id

run("OMERO Extensions");

connected = Ext.connectToOMERO(HOST, PORT, USERNAME, PASSWORD);



if(connected == "true") {
images = Ext.list("images", "dataset", dataset_id);
image_ids = split(images, ",");

for(i=0; i<image_ids.length; i++) {
// Open the image
Ext.removeROIs(image_ids[i])
}
}


Ext.disconnect();
print("processing done");
8 changes: 8 additions & 0 deletions src/test/java/fr/igred/ij/plugin/OMEROExtensionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import fr.igred.omero.Client;
import fr.igred.omero.annotations.TableWrapper;
import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.OMEROServerError;
import fr.igred.omero.exception.ServiceException;
import ij.ImagePlus;
import ij.gui.Overlay;
import ij.gui.Roi;
Expand All @@ -39,6 +42,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -284,10 +288,14 @@ void testSaveAndGetROIs() {
int savedROIs = ext.saveROIs(imp, 1L, "");
overlay.clear();
int loadedROIs = ext.getROIs(imp, 1L, true, "");
ext.removeROIs(1L);
int clearedROIs = ext.getROIs(imp, 1L, true, "");


assertEquals(1, savedROIs);
assertEquals(1, loadedROIs);
assertEquals(1, imp.getOverlay().size());
assertEquals(0, clearedROIs);
}


Expand Down

0 comments on commit b928ca2

Please sign in to comment.