Note
This documentation is for OMERO 5.2. This version is now in maintenance mode and will only be updated in the event of critical bugs or security concerns. OMERO 5.3 is expected in the first quarter of 2017.
These guidelines for writing OMERO scripts are designed to improve the interaction of the scripts with OMERO clients so that they can:
If you want instructions on how to get started with OMERO scripts, see the link above or the OMERO.scripts user guide.
Most of the points below are implemented in the example Edit_Descriptions.py.
Parameter Names should be in the form ‘Parameter_Name’. Underscores will be replaced by spaces in the UI generated in OMERO.insight.
Where applicable, Parameters should be supplied with a list of options. For example:
scripts.String("Algorithm", values=[rstring('Maximum_Intensity'),rstring('Mean_Intensity')] )
Where possible, parameters should be supplied with default values. These will be used to populate fields in the OMERO.insight script UI and will be used by default when launching the script from the command line.
scripts.String("Folder_Name", description="Name of folder to store images", default='Batch_Image_Export'),
Where applicable, Parameters should have min and max values, E.g:
scripts.Int("Size_Z", description="Number of Z planes in new image", min=1),
Parameters are not ordered by default. They can be ordered and grouped by adding a “grouping” attribute, which is a string, where ‘groups’ are separated by a ‘.’ E.g. “01.A”. Parameters will be ordered by the lexographic sorting of this string and groups indicated in the UI. In most cases this will simply be a common indentation of parameters in the same group. In addition, if the ‘parent’ parameter of a group is a boolean, then un-checking the check-box in the UI will disable the child parameters. For example a UI generated from the code below will have a ‘Show Scalebar’ option. If this is un-checked, then the Size and Colour parameters will be disabled and will not be passed to the script.
scripts.Bool("Show_Scalebar", grouping="10", default=True),
scripts.Int("Scalebar_Size", grouping="10.1"),
scripts.String("Scalebar_Colour", grouping="10.2"),
Both OMERO.insight and OMERO.web recognize and populate a pair of fields named ‘Data_Type’ (string) and ‘IDs’ (Long list) with the objects currently selected in the client UI when the script is launched. You should specify the ‘Data_Type’ options that your script should accept. E.g.
dataTypes = [rstring('Dataset'),rstring('Image')]
client = scripts.client('Thumbnail_Figure.py', "Export a figure of thumbnails",
scripts.String("Data_Type", optional=False, grouping="01", values=dataTypes, default="Dataset"),
scripts.List("IDs", optional=False, grouping="02").ofType(rlong(0))
)
Scripts may return a short message to report success or failure. This should use the key: ‘Message’ in the output map. This will be displayed in OMERO.insight when the script completes.
client.setOutput("Message", rstring("Script generated new Image"))
Scripts that generate an Image should return the ImageI object. OMERO.insight will provide a link to view the Image. The key that is used (“Image” in this example) is not important for this to work, but ‘image’ should be an omero.model.ImageI object.
client.setOutput("Image",robject(image))
Scripts that generate a File Annotation or Original File should return these objects. OMERO.insight will give users the option of downloading the File, and may also allow viewing of the file if it is of a suitable type. This should be set as the mimetype of the File Annotation (E.g. ‘plain/text’, ‘image/jpeg’ etc). In this example, fileAnnotation should be an omero.model.FileAnnotationI object, but could also be an omero.model.OriginalFileI object.
client.setOutput("File_Annotation",robject(fileAnnotation))
Use the ‘unwrap()’ function from omero.rtypes to unwrap rtypes from the script parameters since this function will iteratively unwrap lists, maps etc.
from omero.rtypes import *
scriptParams = {}
for key in client.getInputKeys():
if client.getInput(key):
scriptParams[key] = unwrap(client.getInput(key))
print scriptParams # stdout will be returned - useful for bug fixing etc.