#!/usr/bin/env python # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- # Copyright (C) 2019 University of Dundee. All rights reserved. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # ------------------------------------------------------------------------------ """ This a basic OMERO script that runs server-side. """ import omero.scripts as scripts from omero.rtypes import rlong from omero.gateway import BlitzGateway from omero.rtypes import robject, rstring def run(conn, params): """ Load the Images. Returns list of images @param conn The BlitzGateway connection @param params The script parameters """ images = [] if params.get("Data_Type") == 'Dataset': for dsId in params["IDs"]: dataset = conn.getObject("Dataset", dsId) if dataset: for image in dataset.listChildren(): images.append(image) if len(images) == 0: return None for image in images: print("---- Processing image", image.id) return images if __name__ == "__main__": dataTypes = [rstring('Dataset')] client = scripts.client( 'Hello World.py', """ This script does connect to OMERO. """, scripts.String( "Data_Type", optional=False, grouping="1", description="Choose source of images", values=dataTypes, default="Dataset"), scripts.List( "IDs", optional=False, grouping="2", description="Dataset IDs.").ofType(rlong(0)), authors=["OME Team", "OME Team"], institutions=["University of Dundee"], contact="ome-users@lists.openmicroscopy.org.uk", ) try: # process the list of args above. scriptParams = {} for key in client.getInputKeys(): if client.getInput(key): scriptParams[key] = client.getInput(key, unwrap=True) print(scriptParams) # wrap client to use the Blitz Gateway conn = BlitzGateway(client_obj=client) # # Call the main script - returns the number of images processed images = run(conn, scriptParams) if images is None: message = "No images found" else: message = "Returned %s images" % len(images) # return first image: client.setOutput("Image", robject(images[0]._obj)) client.setOutput("Message", rstring(message)) finally: client.closeSession()