We're Hiring!

Relationship between MapAnnotationData and MapAnnotationI?

General user discussion about using the OMERO platform to its fullest. Please ask new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

There are workflow guides for various OMERO functions on our help site - http://help.openmicroscopy.org

You should find answers to any basic questions about using the clients there.

Relationship between MapAnnotationData and MapAnnotationI?

Postby Kouichi_C_Nakamura » Mon Jan 28, 2019 4:05 pm

Hello,

Now I'm trying to add MapAnnotation using Java Gateway from MATLAB.

In the client-session approach, ``writeMapAnnotation.m`` and ``linkAnnotation.m`` were used.

``writeMapAnnotation()`` returns a MapAnnotationI object saved in OMERO and ``linkAnnotation()`` can link that to an image.

Reading this (https://github.com/ome/omero-matlab/issues/5), I thought I should make ``writeMapAnnotation`` accept gateway in place of session. There seems no Gateway equivalent of ``linkAnnotation.m``

``writeMapAnnotation`` returns a MapAnnotationI object. However, DataManagerFacility.attachAnnotation takes ``MapAnnotationData`` object rather than ``MapAnnotationI``. So I needed to construct a ``MapAnnotationData`` object.

Code: Select all
mad = MapAnnotationData(ma)


, where ``ma`` is ``MapAnnotationI``, was easy to be done. And that was followed by

Code: Select all
mad2 = dmf.attachAnnotation(ctx,mad,image1)


This actually worked.

I've noticed the saved MapAnnotation's Id (confirmed from OMERO.web GUI) is that of ``mad`` rather than that of ``ma``. I'm wondering why?

There seems no way to retrieve MapAnnotationI object from MapAnnotationData. What's the relationship between them?

Best,
Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: Relationship between MapAnnotationData and MapAnnotation

Postby Dominik » Tue Jan 29, 2019 10:16 am

Hi Kouichi,

the MapAnnotationData is a simple Java wrapper around the Ice object MapAnnotationI (like ProjectData vs ProjectI, etc.). Usually the wrappers provide some helper methods to modify the objects. Unfortunately the MapAnnotationData doesn't, so you'd have to get the underlying MapAnnotationI object. You can do that via the asIObject() method and cast, i.e.
Code: Select all
MapAnnotationData mad = new MapAnnotationData();
MapAnnotationI ma = (MapAnnotationI) mad.asIObject();


I wonder where your ID discrepancy comes from. If you create an empty MapAnnotationData() object its ID should be -1. If you create a MapAnnotationData(MapAnnotationI ma) from an existing MapAnnotationI it has the same ID (getId() simply gets the ID from the underlying MapAnnotationI object). And if you save that again, the ID shouldn't change. I'm not sure what this matlab function writeMapAnnotation does, maybe it actually doesn't write the MapAnnotation to the database so it doesn't have an ID yet? I'll have to investigate. The attachAnnotation method in the Java gateway writes and links the annotation object, there's no need for separate write and link calls.

Regards,
Dominik
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am

Re: Relationship between MapAnnotationData and MapAnnotation

Postby Kouichi_C_Nakamura » Tue Jan 29, 2019 10:42 am

Thank you for the ``DataObject.asIObject()`` method. This is what I was looking for.

And thank you for the explanation of the concepts, as well. I always wonder if this kind of human-friendly information is included in API Java docs, because that what we always have to look at. Or it may be even better if API Java docs include hyperlinks to the relevant OMERO documentation.

As to the ID discrepancy, it did happen, or at least I thought so, but later when I became more confident about this operation, IDs were shared between IObjects and DataObjects. Perhaps I did something wrong before. If I find this happens again, I'll let you know. I'll keep an eye on it.

I guess there have been very few attempts, if any, of using Jave Gateway from MATLAB done before, but it's working. We still need to refine tools though.


Best,
Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 1 guest