Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Contact with OMERO server and retrieve data.
from __future__ import print_function # OMERO currently seems to only support Python 2.7
from omero.gateway import BlitzGateway
import getpass
def print_obj(obj, indent=0):
'''
Helper method to display info about OMERO objects.
Not all objects will have a "name" or owner field.
'''
print("{}{}:{} Name:{} (owner={})".format(
" " * indent,
obj.OMERO_CLASS,
obj.getId(),
obj.getName(),
obj.getOwnerOmeName(),
)
)
return
if __name__ == '__main__':
'''
Reference:
* OMERO: https://www.openmicroscopy.org/omero/
* OMERO Python API: https://docs.openmicroscopy.org/omero/5.4.0/developers/Python.html
* OMERO Model Objects: https://docs.openmicroscopy.org/omero/5.4.10/developers/Model/EveryObject.html
'''
omero_password = getpass.getpass(prompt='omero password:')
conn = BlitzGateway(
username='johndoe',
passwd=omero_password,
host='omero.hms.harvard.edu',
port=4064)
conn.connect()
my_exp_id = conn.getUser().getId()
default_group_id = conn.getEventContext().groupId
obj_list = conn.getObjects(
obj_type='Dataset',
opts={
'owner':my_exp_id,
'group':default_group_id,
'order_by':'lower(obj.name)',
'limit':5,
'offset':0,
}
)
for dataset in obj_list:
print_obj(dataset, 0)
for image in dataset.listChildren():
print_obj(image, 2)
conn.close()
print('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.