OMERO Java: tags list, ROI modification and tables id

Hello,

We are currently working with OMERO Java and we’re wondering a few things:

  1. How do you get a list of all the tags a user can access using the Java API?
  2. What’s the best way to remove a shape from a ROI without removing/recreating the whole ROI?
  3. Is it possible to access an OMERO.table through its “Id” rather than through its “fileId”?

Cheers,

Pierre

Hi Pierre,

are you using the Java Gateway or the ‘plain’ Java API? There’s no method to retrieve all tags in the gateway yet, but you can do it via the QueryService:

import omero.gateway.Gateway
import omero.gateway.model.TagAnnotationData;
import omero.model.TagAnnotation;

// Gateway gw = .... login etc.

IQueryPrx qs = gw.getQueryService(ctx);
List<IObject> tmp = qs.findAll(TagAnnotation.class.getSimpleName(), null);
List<TagAnnotationData> tags = tmp.stream()
                .map(t -> new TagAnnotationData((TagAnnotation) t))
                .collect(Collectors.toList());

You can remove the Shape of a ROI and save it again. But I just discovered a bug in the Java Gateway doing this. Usually you would use the save method of the ROIFacitliy. But if you save a modified ROI back via this method it doesn’t work, you have to use the UpdateService instead, e. g.

import omero.gateway.facility.ROIFacility;

ROIFacility rf = gw.getFacility(ROIFacility.class);
ROIData roi = rf.loadROI(ctx, roiId).getROIs().iterator().next();
// ShapeData toRemove = ...
roi.removeShapeData(toRemove);
roi = new ROIData((Roi)gw.getUpdateService(ctx).saveAndReturnObject(roi.asIObject()));

It isn’t really smooth yet, so you have to do quite a few conversions between the ‘raw’ model objects (e.g. TagAnnotation) and the more usable gateway model objects (e.g. TagAnnotationData; ROIs respectively).

Your question about the OMERO.table. I’m not quite sure what you mean. The table itself doesn’t have an ID. The table is basically just an HDF5 file, hence the file ID.

Regards,
Dominik

Thank you for these answers.
We are using the Java Gateway, and saw many methods to retrieve all kinds of containers, but not tags, so we were not sure what was the best way to do it. Therefore, we’ll now use the QueryService.

As for the ROIs, we tried to save and noticed it didn’t work, but we weren’t sure if it was because of a bug or because we missed something.

Finally, we just thought there was an ID other than the FileID, but we were wrong, so there’s our answer.

Once again, thank you for your help!

I’m back for another question related to the first one (accessing tags through Java Gateway):
when you get a tag (or any other kind of annotation for that matter), how can you get the linked objects?
The only relevant method in the TagAnnotationData class might be “getDataObjects()”, but it returns nothing (there’s a “FIXME” in the code which may be related?). Also, there is nothing similar for other annotation classes (like MapAnnotationData).
Should we go through “omero.model.Annotation”? Or use the QueryService once again somehow?

In the BlitzGateway, a custom query is used and fetches all the annotation links, but it seems a bit overkill when you already know for which annotation you want links, unless it’s not possible?

Hi Pierre.
The BlitzGateway example fetches all the annotations attached to specific objects. As far as I understand your case is the other way round, you have the annotation and want to get all the objects it’s attached too. I don’t think there’s a method in the Java gateway for that yet. I’ll open an issue on github later to collect these ideas. For now I think QueryService / HQL is your best option. If you want to get all objects, I’m afraid you have to loop through all the ‘annotation link’ types. So for example you have a Tag with id 123, then you can find out to which Projects it is attached to by select link.parent from ProjectAnnotationLink link where link.child = 123. DatasetAnnotationLink, ImageAnnotationLink, etc. accordingly.
Regards,
Dominik

You might try:

select link from ome.model.IAnnotationLink link where link.child.id = 23041350

~Josh

Ok. Thank you Dominik and Josh!