Will Moore
Sébastien Besson
Jean-Marie Burel
Simon Li
Andreas Knab
# 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();
# 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
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)
# 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()
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()
# 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
Improve display of Script Menu, UI and Results in Clients
# ...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
# 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>
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
# 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']
});