Import data using the Command Line Interface (CLI)

Description

This chapter will show how to import data for another user, using Command Line Interface (CLI).

The user importing the data needs to have some admin (or restricted-admin) privileges. More information about restricted privileges can be found at https://docs.openmicroscopy.org/latest/omero/sysadmins/restricted-admins.html

The import for another user will be done only as demo since the user is required to have specific privileges. We will use a user with login name importer1, who could be in real life e.g. a facility manager.

We will show:

  • How to import data using the CLI for myself and for others into a remote OMERO.server
  • How to import data using the CLI “in-place”, which means not copying the imported data into OMERO. Instead, OMERO will point to the original location of “in-place” imported files, thus preventing data duplication.
  • How to deal with imports of large amounts of data in CLI, using the –bulk option and helper csv and yml files which define what is to be imported and how.

Setup

CLI Importer installation

Client libraries from the OMERO.server have to be installed on the client to import images using CLI. The installation instructions can be found at https://docs.openmicroscopy.org/latest/omero/users/cli/installation.html.

Note: When importing for another user using the CLI, the importer1 does not have to be a member of the target group.

Step-by-step

  1. If you did not do so already, open a terminal window on your local machine and activate the conda environment where your omero-py is installed (see the Setup section above):

    $ conda activate myenv
    
  2. Set the OMERODIR variable to point to the downloaded and unzipped OMERO server dir (see the Setup section above):

    $ export OMERODIR=/path/to/OMERO.server-x.x.x-ice36-bxx
    
  3. Login to the OMERO.server you wish to import to. This can be a remote OMERO.server. In the below example we log in as the user importer1, who will import for themselves:

    $ omero -s your-server-address -u importer1 login
    
  4. Go to the directory where there are some images you wish to import:

    $ cd /path/to/images/directory/
    
  5. Create an OMERO Dataset to import to:

    $ DID=$(omero obj new Dataset name=import_for_myself)
    
  6. Import the images as importer1 into the newly created Dataset. You can import a single image as in the example below, or a whole directory of images:

    $ omero import -d $DID <your-image-name>
    
  7. Log in to OMERO.web as importer1 and verify the imported image in the newly created dataset import_for_myself.

  8. Import an image for another user, for example user-1. For that, your importer1 user logs in as user-1:

    $ omero --sudo importer1 -u user-1 login
    
  9. Create a Dataset import_for_user_one as user-1:

    $ DID=$(omero obj new Dataset name=import_for_user_one)
    
  10. Import the data in the newly created Dataset:

    $ omero import -d $DID <path-to-image-or-directory-with-images>
    
  11. Check that the image(s) are successfully imported and that the image(s) and the containing Dataset both belong to user-1 (not importer1).

In-place Import using the CLI

Instead of being copied into OMERO’s managed repository, the image files stay at their original place and are just linked into the repository.

It is only available for the CLI importer, using the argument --transfer=ln_s.

../../_images/importcli1.png

Advantages:

  • All in-place import scenarios provide non-copying benefit. Data that is too large to exist in multiple places, or which is accessed too frequently in its original form to be renamed, remains where it was originally acquired.

Limitations:

  • Only available on the OMERO server system itself.
  • Do not edit or move the files after an in-place import. OMERO may no longer be able to access them if you do.

Important:

A user performing an in-place import MUST have:

Step-by-step:

  1. Connect to the machine on which the OMERO.server is running as OS user importer1 using ssh.

  2. The aim is to import an image from /OMERO/in-place-import/FRAP:

    $ ls /OMERO/in-place-import/FRAP
    
  3. Activate the virtual environment where omero-py is installed or add it to PATH. In the example below, the path to the OMERO.server is /opt/omero/server:

    $ export PATH=/opt/omero/server/venv3/bin:$PATH
    
  4. Point OMERODIR to the location where the OMERO server is installed e.g.:

    $ export OMERODIR=/opt/omero/server/OMERO.server
    
  5. Import now data for another user, this time a large image where the advantage of not copying the image file onto the server is most visible. The importer1 user logs in as user-1:

    $ omero --sudo importer1 -u user-1 login
    
  6. Create a Dataset import_for_user_one:

    $ DID=$(omero obj new Dataset name=import_for_user_one)
    
  • ‘In place’ import a large SVS file into the import_for_user_one dataset:

    $ omero import -d $DID --transfer=ln_s /OMERO/in-place-import/svs/77917.svs
    
  • Check that the image is successfully imported.

  • Click on the paths icon image3 to show the difference between the normal and in-place (ln_s) imported images. Validate that In-place import is indicated image4.

  • Note: The script in_place_import_as.sh shows how to perform the in-place import steps described above in one single command.

Bulk Import using the CLI

In this example, we show how to combine several import strategies using a configuration file. This is a strategy heavily used to import data to https://idr.openmicroscopy.org/.

We import two folders named siRNA-HeLa and condensation.

Note: Connecting over SSH is necessary only if you intend to import in-place. If you do not wish to perform the bulk import in “in-place” manner, you can connect to the server remotely using locally installed OMERO.cli and adjust the bulk.yml file by commenting out the transfer... line, then follow the steps as described below.

  1. Open a terminal and connect to the server (for example as importer1) over SSH. Alternatively, use your local terminal with installed OMERO.cli if not importing “in-place”.

  2. Description of the files used to set up the import (see bulk.yml, import-paths.csv and import-bulk.html#bulk-imports for further details).

    • import-paths.csv: (.csv, comma-separated values) this file has at least two columns. In this case the columns are separated by commas. The first column is the name of the target Dataset and the second one is the path to the folder to import. We will import two folders (the import-paths.csv has two rows).

      Example csv (note the comma between the “HeLa” and “/OMERO…”):

      *Dataset:name:Experiment1-HeLa,/OMERO/in-place-import/siRNAi-HeLa*

      *Dataset:name:Experiment2-condensation,/OMERO/in-place-import/condensation*

    • bulk.yml: this file defines the various import options: transfer option, checksum algorithm, format of the .csv file, etc. Note that setting the dry_run option to true allows to first run an import in dry_run mode and copy the output to an external file. This is useful when running an import in parallel. Comment out the transfer" "ln_s" if not importing “in-place”.

      Example bulk.yml:

    *continue: "true"*
    
    *transfer: "ln_s"*
    
    *# exclude: "clientpath"*
    
    *checksum_algorithm: "File-Size-64"*
    
    *logprefix: "logs"*
    
    *output: "yaml"*
    
    *path: "import-paths.csv"*
    
    *columns:*
    
        -  *target*
    
        -  *path*
    
  3. Activate the virtual environment where omero-py is installed or add it to PATH. In the example below, the path to the OMERO.server is /opt/omero/server:

    $ export PATH=/opt/omero/server/venv3/bin:$PATH
    
  4. Point OMERODIR to the location where the OMERO server is installed e.g.:

    $ export OMERODIR=/opt/omero/server/OMERO.server
    
  5. Find the place where the bulk.yml file is located, for example /OMERO/in-place-import:

    $ cd /OMERO/in-place-import
    
  6. The importer1 (Facility Manager with ability to import for others) OMERO user logs in as user-1:

    $ omero --sudo importer1 -u user-1 login
    
  7. Import the data using the --bulk command:

    $ omero import --bulk bulk.yml
    
  8. Go to the webclient during the import process to show the newly created dataset. The new datasets in OMERO are named Experiment1-HeLa and Experiment2-condensation. This was specified in the first column of the import-paths.csv file.

  9. Select an image.

  10. In the right-hand panel, select the General tab to validate:

    • Click on image3 to show the import details.
    • Validate that In-place import is indicated image4 in case you imported “in-place”.

Advantages:

  • Large amount of data imported using one import command.
  • Heterogeneous data for multiple users can be imported using bulk import in combination with bash scripting, e.g. in_place_import_as.sh
  • Reproducible import.

Limitations:

  • Preparation of the .csv or .tsv file.

For more information about CLI import options, go to import.html.