Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get objects by map annotations #285

Merged
merged 5 commits into from
Aug 25, 2021

Conversation

will-moore
Copy link
Member

@will-moore will-moore commented Apr 6, 2021

See request for "How to query objects by map annotation?"
We don't have any examples at https://docs.openmicroscopy.org/omero/5.6.3/developers/Python.html
and need to look into Mapr source to find out how.
https://forum.image.sc/t/harmonization-of-image-metadata-for-different-file-formats-omero-mde/50827/10

This adds method to gateway:

conn.getObjectsByMapAnnotations('Image', key='Primary Antibody')

conn.getObjectsByMapAnnotations('Image', value='ACA', ns="openmicroscopy.org/omero/client/mapAnnotation")

conn.getObjectsByMapAnnotations('Image', key='Primary Antibody', value='ACA')

To consider:

  • We could allow wild-card queries (as used for auto-complete in mapr)
  • One way to support this would be to allow the 'key' or 'value' to start/end with *: e.g. key='Anti*'
  • The BlitzGateway code could replace the * with %% and use like in the HQL query.

TODO:

  • add tests... (Done - thanks Dom)
  • Add docstring

@will-moore will-moore changed the title Use opts for limit & offset, same as getObjects() get objects by map annotations Apr 6, 2021
@pwalczysko
Copy link
Member

used folllowing workflow to set up the testing env:

  1. create a new conda env as per https://docs.openmicroscopy.org/omero/5.6.3/users/cli/installation.html
  2. run following:
pip uninstall omero-py
pip install git+https://github.com/will-moore/omero-py.git@get_objects_by_map_annotations

Use a script which contains lines from the description of this PR

@pwalczysko
Copy link
Member

pwalczysko commented Apr 7, 2021

What is the way to sanitize one's script against the case that no images with specified KVPs were found ? The "generator" object which is returned by the methods added here has not a length zero even if turned into a list and checked for length ?

Constantly crashing on things like

<generator object _BlitzGateway.getObjects at 0x10ec0deb8>
WARNING:omero.gateway:ApiUsageException on <class 'omero.gateway.OmeroGatewaySafeCallWrapper'> to <dd32cf4a-c600-4149-80b6-f7ad7bd1aa64omero.api.IQuery> findAllByQuery(('select obj from Image obj join fetch obj.details.owner as owner join fetch obj.details.creationEvent where obj.id in (:ids)', object #0 (::omero::sys::Parameters)
{
    map = 
    {
        key = ids
        value = object #1 (::omero::RList)
        {
            _val = 
            {
            }
        }
    }
    theFilter = <nil>
    theOptions = <nil>
}, <ServiceOptsDict: {'omero.client.uuid': 'dd32cf4a-c600-4149-80b6-f7ad7bd1aa64', 'omero.session.uuid': '3d72dd68-4075-48c4-9d6d-f370c6f61e17'}>), {})
Traceback (most recent call last):
  File "/Users/pwalczysko/miniconda3/envs/env563/lib/python3.6/site-packages/omero/gateway/__init__.py", line 4832, in __call__
    return self.f(*args, **kwargs)
  File "/Users/pwalczysko/miniconda3/envs/env563/lib/python3.6/site-packages/omero_api_IQuery_ice.py", line 710, in findAllByQuery
    return _M_omero.api.IQuery._op_findAllByQuery.invoke(self, ((query, params), _ctx))
omero.ApiUsageException: exception ::omero::ApiUsageException
{
    serverStackTrace = ome.conditions.ApiUsageException: unexpected end of subtree [select obj from ome.model.core.Image obj join fetch obj.details.owner as owner join fetch obj.details.creationEvent where obj.id in ()]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [select obj from ome.model.core.Image obj join fetch obj.details.owner as owner join fetch obj.details.creationEvent where obj.id in ()]

The bit of code which is crashing is not the new method itself, but the following code which is trying to consume the "generator" object created by the method...

...
result2 = conn.getObjectsByMapAnnotations('Image', key='Primar Antibody')
	print ("result2", "\n")
	print(result2)
	if len(list(result2)) > 0:
		for i in result2:
			print(i.name, "\n", i.id)
...

The bit inside the for loop above is crashing, but only when no images are found. When some images are found, then the script ends with a success.

@pwalczysko
Copy link
Member

pwalczysko commented Apr 7, 2021

Just tried to read the retrieved Images (objects) which were returned by the methods added in this PR just as specified in https://docs.openmicroscopy.org/omero/5.6.3/developers/Python.html#read-data

But, again, when no images are found, the same error as in #285 (comment) happened. Maybe something is really wrong with the Image objects (generators) returned by the new methods here ?

@pwalczysko
Copy link
Member

Tested all three options in the header of this PR. All works, including the cases where no images are retrieved. Also tried to add the KVP on a Project, worked too. All good fmpov.

@joshmoore
Copy link
Member

In general, probably a good example of something that needs to be moved server-side (or into the eventual JSON API).

👍

@joshmoore joshmoore merged commit 0ec65ee into ome:master Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants