We're Hiring!

retrieving "tag" API?

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please 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

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

retrieving "tag" API?

Postby bhcho » Thu Dec 09, 2010 9:32 pm

Hi All,

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

Best,
BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: retrieving "tag" API?

Postby jmoore » Fri Dec 10, 2010 10:26 am

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
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: retrieving "tag" API?

Postby bhcho » Fri Dec 10, 2010 3:52 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: retrieving "tag" API?

Postby jmoore » Fri Dec 10, 2010 5:20 pm

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
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: retrieving "tag" API?

Postby bhcho » Fri Dec 10, 2010 5:53 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: retrieving "tag" API?

Postby jmoore » Fri Dec 10, 2010 6:06 pm

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.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: retrieving "tag" API?

Postby bhcho » Fri Dec 10, 2010 6:21 pm

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)
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: retrieving "tag" API?

Postby jmoore » Fri Dec 10, 2010 7:23 pm

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
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: retrieving "tag" API?

Postby bhcho » Fri Dec 10, 2010 7:40 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: retrieving "tag" API?

Postby jmoore » Fri Dec 10, 2010 8:09 pm

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.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Next

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest