Page 1 of 2

retrieving "tag" API?

PostPosted: Thu Dec 09, 2010 9:32 pm
by bhcho
Hi All,

Is there any API that can set/retrieve the "tag" on/from images?

Best,
BK

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 10:26 am
by jmoore
Hi BK,

you may want to take a look at the IMetadata interface for loading annotations. If that doesn't fulfill your needs for the moment, you'll need to use IQuery. For creating annotations, everything takes place via creating model objects, linking them appropriately, and passing them to one of the save methods on IUpdate.

Cheers,
~Josh

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 3:52 pm
by bhcho
Hi Josh,

I'm now using Matlab interface.
Could you show me a snippet to retrieve all tags attached to an image, assuming that I have an image ID?

Best,
BK

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 5:20 pm
by jmoore
Sure, BK. Added an example in: http://trac.openmicroscopy.org.uk/omero/changeset/8744

Code: Select all
% Simple example of using omero.api.IMetadataPrx
% to retrieve the annotations associated with an
% Image.

[client, sf] = loadOmero;
try

    metadataService = sf.getMetadataService();

    imageIds = java.util.ArrayList();
    imageIds.add(java.lang.Long(1));

    annotationTypes = java.util.ArrayList();
    annotationTypes.add('TagAnnotation');

    % Unused
    annotatorIds = java.util.ArrayList();
    parameters = omero.sys.Parameters();

    idSetMap = metadataService.loadAnnotations('Image', imageIds, annotationTypes, annotatorIds, parameters);
    itr = idSetMap.keySet().iterator();
    while itr.hasNext()
        disp(itr.next()); % Each image id in imageIds
    end

catch ME

    disp(ME);
    client.closeSession();

end


Cheers,
~Josh

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 5:53 pm
by bhcho
Hi Josh,

After I run the code, the results displays only the file ID.

imageIds = java.util.ArrayList();
imageIds.add(java.lang.Long(1));

in this part I put the image file ID instead of "1", such as 4779.
And the result is that file ID again.
I clearly put some text tag to that Image from OMERO.Insight though.

Am I misunderstanding something?

BK

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 6:06 pm
by jmoore
imageIds = java.util.ArrayList();
imageIds.add(java.lang.Long(1));
in this part I put the image file ID instead of "1", such as 4779.


Right.

And the result is that file ID again.
I clearly put some text tag to that Image from OMERO.Insight though.

Am I misunderstanding something?


The return value is a map from the ids to a set of annotations. See IMetadata.loadAnnotations. Are there any values in the map for the id?
Code: Select all
idSetMap.get(itr.next());


~J.

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 6:21 pm
by bhcho
it's just like below


Code: Select all
>> idSetMap

idSetMap =

{4777=[]}


where 4777 is the file ID.

and when I do that,
Code: Select all
>> idSetMap.get(itr.next())
??? Java exception occurred:
java.util.NoSuchElementException
        at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
        at java.util.HashMap$KeyIterator.next(Unknown Source)

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 7:23 pm
by jmoore
My apologies, BK. In cleaning up the code I shortened the class name to "TagAnnotation", but that is not currently accepted by the method. You will need to use the full, internal class name:


Code: Select all
ome.model.annotations.TagAnnotation


I've updated the example.

Cheers,
~Josh

See: http://trac.openmicroscopy.org.uk/omero/ticket/3671

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 7:40 pm
by bhcho
Thanks Josh,

Now I got something.

Code: Select all
>> idSetMap             

idSetMap =

{4776=[omero.model.TagAnnotationI@760951a0]}


Could you tell me how to retrieve all the text tag from this Map?

BK

Re: retrieving "tag" API?

PostPosted: Fri Dec 10, 2010 8:09 pm
by jmoore
For each annotation object in the set, you want to call:
Code: Select all
tag.getTextValue().getValue()

keeping in mind that getTextValue() could return null. Here's how I would do it in Python:


Code: Select all
In [3]: m = client.sf.getMetadataService()

In [4]: images = client.sf.getQueryService().findAll("Image",None)

In [5]: idSetMap = m.loadAnnotations("Image",[x.id.val for x in images], ["ome.model.annotations.TagAnnotation"], [],None)

In [6]: for k,v in idSetMap.items():
   ...:     if len(v) > 0:
   ...:         print k, [x.getTextValue().getValue() for x in v if x.getTextValue() is not None]

4518 ['Classlabel: 2']
4520 ['Classlabel: 1']
4519 ['Classlabel: 1']


~J.