We're Hiring!

OMERO APIs for free format/ key-value search

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.

Re: OMERO APIs for free format/ key-value search

Postby pz3977 » Wed Aug 13, 2014 9:42 pm

Hi,
Thanks Will for the reply. I managed to upload a script but without --official since I am not admin. However, I feel using the scripts is not the way I am looking for since I am not using OMERO.insight etc. I am interested in searching metadata using APIs, and extract those metadata. For this purpose I tried:

for i in conn.searchObjects(["Image"], "*lens*"):
print i.OMERO_CLASS, i.getId(), i.getName()
print i.loadOriginalMetadata()

for some files such as .tiff or .czi I got some result but for some others such as .mrc, it give an error:

return self.c.waitOnCmd(handle, loops=loops, ms=ms, failonerror=failonerror)
File "../OMEROpy/lib/python/omero/clients.py", line 831, in waitOnCmd
raise omero.CmdError(rsp)
omero.CmdError

My questions are: Is loadOriginalMetadata() an appropriate function to get metadata or you have other suggestions? why it gives error for some files and how I can solve it?

Thanks for your patience.

Best regards,
pz3977
pz3977
 
Posts: 31
Joined: Thu Jul 10, 2014 11:39 am

Re: OMERO APIs for free format/ key-value search

Postby wmoore » Wed Aug 13, 2014 10:39 pm

Hi,

The image.loadOriginalMetadata() function gives you the same key-value pairs that you can access from the clients in the right hand "Acquisition" tab, under "Original Metadata".
It contains all the metadata read from the original imported image file (including info that doesn't have a place in the OMERO data model), but this is read from the file each time, not the database, so you can't do search queries on it.

The OMERO.script was really just a code example, so don't worry about trying to upload it.
You should probably just take the searchImages() function from it....

OK, I've created an example that's a simpler stand-alone script you can run:
https://gist.github.com/will-moore/bc9b3e5d87d60067caa7

You can see that it performs a bunch of searches as examples.
As I said, adding more fields to the query requires some knowledge of the OMERO model, so let us know if you need help with anything specific.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: OMERO APIs for free format/ key-value search

Postby pz3977 » Fri Aug 15, 2014 8:12 am

Hi wmoore,

Thank you so much for your reply and excellent example. It works perfect and I will use it for key-value search.
Regarding your explanation about loadOriginalMetadata(), as I mentioned in my previous post, my intension is to extract metadata and store it in my system after search. Let me elaborate it more for keyword search:

These are the steps:
1. Search the images which has 'keyword', any where in their metadata
2. Get the image Ids from the result of previous step
3. Extract all the metadata of the image Ids from previous step(no matter from file or database) and store it in my system

for the first and second step I used:
for i in conn.searchObjects(["Image"], "*lens*"):
print i.OMERO_CLASS, i.getId(), i.getName()

and for the third step I had plan to use loadOriginalMetadata(). As I said it raise error for some kind of files such as 'mrc', but it works for tiff or czi. so my question is : why it gives error for some files and how I can solve it?

Thanks for your patience

Best regards,
pz3977
pz3977
 
Posts: 31
Joined: Thu Jul 10, 2014 11:39 am

Re: OMERO APIs for free format/ key-value search

Postby wmoore » Fri Aug 15, 2014 2:51 pm

Hi,

By default, you can only search for keywords in the indexed fields See https://www.openmicroscopy.org/site/sup ... ield-names

Adding extra fields requires building a search bridge: https://www.openmicroscopy.org/site/sup ... idges.html

The Original Metadata is not currently indexed (ticket to fix that is http://trac.openmicroscopy.org/ome/ticket/12376).


I've just tried image.loadOriginalMetadata() for a handful of mrc files and I didn't see any problems. Can you upload a sample file at http://qa.openmicroscopy.org.uk/qa/upload/ (you might have to zip it if you don't see .mrc format there) and we'll see if we can reproduce the problem. Maybe reply here with the ID you get if we don't respond directly.

Thanks.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: OMERO APIs for free format/ key-value search

Postby pz3977 » Mon Aug 18, 2014 10:23 am

Hi wmoore,

Thanks for the reply.
It seems the problem which I reported about mrc files, is raised when one specific file is included in my search.
I am doing a research project and my test is on several files which are uploaded on omero.ohsu.edu. Unfortunately, I could not download that specifc file which raise error to send it to you. Its ID = '13471' and the name= 'S1_Helios_2of3_full.mrc', if in any case it helps.

The following is the error :
Traceback (most recent call last):
File "testSearch.py", line 24, in <module>
print i.loadOriginalMetadata()
File ".../OMERO.py/lib/python/omero/gateway/__init__.py", line 6389, in loadOriginalMetadata
cb = self._conn._waitOnCmd(handle)
File ".../OMERO.py/lib/python/omero/gateway/__init__.py", line 3438, in _waitOnCmd
closehandle=closehandle)
File ".../OMERO.py/lib/python/omero/clients.py", line 856, in waitOnCmd
raise omero.CmdError(rsp)
omero.CmdError


Best regards,
pz3977
pz3977
 
Posts: 31
Joined: Thu Jul 10, 2014 11:39 am

Re: OMERO APIs for free format/ key-value search

Postby wmoore » Mon Aug 18, 2014 10:42 am

Hi,

Ahh, so you don't have the image apart from in OMERO.
Is there a reason that you can't download that Original file from OMERO? Do Insight or web allow you to download it? Do you see an error message if you try?
Does that image '13471' look OK in other ways? (does it display OK in the main image viewers)?
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: OMERO APIs for free format/ key-value search

Postby pz3977 » Mon Aug 18, 2014 3:12 pm

Hi,

Ohhh, I think the file is corrupted since image viewer cannot open it. Sorry to waste your time!

Regards,
pz3977
pz3977
 
Posts: 31
Joined: Thu Jul 10, 2014 11:39 am

Previous

Return to User Discussion

Who is online

Users browsing this forum: No registered users and 1 guest