OMERO.figure scripting

Description:

We can use JavaScript in the browser console to script changes to a figure. This is an experimental feature and not documented. In this example, we will automatically add labels based on analysis results.

Setup:

Resources:

Step-by-Step:

Figure creation in Python

OMERO.figure files are simply JSON data, stored in OMERO File Annotations with a specific namespace of omero.web.figure.json. We can create these files using Python scripts, uploaded to the OMERO.scripting service to make them available to all OMERO users.

The format of the JSON is described at https://github.com/ome/omero-figure/blob/master/docs/figure_file_format.rst. We will use the example Split_View_Figure.py script.

  1. Select a few images in the webclient.
  2. Click on the Script button script_icon in the top-right of the webclient and choose the Split_View_Figure.py script (e.g. under Workshop Scripts).
  3. Run the script. When complete, open the OMERO.figure app and File > Open.
  4. Choose the most recent figure, called “Split View Figure”.

Figure editing in JavaScript

We will use the time-lapse images listed above to create a FRAP figure but you can use any time-lapse images.

_images/script_frap_figure.png
  1. To see the data model for any current file in OMERO.figure, go to File > Export as JSON….

  2. You will see that the panels list defines the panels and each panel has attributes. For example, a panel with a single white label might include the following attributes:

    "name": "image1.tiff",
    "labels":[{"text":"label text","size":12,"position":"topleft","color":"FFFFFF"}],
    "x": 200, "y", 200, "width": 100, "height": 100,
    ...many other attributes not shown...
    
  3. The figureModel variable is accessible in the console. We can use figureModel.getSelected() to get selected panels and for each panel we can call p.set() to change an attribute.

  4. For example, to set the height of each selected panel to 200, we can do:

    figureModel.getSelected().forEach(function(p){
        p.set('height', 200)
    });
    
  5. We can use AJAX to load JSON data and we will use p.add_labels() to create labels.

  6. In this example we will load the FRAP intensities from the Map Annotations on these images.

  7. Select 2 FRAP images that have previously been analysed to create a Map Annotation with the namespace demo.simple_frap_data.

    _images/script_map_ann_analysis.png
  8. Alternatively, you can add your own Map Annotation with each Key being a T-index (start at 0), and the Value will be a FRAP intensity (number).

    _images/script_map_ann_manual.png
  9. Create a Figure with 2 images.

  10. Copy and paste each image several times and increment T-index in the Preview panel to show multiple time-points per image.

  11. Open the browser console by right-click > Inspect Element (Firefox) or right-click > Inspect (Chrome) and click on the Console tab.

  12. Copy the code from https://raw.githubusercontent.com/ome/training-scripts/v0.6.0/practical/javascript/figure_frap_mapannotation_label.js

  13. Drag to select the FRAP movie images in the figure.

  14. Paste the code into the console. Do not hit enter yet.

  15. Inspect the code. It will iterate through each of the selected panels, an AJAX call is made to load the Map Annotations with the namespace that we created from FRAP values above.

  16. NB: If you manually created your own Map Annotation above, you can remove the line url += '&ns=' + ns; to avoid filtering by namespace.

  17. The FRAP values are a list of [key, value] pairs and we can get the value for the current T index of the panel with values[theT][1] and use this to create a label.

  18. Hit Enter to run the code on selected panels.

  19. The labels should be added. Note that you can undo and redo these changes in the UI as normal.

  20. Try out other examples in https://github.com/ome/training-scripts/tree/v0.6.0/practical/javascript