Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Examples for how to query OMERO for Images based on pixel type of Map Annotations
import omero
from omero.gateway import BlitzGateway
conn = BlitzGateway('username', 'password', port=4064, host='')
# current group
group_id = conn.getEventContext().groupId
print('group_id', group_id)
# Use -1 for cross-group query
# Find Images by Pixel Type
params = omero.sys.ParametersI()
params.addString('value', 'uint8')
# pagination
offset = 0
limit = 100, limit)
query = """
select img from Image img
join fetch img.pixels as pixels
where pixels.pixelsType.value = :value
images = conn.getQueryService().findAllByQuery(query, params, conn.SERVICE_OPTS)
for img in images:
# Find Images by Key-Value pairs (map annotations)
params = omero.sys.ParametersI()
params.addString('key', 'Primary Antibody')
params.addString('value', 'ACA')
offset = 0
limit = 100, limit)
# Here we use 'projection' query to load specific values rather than whole objects
# This can be more performant, but here I'm using it based on Map-Annotation
# query examples in omero-mapr
query = """
select, from
ImageAnnotationLink ial
join ial.child a
join a.mapValue mv
join ial.parent image
where = :key and mv.value = :value"""
result = conn.getQueryService().projection(query, params, conn.SERVICE_OPTS)
for row in result:
print("Img ID: %s Name: %s" % (row[0].val, row[1].val))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment