R Gateway

This section shows how to install and use the R Gateway to analyze data. Jupyter notebooks are available to demonstrate some of the functionalities available.

https://mybinder.org/badge_logo.svg

Contents

Installing rOMERO-gateway

rOMERO-gateway will use rJava to communicate with an OMERO server.

Install in a Conda environment

In this section, we show how to install rOMERO-gateway and additional packages for image analysis (see environment.yml and postBuild) in a Conda environment.

  • Install Miniconda if necessary.

  • If you do not have a local copy of the omero-guide-r repository, first clone the repository:

    $ git clone https://github.com/ome/omero-guide-r.git
    
  • Go into the directory:

    $ cd omero-guide-r
    
  • Create a programming environment using Conda:

    $ conda create -n rgateway
    
  • Install dependencies and some packages used in the notebooks using an installation file:

    $ conda env update -n rgateway --file binder/environment.yml
    
  • Run a bash script to install rOMERO-gateway and the Java dependencies:

    $ bash binder/postBuild
    
  • Activate the environment:

    $ conda activate rgateway
    

Install in RStudio

See Installing and using romero.gateway package in RStudio

Installing and using romero.gateway package in RStudio
Linux

This example uses Debian 10. On other distributions the commands and packages might be called slightly differently.

As root user install the system dependencies: apt install r-base openjdk-11-jdk libssl-dev libcurl4-openssl-dev

Then you need to find out where exactly the JDK was installed: ls -l /etc/alternatives/ | grep java

Lookout for ‘openjdk’ to find the location.

Configure Java for R (still using root user):

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 # Whatever your path to openjdk is
R CMD javareconf

As normal user install and start up RStudio. In RStudio install the dependencies from CRAN needed for the romero.gateway package:

_images/rstudio_romero_deps.png

Alternative: Run the following in the console: install.packages(c("jpeg", "curl", "httr", "rJava"))

Download the latest romero.gateway release tar.gz from Github. Install it in RStudio:

_images/rstudio_romero.png

Alternative: Run the following in the console: install.packages("~/Downloads/romero.gateway_0.4.8.tar.gz", repos = NULL, type = "source")

Windows

This example uses Windows 10, other Windows version should be similar.

Install a JDK, for example AdoptOpenJDK. Make sure to tick the checkbox to set the JAVA_HOME and PATH environment variables!

Install the dependencies httr, jpeg and rJava from CRAN:

_images/windows_romero_deps.png

Download the latest romero.gateway release zip from Github and install it:

_images/windows_romero.png

Analyse data using R (statistical package)

R is a free software environment for statistical computing and graphics. See https://www.r-project.org/ for more information.

Description

Here we demonstrate how to connect to OMERO using R, load images and other objects from OMERO and perform image analysis followed up by statistical analysis in R. We use R as part of a Jupyter notebook. In the notebook we are going to use the idr0021 data. These are super resolution microscopy images showing certain proteins around the centrioles. With these images the authors of the article Subdiffraction imaging of centrosomes reveals higher-order organizational features of pericentriolar material showed that the area around the centrioles has a specific structure. By measuring the shape and diameter of these proteins and comparing them to each other they could show that each protein builds a specific part of this structure, see Figure 1. Instead of manually measuring each centriole ring like the authors did, we are going to try to do this in an automated way in order to show that there is a significant difference between these proteins and create a plot similar to the one seen on Figure 1.

We will show:

  • How to connect to OMERO using R.

  • How to load images from OMERO to R.

  • How to perform segmentation of objects in an image in R.

  • How to calculate properties of the segmented objects (e.g. diameter) in R.

  • How to save the properties of the objects as an R dataframe.

  • How to create and save ellipse representations of the ROI for each segmented object onto the original image in OMERO.

  • How to save the properties of the objects as attachments in OMERO.

  • How to load images in a whole Dataset or Project from OMERO and perform the steps above on all images.

  • How to perform statistical analysis on the generated data in R and save results back to OMERO.

Setup

In order to be able to connect to OMERO from within R we need the rOMERO-gateway and rJava packages.

Note: Everything we are going to do there can be done in Rstudio as well, if the rOMERO-gateway package and its dependencies are available on your system.

See Installing rOMERO-gateway.

Resources

We will use data from the Image Data Resource (IDR).

For convenience, the IDR data have been imported into the training OMERO.server. This is only because we cannot save results back to IDR which is a read-only OMERO.server.

Step-by-step

All the steps are described in detail inside the Jupyter notebook. In you are running locally or in mybinder, go to:

  • In the notebooks folder, select the notebook idr0021_Segmentation.ipynb.

Note: We are going to show the image segmentation and feature calculation on a small subset of the idr0021 data. The full analysis of the idr0021 project has already been done and the result saved as ‘Summary from R’ table. We are going to load this table in order to do the statistical analysis at the end of the notebook.

Here, we give a digest of the steps inside the notebook: The notebook steps will:

  1. Fetch the images from OMERO using rOMERO-gateway.

  2. Perform image segmentation to identify the protein rings around the centrioles using EBImage in R.

  3. Calculate the properties (features) of the identified objects (shape, diameter, etc.) using EBImage.

  4. Store these features in R as an R dataframe.

  5. The segmentation and feature calculation is a rather costly process. You don’t want to do this all over again. Therefore we save the identified objects (ROIs, region of interests) and the properties back to OMERO using rOMERO-gateway.

  6. Perform statistical analysis on that data in R.

  7. At the end of the notebook a plot is created which is similar to the one shown in Figure 1 of the article. One dataset in particular has extreme outliers. OMERO.parade https://github.com/ome/omero-parade can be used to find the images that cause the outliers.

  8. Note: OMERO.parade uses the Summary from R table that is attached to the project in order to provide enhanced filtering and plotting features.

Contribute

Changes to the documentation or the materials should be made directly in the omero-guide-r repository.