37. OMERO.downloader

37.1. Preparation

Downloader

To minimize typing make a helpful alias like:

$ cd omero-downloader/
$ mvn
...
$ export SOURCE_DIR="`pwd`" TARGET_DIR="/tmp/repo" OME_DIR="/ome"
$ rm -fr "$TARGET_DIR"
$ mkdir "$TARGET_DIR"
$ alias download="\"$SOURCE_DIR\"/download.sh -b \"$TARGET_DIR\" -s eel.openmicroscopy.org -u user-3 -w ome"
$ cd

SOURCE_DIR is where your sources for OMERO.downloader are and TARGET_DIR is to where it should download files. The following test steps assume that something like that shell alias has been set. OME_DIR is where you have squig mounted locally. Adjust the options in the alias definition according to how you log in to your OMERO server.

Bio-Formats

This scenario assumes that the Bio-Formats command-line tools are available locally.

XML formatter

It helps for some optional steps to have a reasonable OME-XML formatter or editor. Here I shall assume that xmllint is available: it is easily installed as part of libxml2. Feel free to substitute for any other such tool.

OMERO.cli

For using the omero executable you may find it convenient to add its bin directory to your search PATH. Alternatively, from your OMERO directory you could set another alias:

alias omero="`pwd`/bin/omero"

This scenario assumes that typing omero without any prefix suffices for your shell to locate the OMERO.cli Python executable.

Working directory

With the environment variables and aliases set as above you can follow this scenario from any convenient working directory. This flexibility may be helpful as you investigate the outcome of any particular step of the scenario.

37.2. File downloads

  1. Get the ID of an image that has a companion file:

    omero login
    DV_IMAGE=$(omero import "$OME_DIR"/data_repo/test_images_good/dv/IAGFP-Noc01_R3D.dv)
    
  2. Download the image’s binary file:

    download -f binary $DV_IMAGE
    
  3. Check that three files are listed: for fileset, image and repository:

    find "$TARGET_DIR" -name IAGFP-Noc01_R3D.dv -print
    
  4. Check with ls -l that the image file is a symlink to the fileset file.

  5. Check with ls -l that the fileset file is a symlink to the repository file.

  6. Check that showinf -autoscale on any of those files shows the image.

  7. Download the image’s log file:

    download -f companion $DV_IMAGE
    find "$TARGET_DIR" -name IAGFP-Noc01_R3D.dv\* -print
    
  8. Check that for the fileset and image directories, the binary file is in a Binary directory and the log file in a Companion directory.

  9. Check that within the repository directory both files are in the same directory.

  10. Check that showinf on the repository’s log file shows the image:

    showinf -autoscale `find "$TARGET_DIR"/Repository -name IAGFP-Noc01_R3D.dv.log -print`
    
  11. Download both the binary and companion files for the image:

    download -f binary,companion $DV_IMAGE
    
  12. Check that two files are listed, both as “already downloaded”

  13. Get the ID of an image whose file is large:

    omero login
    SCN_IMAGE=$(omero import "$OME_DIR"/data_repo/test_images_good/leica-scn/mihaela/UCLAD_0000000280_2011-02-10\ 13_32_55Z.scn)
    

    That import may take a few minutes so perhaps take a short break.

  14. Start to download the file:

    download -f binary $SCN_IMAGE
    
  15. Once the “commencing download of file” message is shown and its line of dots is growing then quit the downloader mid-download with control+C or similar.

  16. Retry the download, Check that the message is now “resuming download”. Allow it to complete.

  17. Retry the download, Check that the message is now “already downloaded”. (If you used the above Leica file then you should have already seen this as its second image uses the same file.)

  18. Find the file in the local repository:

    SCN_FILE=`find "$TARGET_DIR/"Repository -name UCLAD_0000000280_2011-02-10\ 13_32_55Z.scn -print`
    
  19. Find the checksum of the file then delete it:

    cksum "$SCN_FILE"
    rm "$SCN_FILE"
    
  20. Download the file again without interrupting it.

  21. Check that the file’s checksum matches the previous.

37.3. File exports

  1. Import a big image, e.g.:

    omero login
    JPEG_IMAGE=$(omero import "$OME_DIR"/data_repo/test_images_good/jpeg/4kx4k.jpg)
    
  2. In a graphical client wait for the image’s thumbnail to become available.

  3. Annotate the image a little: add a tag, a comment, a ROI, etc. Note the IDs of what you add.

  4. Annotate one of the ROIs, e.g.:

    omero obj new RoiAnnotationLink parent=Roi:1234 child=TagAnnotation:567
    

    to add tag ID 567 to ROI ID 1234.

  5. Start to export the image:

    download -f tiff $JPEG_IMAGE
    
  6. Once the “commencing download of pixels” message is shown and its line of dots is growing then quit the downloader mid-download with control+C or similar.

  7. Restart the download, Check that the message is now “resuming download”. Allow it to complete.

  8. Change to the export directory for that image then see what it has:

    cd "$TARGET_DIR"/`echo $JPEG_IMAGE | tr : /`/Export/
    ls
    
  9. Check that tiffcomment does not have much to report about the export:

    tiffcomment 4kx4k.jpg.tiff
    
  10. Check that 4kx4k.jpg.tiff is viewable with its smooth intensity gradient:

    showinf 4kx4k.jpg.tiff
    
  11. Now export the OME-TIFF version of the image:

    download -f ome-tiff $JPEG_IMAGE
    
  12. Check that tiffcomment has rather more to say about that export:

    tiffcomment 4kx4k.jpg.ome.tiff
    
  13. Check that 4kx4k.jpg.ome.tiff has the same pixel data as 4kx4k.jpg.tiff:

    showinf 4kx4k.jpg.ome.tiff
    
  14. Check that 4kx4k.jpg.ome.tiff has valid OME-XML:

    xmlvalid 4kx4k.jpg.ome.tiff
    
  15. Check the XML output from tiffcomment above:

    tiffcomment 4kx4k.jpg.ome.tiff | xmllint -format -
    
    1. Check that at the top level is an OME element.

    2. Check that the Pixels element contains TiffData elements.

    3. Check that the image has annotation and ROI reference elements.

    4. Check that the ROI has an annotation reference element.

    5. Check that the referenced elements are present.

  16. Import a multi-Z,C,T image, e.g.:

    omero login
    LSM_IMAGE=$(omero import "$OME_DIR"/data_repo/test_images_good/zeiss-lsm/2chZT.lsm)
    
  17. Export both the TIFF and OME-TIFF versions of the image:

    download -f tiff,ome-tiff $LSM_IMAGE
    
  18. Import both the exported images:

    omero import "$TARGET_DIR"/`echo $LSM_IMAGE | tr : /`/Export/*.tiff
    
  19. Check that 2chZT.lsm, 2chZT.lsm.tiff, 2chZT.lsm.ome.tiff look the same in OMERO:

    1. Check that the three images’ thumbnails look identical.

    2. Check by scrolling in Z and T that their plane order matches.

  20. Check the channel names and exposure times from 2chZT.lsm using the ‘Acquisition’ tab:

    1. Check that they match those from 2chZT.lsm.ome.tiff though other metadata may be missing.

    2. Check that they are missing from 2chZT.lsm.tiff which should include little metadata overall.

37.4. Fetching metadata

Here we reuse the JPEG_IMAGE for testing exports. If you are not also testing exports then just run the first few import and annotation steps of File exports until the first download. If you prefer then you can use 2kx2k.jpg instead of the larger.

  1. Download XML fragments for your image’s model objects:

    download -f ome-xml-parts $JPEG_IMAGE
    
  2. Change to the metadata directory for that image then see what it has:

    cd "$TARGET_DIR"/`echo $JPEG_IMAGE | tr : /`/Metadata/
    ls
    
  3. Check that the export directory has no XML files in it yet:

    ls ../Export/
    
  4. Check the XML fragment for the image:

    xmllint -format `echo $JPEG_IMAGE | tr I: i-`.ome.xml
    
    1. Check that at the top level is an Image element.

    2. Check that the Pixels element contains a MetadataOnly element.

    3. Check that the image has no annotation or ROI reference elements.

  5. Check the related XML fragments:

    ls ../*/*/Metadata/*
    
  6. Check that these annotations and ROIs are the ones you expected. xmllint -format ... can be used to inspect each.

    1. Check that their top-level element is ROI or some kind of annotation.

    2. Check that their XML contains no reference elements.

    3. Check the same for the annotation that you put on the ROI:

      ls ../Roi/*/Annotation/*/Metadata/*
      
  7. Assemble the XML fragments into one whole:

    download -f ome-xml-whole $JPEG_IMAGE
    
  8. Check that nothing mentioned writing anything as XML.

  9. Check that the export directory now has an XML file in it:

    ls ../Export/
    
  10. Check the contents of the XML file:

    xmllint -format ../Export/`echo $JPEG_IMAGE | tr I: i-`.ome.xml
    
    1. Check that at the top level is an OME element.

    2. Check that the Pixels element contains a MetadataOnly element.

    3. Check that the image has annotation and ROI reference elements.

    4. Check that the ROI has an annotation reference element.

    5. Check that the referenced elements are present.

  11. Delete all the downloaded XML:

    find "$TARGET_DIR" -name \*.xml -print -exec rm {} +
    

    You may wish to first omit everything after the -print to check what would be deleted.

  12. Run the combined parts-and-whole metadata export:

    download -f ome-xml $JPEG_IMAGE
    

    For the -f option ome-xml is simply shorthand for ome-xml-parts,ome-xml-whole, options you used above.

  13. Check that the XML fragments are again just as before after running the ome-xml-parts download.

  14. Check that the assembled OME-XML document is again just as before after running the ome-xml-whole download.

  15. Optionally, try deleting some subset of XML files and repeating the export to ensure that the download messages are as you would expect, e.g.:

    writing annotations as XML, need up to 3, already have 2... done
    

37.5. Whole fileset

  1. Remove any existing export directories:

    rm -fr "$TARGET_DIR"/Image/*/Export
    
  2. Import a plate:

    omero login
    INCELL_PLATE=$(omero import "$OME_DIR"/data_repo/test_images_good/incell/Single\ plane\ no\ flatfield\ corr/)
    
  3. Download its binary files:

    download -f binary $INCELL_PLATE
    
  4. Check that file download failures are reported. A server with default configuration does not allow download of plate files.

  5. Export one of the images listed for, “determining files used by image”:

    download -f ome-tiff,ome-xml Image:1234
    
  6. Check that the OME-TIFF and OME-XML files were exported:

    cd "$TARGET_DIR"/Image/*/Export/
    ls
    
  7. Check that the OME-TIFF and OME-XML files look reasonable:

    showinf -autoscale 2007.10.17.17.04.55.xdce*.ome.tiff
    xmllint -format image-*.ome.xml
    
  8. Check that downloads can be expanded to whole filesets, using the same image ID as above:

    download -f ome-xml -a Image:1234
    
  9. Check that you see many “assembling metadata for image” messages.

  10. Check that you see an “already assembled metadata for image” message for the image that you chose above.

  11. Check that referencing the plate directly works the same as -a:

    download -f ome-xml $INCELL_PLATE
    
  12. Check that you see many “already assembled metadata for image” messages.

37.7. Limit metadata

Here we reuse the JPEG_IMAGE for testing exports. If you are not also testing exports then just run the first few import and annotation steps of File exports until the first download. If you prefer then you can use 2kx2k.jpg instead of the larger.

  1. Delete all the downloaded XML:

    find "$TARGET_DIR" -name \*.xml -print -exec rm {} +
    

    You may wish to first omit everything after the -print to check what would be deleted.

  2. Run the normal XML fragment download:

    download -f ome-xml-parts $JPEG_IMAGE
    
  3. Check that images, ROIs and annotations were downloaded:

    find "$TARGET_DIR" -name \*.xml -print
    
  4. Assemble the XML document for that image, both with and without pixel data:

    download -f ome-tiff,ome-xml $JPEG_IMAGE
    
  5. Change to the export directory for that image:

    cd "$TARGET_DIR"/`echo $JPEG_IMAGE | tr : /`/Export/
    
  6. Check that the XML includes images, ROIs and annotations:

    tiffcomment 4kx4k.jpg.ome.tiff | xmllint -format -
    xmllint -format `echo $JPEG_IMAGE | tr I: i-`.ome.xml
    
  7. Delete the exported files:

    rm -f *.ome.tiff *.ome.xml
    

    This step is important because any change in the -x option will not overwrite previous exports.

  8. Repeat the above steps using fewer kinds of model object for the -x option in the download:

    • -x image,roi

    • -x image,annotation

    • -x image

    1. Check that ROIs and annotations are omitted from the XML accordingly.

    2. Check that omission from assembled XML is regardless of if extra XML fragments were downloaded in a previous ome-xml-parts step.

  9. Repeat the above step using even fewer kinds of model object for the -x option in the download:

    • -x roi,annotation

    • -x roi

    Note that the exported file for xmllint will be found among:

    ls "$TARGET_DIR"/`echo $JPEG_IMAGE | tr : /`/Roi/*/Export/roi-*.ome.xml
    
  10. Do one more repetition for -x annotation.

    Note that the exported files for xmllint will be found among:

    ls "$TARGET_DIR"/`echo $JPEG_IMAGE | tr : /`/Annotation/*/Export/annotation-*.ome.xml
    ls "$TARGET_DIR"/`echo $JPEG_IMAGE | tr : /`/Roi/*/Annotation/*/Export/annotation-*.ome.xml
    

    according to how you annotated the image and ROI.

37.8. Session login

The above suggested “download” shell alias uses the -u, -w options to supply a username and password. A session key should suffice:

  1. Obtain an OMERO session key:

    omero login
    KEY=`omero sessions key`
    
  2. Import a simple image:

    DICOM_IMAGE=$(omero import "$OME_DIR"/data_repo/test_images_good/dicom/ankle.dcm)
    
  3. Download the image file using the session key:

    "$SOURCE_DIR"/download.sh -b "$TARGET_DIR" -s eel.openmicroscopy.org -k $KEY -f binary $DICOM_IMAGE
    

    As when you set the “download” shell alias adjust the server name for your OMERO server.

  4. Check that the downloaded file looks as expected:

    showinf "$TARGET_DIR"/`echo $DICOM_IMAGE | tr : /`/Binary/ankle.dcm
    

37.9. Other groups

The above tests pay no mind to which images are in which groups: probably everything was done as the current user in their default group. OMERO.downloader should be able fetch from outside the current group. For example, try adding a -g <group-name> option to the login in some of the above workflows. One could even adjust the -u and -w options in the “download” shell alias, and adjust the options given to omero login, to have an administrator try to download data that a normal user has in a private group. Try a couple of different types of download with the various -f options from the workflows to Check that any kind of data can be fetched from any group that the download user can read.