# # To be run in OMERO CLI shell as follows: # # # Download script to current working directory # omero shell --login # ... # %run -i rename-image.py image_id name # import sys from omero.gateway import omero_type try: image_id, name = sys.argv[1:] except ValueError: print "Usage: %s <image_id> <name>" sys.exit(1) image_id = long(image_id) session = client.getSession() iquery = session.getQueryService() iupdate = session.getUpdateService() image = iquery.find('Image', image_id) image.setName(omero_type(name)) iupdate.saveObject(image) print 'Successfully set name of Image:%d to %r' % (image_id, name)
from omero.gateway import omero_type try: plate_id, name = sys.argv[1:] except ValueError: print "Usage: %s <plate_id> <name>" sys.exit(1) plate_id = long(plate_id) session = client.getSession() iquery = session.getQueryService() iupdate = session.getUpdateService() params = omero.sys.Parameters() params.map = {"pid": omero_type(plate_id)} query = """select image from Image image join image.wellSamples as samples join samples.well as well join well.plate as plate where plate.id=:pid""" images = iquery.findAllByQuery(query, params) for image in images: image.setName(omero_type(name)) iupdate.saveObject(image) print 'Successfully set name of %d images in Plate:%d to %r' % ( len(images), plate_id, name)
# # # Download script to current working directory # omero shell --login # ... # %run -i edit_plate.py plate_id attribute value # import sys from omero.gateway import omero_type try: plate_id, attribute, value = sys.argv[1:] except ValueError: print "Usage: %s <plate_id> <attribute> <value>" sys.exit(1) plate_id = long(plate_id) session = client.getSession() iquery = session.getQueryService() iupdate = session.getUpdateService() plate = iquery.find('Plate', plate_id) if not hasattr(plate, attribute): print 'Plate has no attribute %r' % (attribute) sys.exit(1) setattr(plate, attribute, omero_type(value)) iupdate.saveObject(plate) print 'Successfully set attribute %r of Plate:%d to %r' % \ (attribute, plate_id, value)