Page 1 of 1

Relationship between MapAnnotationData and MapAnnotationI?

PostPosted: Mon Jan 28, 2019 4:05 pm
by Kouichi_C_Nakamura
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

Re: Relationship between MapAnnotationData and MapAnnotation

PostPosted: Tue Jan 29, 2019 10:16 am
by Dominik
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

Re: Relationship between MapAnnotationData and MapAnnotation

PostPosted: Tue Jan 29, 2019 10:42 am
by Kouichi_C_Nakamura
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