Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed project and switched to simple-omero-client 5.8.3 #3

Merged
merged 7 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[![Java CI with Maven](https://github.com/GReD-Clermont/omero_macroextensions/actions/workflows/maven.yml/badge.svg)](https://github.com/GReD-Clermont/omero_macroextensions/actions/workflows/maven.yml)
[![Java CI with Maven](https://github.com/GReD-Clermont/omero_macro-extensions/actions/workflows/maven.yml/badge.svg)](https://github.com/GReD-Clermont/omero_macro-extensions/actions/workflows/maven.yml)

# omero_macroextensions
# OMERO Macro Extensions

A plugin for ImageJ to provide macro extensions to access OMERO.

## How to install

1. Install the [OMERO.insight plugin for Fiji](https://omero-guides.readthedocs.io/en/latest/fiji/docs/installation.html) (if you haven't already).
1. Install
the [OMERO.insight plugin for Fiji](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/latest/).
3. Download the JAR file ([for this plugin](https://github.com/GReD-Clermont/omero_macroextensions/releases/latest/)).
3. Download the JAR file ([for this plugin](https://github.com/GReD-Clermont/omero_macro-extensions/releases/latest/)).
4. Place these JAR files in your plugins folder.

## How to use
Expand Down Expand Up @@ -156,7 +158,7 @@ projectId = Ext.createProject(name, description);
Datasets can be created with *Ext.createDataset*:

```
datasetId = Ext.createDataset(projectId, name, description);
datasetId = Ext.createDataset(name, description, projectId);
```

Tags can be created with *Ext.createTag*:
Expand Down Expand Up @@ -189,14 +191,17 @@ Pixel intensities can be retrieved from images:
imageplusID = Ext.getImage(imageIds[0]);
```

ROIs from OMERO can also be added to the ROI manager (and the current image):
ROIs from OMERO can also be added to the ROI manager (and the current image). ROIs composed of multiple shapes (eg
3D/4D) will share the same values in the "ROI" and "ROI_ID" properties in ImageJ. These can be optionnally changed with
the "property" parameter: local indices will be in "property" while OMERO IDs will be in "property + _ID".
This is achieved through:

```
nIJROIs = Ext.getROIs(imageIds[0]);
nIJROIs = Ext.getROIs(imageIds[0], property);
```

Conversely, ImageJ ROIs can also be saved to OMERO (the property is used to group ImageJ shapes into a single 3D/4D ROI
on OMERO):
on OMERO, if the string is empty, "ROI" is used):

```
nROIS = Ext.saveROIs(imageId, property);
Expand Down Expand Up @@ -229,7 +234,7 @@ Ext.deleteFile(fileId);
A table can be created/updated using the results with *Ext.addToTable*:

```
Ext.addToTable(tableName, resultsName, imageId);
Ext.addToTable(tableName, resultsName, imageId, roiProperty);
```

If a column named ROI containing ROI IDs is present, these will be added to the table. Alternatively, if ROIs that were
Expand All @@ -240,14 +245,12 @@ The table can then be saved to a project/dataset/image through *Ext.saveTable*:

```
Ext.saveTable(tableName, 'dataset', datasetId);

```

It can then be saved to a tab-separated text file through *Ext.saveTableAsTXT*:

```
Ext.saveTableAsTXT(tableName, pathToTXT);

```

### Work as another user (sudo)
Expand Down
19 changes: 9 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
</parent>

<groupId>fr.igred</groupId>
<artifactId>omero_macroextensions</artifactId>
<artifactId>omero_macro-extensions</artifactId>
<version>1.0.1</version>

<name>ImageJ OMERO macro extensions</name>
<description>Plugin providing macro extensions for OMERO.</description>
<url>https://github.com/GReD-Clermont/omero_macroextensions</url>
<url>https://github.com/GReD-Clermont/omero_macro-extensions</url>
<inceptionYear>2021</inceptionYear>

<organization>
Expand Down Expand Up @@ -63,24 +63,24 @@
</mailingLists>

<scm>
<connection>scm:git:git://github.com/GReD-Clermont/omero_macroextensions</connection>
<developerConnection>scm:git:[email protected]:GReD-Clermont/omero_macroextensions</developerConnection>
<connection>scm:git:git://github.com/GReD-Clermont/omero_macro-extensions</connection>
<developerConnection>scm:git:[email protected]:GReD-Clermont/omero_macro-extensions</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/GReD-Clermont/omero_macroextensions</url>
<url>https://github.com/GReD-Clermont/omero_macro-extensions</url>
</scm>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/GReD-Clermont/omero_macroextensions/issues</url>
<url>https://github.com/GReD-Clermont/omero_macro-extensions/issues</url>
</issueManagement>
<ciManagement>
<system>GitHub Actions</system>
<url>https://github.com/GReD-Clermont/omero_macroextensions/actions</url>
<url>https://github.com/GReD-Clermont/omero_macro-extensions/actions</url>
</ciManagement>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub GReD-Clermont Apache Maven Packages</name>
<url>https://maven.pkg.github.com/GReD-Clermont/omero_macroextensions</url>
<url>https://maven.pkg.github.com/GReD-Clermont/omero_macro-extensions</url>
</repository>
</distributionManagement>

Expand All @@ -91,7 +91,7 @@
<license.licenseName>gpl_v2</license.licenseName>
<license.copyrightOwners>GReD</license.copyrightOwners>
<allowedDuplicateClasses>com.esotericsoftware.kryo.*,com.esotericsoftware.minlog.*,com.esotericsoftware.reflectasm.*</allowedDuplicateClasses>
<soc.version>5.8.2</soc.version>
<soc.version>5.8.3</soc.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -122,7 +122,6 @@
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
<version>1.53c</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static ij.macro.ExtensionDescriptor.newDescriptor;


public class OMEROExtension implements PlugIn, MacroExtension {
public class OMEROMacroExtension implements PlugIn, MacroExtension {

private static final String PROJECT = "project";
private static final String DATASET = "dataset";
Expand All @@ -65,11 +65,12 @@ public class OMEROExtension implements PlugIn, MacroExtension {
newDescriptor("switchGroup", this, ARG_NUMBER),
newDescriptor("list", this, ARG_STRING, ARG_STRING + ARG_OPTIONAL, ARG_NUMBER + ARG_OPTIONAL),
newDescriptor("createDataset", this, ARG_STRING, ARG_STRING, ARG_NUMBER + ARG_OPTIONAL),
newDescriptor("createProject", this, ARG_NUMBER, ARG_STRING, ARG_STRING),
newDescriptor("createProject", this, ARG_STRING, ARG_STRING),
newDescriptor("createTag", this, ARG_STRING, ARG_STRING),
newDescriptor("link", this, ARG_STRING, ARG_NUMBER, ARG_STRING, ARG_NUMBER),
newDescriptor("addFile", this, ARG_STRING, ARG_NUMBER, ARG_STRING),
newDescriptor("addToTable", this, ARG_STRING, ARG_STRING + ARG_OPTIONAL, ARG_NUMBER + ARG_OPTIONAL),
newDescriptor("addToTable", this, ARG_STRING,
ARG_STRING + ARG_OPTIONAL, ARG_NUMBER + ARG_OPTIONAL, ARG_STRING + ARG_OPTIONAL),
newDescriptor("saveTable", this, ARG_STRING, ARG_STRING, ARG_NUMBER),
newDescriptor("saveTableAsTXT", this, ARG_STRING, ARG_STRING),
newDescriptor("clearTable", this, ARG_STRING),
Expand All @@ -78,8 +79,8 @@ public class OMEROExtension implements PlugIn, MacroExtension {
newDescriptor("delete", this, ARG_STRING, ARG_NUMBER),
newDescriptor("getName", this, ARG_STRING, ARG_NUMBER),
newDescriptor("getImage", this, ARG_NUMBER),
newDescriptor("getROIs", this, ARG_NUMBER),
newDescriptor("saveROIs", this, ARG_NUMBER, ARG_STRING),
newDescriptor("getROIs", this, ARG_NUMBER, ARG_STRING + ARG_OPTIONAL),
newDescriptor("saveROIs", this, ARG_NUMBER, ARG_STRING + ARG_OPTIONAL),
newDescriptor("sudo", this, ARG_STRING),
newDescriptor("endSudo", this),
newDescriptor("disconnect", this),
Expand Down Expand Up @@ -109,6 +110,18 @@ private static String singularType(String type) {
}


private static Long doubleToLong(Double d) {
if (d != null) return d.longValue();
else return null;
}


private static ResultsTable getTable(String resultsName) {
if (resultsName == null) return ResultsTable.getResultsTable();
else return ResultsTable.getResultsTable(resultsName);
}


private GenericObjectWrapper<?> getObject(String type, long id) {
String singularType = singularType(type);

Expand Down Expand Up @@ -144,7 +157,7 @@ private GenericRepositoryObjectWrapper<?> getRepositoryObject(String type, long
default:
IJ.error(INVALID + ": " + type + ".");
}
} catch (ServiceException | AccessException e) {
} catch (ServiceException | AccessException | ExecutionException e) {
IJ.error("Could not retrieve object: " + e.getMessage());
}
return object;
Expand All @@ -156,7 +169,7 @@ public boolean connect(String host, int port, String username, String password)
try {
client.connect(host, port, username, password.toCharArray());
connected = true;
} catch (ServiceException | ExecutionException e) {
} catch (ServiceException e) {
IJ.error("Could not connect: " + e.getMessage());
}
return connected;
Expand All @@ -167,7 +180,7 @@ public String downloadImage(long imageId, String path) {
List<File> files = new ArrayList<>();
try {
files = client.getImage(imageId).download(client, path);
} catch (ServiceException | AccessException | OMEROServerError e) {
} catch (ServiceException | AccessException | OMEROServerError | ExecutionException e) {
IJ.error("Could not download image: " + e.getMessage());
}
return files.stream().map(File::toString).collect(Collectors.joining(","));
Expand Down Expand Up @@ -227,23 +240,16 @@ public void deleteFile(long fileId) {
}


public void addToTable(String tableName, String resultsName, Long imageId) {
ResultsTable rt;
if (tableName == null) rt = ResultsTable.getResultsTable();
else rt = ResultsTable.getResultsTable(resultsName);

RoiManager rm = RoiManager.getRoiManager();
List<Roi> ijRois = Arrays.asList(rm.getRoisAsArray());

public void addToTable(String tableName, ResultsTable results, Long imageId, List<Roi> ijRois, String property) {
TableWrapper table = tables.get(tableName);

try {
if (table == null) {
table = new TableWrapper(client, rt, imageId, ijRois, ROIWrapper.IJ_PROPERTY);
table = new TableWrapper(client, results, imageId, ijRois, property);
table.setName(tableName);
tables.put(tableName, table);
} else {
table.addRows(client, rt, imageId, ijRois, ROIWrapper.IJ_PROPERTY);
table.addRows(client, results, imageId, ijRois, property);
}
} catch (ExecutionException | ServiceException | AccessException e) {
IJ.error("Could not add results to table: " + e.getMessage());
Expand Down Expand Up @@ -384,7 +390,7 @@ public String list(String type) {
default:
IJ.error(INVALID + ": " + type + ". Possible values are: projects, datasets, images or tags.");
}
} catch (ServiceException | AccessException | OMEROServerError e) {
} catch (ServiceException | AccessException | OMEROServerError | ExecutionException e) {
IJ.error("Could not retrieve " + type + ": " + e.getMessage());
}
return results;
Expand Down Expand Up @@ -416,7 +422,7 @@ public String list(String type, String name) {
default:
IJ.error(INVALID + ": " + type + ". Possible values are: projects, datasets, images or tags.");
}
} catch (ServiceException | AccessException | OMEROServerError e) {
} catch (ServiceException | AccessException | OMEROServerError | ExecutionException e) {
IJ.error("Could not retrieve project name: " + e.getMessage());
}
return results;
Expand Down Expand Up @@ -585,7 +591,7 @@ public ImagePlus getImage(long id) {
}


public int getROIs(long id) {
public int getROIs(long id, String property) {
List<ROIWrapper> rois = new ArrayList<>();
try {
ImageWrapper image = client.getImage(id);
Expand All @@ -596,7 +602,7 @@ public int getROIs(long id) {

ImagePlus imp = IJ.getImage();

List<Roi> ijRois = ROIWrapper.toImageJ(rois);
List<Roi> ijRois = ROIWrapper.toImageJ(rois, property);

RoiManager rm = RoiManager.getInstance();
if (rm == null) rm = RoiManager.getRoiManager();
Expand Down Expand Up @@ -631,7 +637,7 @@ public int saveROIs(long id, String property) {
}
result = rois.size();
rm.reset();
this.getROIs(id);
this.getROIs(id, property);
} catch (ServiceException | AccessException | ExecutionException e) {
IJ.error("Could not save ROIs to image: " + e.getMessage());
}
Expand Down Expand Up @@ -707,8 +713,7 @@ public String handleExtension(String name, Object[] args) {
break;

case "createDataset":
Long projectId = null;
if (args[2] != null) projectId = ((Double) args[2]).longValue();
Long projectId = doubleToLong((Double) args[2]);
id = createDataset((String) args[0], (String) args[1], projectId);
results = String.valueOf(id);
break;
Expand All @@ -726,13 +731,20 @@ public String handleExtension(String name, Object[] args) {
case "addToTable":
tableName = (String) args[0];
String resultsName = (String) args[1];
Long imageId = null;
if (args[2] != null) imageId = ((Double) args[2]).longValue();
addToTable(tableName, resultsName, imageId);
Long imageId = doubleToLong((Double) args[2]);
String property = (String) args[3];

ResultsTable rt = getTable(resultsName);
RoiManager rm = RoiManager.getRoiManager();
List<Roi> ijRois = Arrays.asList(rm.getRoisAsArray());

addToTable(tableName, rt, imageId, ijRois, property);
break;

case "saveTableAsTXT":
saveTableAsTXT((String) args[0], (String) args[1]);
tableName = (String) args[0];
path = (String) args[1];
saveTableAsTXT(tableName, path);
break;

case "saveTable":
Expand Down Expand Up @@ -791,13 +803,15 @@ public String handleExtension(String name, Object[] args) {
break;

case "getROIs":
int nIJRois = getROIs(((Double) args[0]).longValue());
id = ((Double) args[0]).longValue();
property = (String) args[1];
int nIJRois = getROIs(id, property);
results = String.valueOf(nIJRois);
break;

case "saveROIs":
id = ((Double) args[0]).longValue();
String property = ((String) args[1]);
property = (String) args[1];
int nROIs = saveROIs(id, property);
results = String.valueOf(nROIs);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/omero.extensions.plugins.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Plugins>OMERO, "OMERO Extensions", fr.igred.ij.plugin.OMEROExtension("")
Plugins>OMERO, "OMERO Extensions", fr.igred.ij.plugin.OMEROMacroExtension("")
Loading