OMERO: Analysis Workshop

Matlab, Java, Python, Scripting & Web

Paris 2013

Will Moore
S├ębastien Besson
Jean-Marie Burel
Simon Li
Andreas Knab



OMERO model objects

Graph of OMERO model objects
OMERO Model Documentation

Distributed Computing: ICE

# python

import omero

client = omero.client("localhost")
# create Service Factory
session = client.createSession("will", "ome")
# get a Stateless Service
queryService = session.getQueryService()
# get a local omero.model.DatasetI
dataset = queryService.get("Dataset", 1)
print dataset				# see what's loaded
print dataset.getName().getValue()	# rtypes
print dataset.copyImageLinks()		# omero.UnloadedEntityException!

client.closeSession() 			# Free server resourses
Developing OMERO Clients | Working With OMERO

// Java    NB: Exception handling omitted

import omero.api.IQueryPrx;
import omero.api.ServiceFactoryPrx;
import omero.model.Dataset;

omero.client client = new omero.client("localhost");
// create Service Factory
ServiceFactoryPrx session = client.createSession("will", "ome");
// get a Stateless Service
IQueryPrx queryService = session.getQueryService();
// get a local omero.model.DatasetI
Dataset dataset = (Dataset) queryService.get("Dataset", 1);
// omero.UnloadedEntityException!



Where's My Data?


Combining Services

# FRAP Analysis (pseudo code)
session = client.createSession()

# Get Dataset and Images via DatasetId
session.getContainerService().getImages(did) 	# Stateless service

# Get ROIs
session.getRoiService().findByImage(iid) 	# Stateless service

# Get Timestamps for Planes
session.getQueryService().findByQuery("select...") # Stateless service

# Get Pixel Data
store = session.createRawPixelsStore() 		# Stateful service
store.getPlane(z, c, t)
store.getPlane(z, c, t)

client.closeSession() 			# Free server resourses

OMERO extension points

  • Standalone Client
  • OMERO.script
    • Python scripts run on Server
    • Can call other code via wrappers or command line:
      E.g. Matlab, C++, Fortran, ImageJ
    • Available to run from all clients
  • OMERO.web
    • Python-based Web framework
    • OMERO in your browser / iPad etc
    • Public Data

OMERO Python "Blitz Gateway" API...

from omero.gateway import BlitzGateway
# Connect to OMERO
conn = BlitzGateway("will", "ome", host="localhost")

# Load a Dataset
dataset = conn.getObject("Dataset", 123)	# DatasetWrapper
print dataset.getName()

# Object Wrappers have their own 'conn' - can load data on the fly
for image in dataset.listChildren():
    print image				# ImageWrapper id=152
    print image.getPrimaryPixels().getPlane() 	# numpy 2D array
Blitz Gateway: Getting Started | Code (best doc)

...Blitz Gateway

# To access the wrapped object
print dataset._obj 	# object #0 (::omero::model::Dataset) ...

# Wrappers don't (yet) exist for ALL omero.model objects, E.g:
roiService = conn.getRoiService()
result = roiService.findByImage(imageId, None)
for roi in result.rois:
    print roi.getId().getValue()	# omero.rtypes need getValue()

# When you're done, close the session to free up server resources


Use Python API for...

  • OMERO scripts Next Slide ->
    • Upload and run scripts on server
    • Called from OMERO.insight or OMERO.web clients
  • OMERO.web framework Fast Forward ->
    • OMERO.web client
    • Extend with your own Web pages

OMERO Scripts

Launch Scripts from OMERO.web client

Client UI from Script

Batch Image Export Script UI

Starter Script

import omero.scripts as scripts
from omero.rtypes import rstring, rlong
from omero.gateway import BlitzGateway

dataTypes = [rstring('Dataset'),rstring('Image')]

client = scripts.client('',
    "Flip or Rotate an Image and create a new Image in OMERO",

    scripts.String("Data_Type", optional=False, grouping="1",
    description="The data you want to work with.", values=dataTypes, default="Image"),

    scripts.List("IDs", optional=False, grouping="2",
    description="List of Dataset IDs or Image IDs").ofType(rlong(0)),


    conn = BlitzGateway(client_obj=client)

    imageIds = client.getInput("IDs", unwrap=True)
    images = list( conn.getObjects("Image", imageIds) )

    for i in images:
        print i.getName()

    client.setOutput("Message", rstring("Processed %s images" % len(images)))



Command-Line Workflow

# Upload script  NB: --official
$ omero script upload Desktop/ --official
# [will need to login... not shown]
Uploaded official script as original file #30

# Run the script...
$ omero script launch 30
# You'll be asked for any Parameters needed...
Enter value for "IDs": 152
Job 113 ready
Callback received: FINISHED

	*** start stdout (id=166)***
	* U20S-RCC1.10_R3D_FRAP.dv
	*** end stdout ***

	*** out parameters ***
	* Message=Processed 1 images
	***  done ***
Scripting Service Workflow

Style Guidelines

Improve display of Script Menu, UI and Results in Clients

Script results shown in Web client
Scripting Style Guide

Example Scripts

OMERO.web Framework

OMERO.web Framework OMERO.web documentation

Development Setup

OMERO.web Framework
  • Connect to local OR remote OMERO.server
  • Code under components/tools/OmeroWeb/omeroweb/
OMERO.web setup

Run Django development web server

# ...after various setup steps (see link below)

$ cd ../components/tools/OmeroWeb/omeroweb
$ python runserver
Validating models...
0 errors found

Django version 1.1.1, using settings 'omeroweb.settings'
Development server is running at
Quit the server with CONTROL-C.
OMERO.web setup

Show Dataset Thumbnails

url( r'^dataset/(?P<datasetId>[0-9]+)/$', views.dataset ),

@login_required() 		# gets 'conn' from request
def dataset(request, datasetId, conn=None, **kwargs):
    ds = conn.getObject("Dataset", datasetId)
    # generate html from template
    return render_to_response('webtest/dataset.html', {'dataset': ds})


<!-- dataset.html -->
<h1>{{ dataset.getName }}</h1>

{% for i in dataset.listChildren %}
    <img src="{% url webgateway.views.render_thumbnail %}" />
    {{ i.getName }}
{% endfor %}


WebGateway Rendering and


Webtest Examples

Webtest is shipped and enabled in OMERO.web

# OmeroWeb/webtest/

# 'Hello World' example from tutorial on
url( r'^dataset/(?P<datasetId>[0-9]+)/$', views.dataset, name="webtest_dataset" ),

# Show a panel of ROI thumbnails for an image
url( r'^image_rois/(?P<imageId>[0-9]+)/', views.image_rois, name='webtest_image_rois' ),

Use Firebug (or similar)

OMERO.web Firebug

Extending OMERO.web

  1. Create a new Django App
  2. Build your pages
  3. [Optional] Integrate with OMERO webclient
    • Use html templates for webclient look and feel
    • Inject content into the webclient UI

Webtest ROIs added to Right Panel

ROIs tab added to right panel


# omeroweb/

"omero.web.ui.right_plugins": ["RIGHT_PLUGINS",
  '[["Acquisition", "webclient/data/includes/right_plugin.acquisition.js.html", "metadata_tab"],'\
  #'["ROIs", "webtest/webclient_plugins/right_plugin.rois.js.html", "image_roi_tab"],'\
  '["Preview", "webclient/data/includes/right_plugin.preview.js.html", "preview_tab"]]', json.loads],

// webtest/webclient_plugins/right_plugin.rois.js.html

    plugin_index:{{ forloop.counter }},
    load_tab_content: function(selected, obj_dtype, obj_id) {    // Url based on selected object(s)
        var url = '{% url webtest_index %}image_rois/'+obj_id +'/';
    supported_obj_types: ['image']

Center panel extension

ROIs tab added to right panel