OMERO: Analysis Workshop

Matlab, Java, Python, Scripting & Web

Paris 2013

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

OMERO API

OMERO API

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);
System.err.println(dataset.getId().getValue());
System.err.println(dataset.getName().getValue());
// omero.UnloadedEntityException!
System.err.println(dataset.copyImageLinks());

client.closeSession();

						

Where's My Data?

OMERO Services OMERO API

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.setId(pid)
store.getPlane(z, c, t)
store.getPlane(z, c, t)
store.close()

client.closeSession() 			# Free server resourses
					
Simple_FRAP.py

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")
conn.connect()

# 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
conn._closeSession()

					

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
OMERO.scripts

Client UI from Script

Batch Image Export Script UI
Batch_Image_Export.py

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('Transform_Image.py',
    "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)),
)

try:

    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)))

finally:
    client.closeSession()

					

Command-Line Workflow


# Upload script  NB: --official
$ omero script upload Desktop/Transform.py --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
Waiting....
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 manage.py runserver
Validating models...
0 errors found

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

Show Dataset Thumbnails


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

# views.py
@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 -->
<html><body>
<h1>{{ dataset.getName }}</h1>

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

</body></html>
					

WebGateway Rendering and
Viewports


WebGateway

Webtest Examples

Webtest is shipped and enabled in OMERO.web


# OmeroWeb/webtest/urls.py

# 'Hello World' example from tutorial on http://trac.openmicroscopy.org.uk/ome/wiki/OmeroWeb
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' ),
					
webtest

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

Webclient "RIGHT_PLUGINS"
configuration


# omeroweb/settings.py

"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

$("#image_roi_tab").omeroweb_right_plugin({
    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 +'/';
        $(this).load(url);
    },
    supported_obj_types: ['image']
});
    				

Center panel extension

ROIs tab added to right panel