Repository 'idr_download_by_ids'
hg clone https://toolshed.g2.bx.psu.edu/repos/iuc/idr_download_by_ids

Changeset 3:381f248febba (2020-04-22)
Previous changeset 2:17b1cd0f4812 (2020-04-14) Next changeset 4:11036f6197d6 (2020-05-15)
Commit message:
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
modified:
idr_download_by_ids.py
idr_download_by_ids.xml
added:
test-data/test_output.log
b
diff -r 17b1cd0f4812 -r 381f248febba idr_download_by_ids.py
--- a/idr_download_by_ids.py Tue Apr 14 10:27:25 2020 -0400
+++ b/idr_download_by_ids.py Wed Apr 22 11:43:18 2020 -0400
[
b'@@ -7,10 +7,22 @@\n from omero.constants.namespaces import NSBULKANNOTATIONS  # noqa\n \n \n-def warn(message, image_identifier):\n+def warn(message, image_identifier, warn_skip=False):\n+    message = message.rstrip()\n+    if warn_skip:\n+        if message[-1] in [\'.\', \'!\', \'?\']:\n+            skip_msg = \' Skipping download!\'\n+        else:\n+            skip_msg = \'. Skipping download!\'\n+    else:\n+        skip_msg = \'\'\n     print(\n-        \'ImageSpecWarning for {0}: {1}\'\n-        .format(image_identifier, message),\n+        \'ImageSpecWarning for {0}: {1}{2}\'\n+        .format(\n+            image_identifier,\n+            message,\n+            skip_msg\n+        ),\n         file=sys.stderr\n     )\n \n@@ -93,6 +105,7 @@\n     if fname[-5:] != \'.tiff\':\n         fname += \'.tiff\'\n     try:\n+        fname = fname.replace(\' \', \'_\')\n         tiff = TIFF.open(fname, mode=\'w\')\n         tiff.write_image(selection)\n     finally:\n@@ -105,6 +118,19 @@\n     coord=(0, 0), width=0, height=0, region_spec=\'rectangle\',\n     skip_failed=False\n ):\n+    # basic argument sanity checks and adjustments\n+    prefix = \'image-\'\n+    # normalize image ids by stripping off prefix if it exists\n+    image_ids = [\n+        iid[len(prefix):] if iid[:len(prefix)] == prefix else iid\n+        for iid in image_ids\n+    ]\n+\n+    if region_spec not in [\'rectangle\', \'center\']:\n+        raise ValueError(\n+            \'Got unknown value "{0}" as region_spec argument\'\n+            .format(region_spec)\n+        )\n \n     # connect to idr\n     conn = BlitzGateway(\'public\', \'public\',\n@@ -113,20 +139,30 @@\n     conn.connect()\n \n     try:\n-        prefix = \'image-\'\n         for image_id in image_ids:\n-            if image_id[:len(prefix)] == prefix:\n-                image_id = image_id[len(prefix):]\n-            image_id = int(image_id)\n-            image = conn.getObject("Image", image_id)\n+            image_warning_id = \'Image-ID: {0}\'.format(image_id)\n+            try:\n+                image_id = int(image_id)\n+            except ValueError:\n+                image = None\n+            else:\n+                try:\n+                    image = conn.getObject("Image", image_id)\n+                except Exception as e:\n+                    # respect skip_failed on unexpected errors\n+                    if skip_failed:\n+                        warn(str(e), image_warning_id, warn_skip=True)\n+                        continue\n+                    else:\n+                        raise\n \n             if image is None:\n-                image_warning_id = \'Image-ID: {0}\'.format(image_id)\n                 if skip_failed:\n                     warn(\n                         \'Unable to find an image with this ID in the \'\n-                        \'database. Skipping download!\',\n-                        image_warning_id\n+                        \'database.\',\n+                        image_warning_id,\n+                        warn_skip=True\n                     )\n                     continue\n                 raise ValueError(\n@@ -135,23 +171,39 @@\n                     .format(image_warning_id)\n                 )\n \n-            image_name = os.path.splitext(image.getName())[0]\n-            image_warning_id = \'{0} (ID: {1})\'.format(\n-                image_name, image_id\n-            )\n+            try:\n+                # try to extract image properties\n+                # if anything goes wrong here skip the image\n+                # or abort.\n+                image_name = os.path.splitext(image.getName())[0]\n+                image_warning_id = \'{0} (ID: {1})\'.format(\n+                    image_name, image_id\n+                )\n+\n+                if region_spec == \'rectangle\':\n+                    tile = get_clipping_region(image, *coord, width, height)\n+                elif region_spec == \'center\':\n+                    tile = get_clipping_region(\n+                        image,\n+                        *_center_to_ul(*coord, width, height)\n+                    )\n \n-            if region_spec == \'rectangle\':\n-'..b'_spec argument\'\n-                    .format(region_spec)\n-                )\n+                ori_z, z_stack = z_stack, confine_plane(image, z_stack)\n+                ori_frame, frame = frame, confine_frame(image, frame)\n+                num_channels = image.getSizeC()\n+                if channel is None:\n+                    channel_index = 0\n+                else:\n+                    channel_index = find_channel_index(image, channel)\n+            except Exception as e:\n+                # respect skip_failed on unexpected errors\n+                if skip_failed:\n+                    warn(str(e), image_warning_id, warn_skip=True)\n+                    continue\n+                else:\n+                    raise\n+\n+            # region sanity checks and warnings\n             if tile[2] < width or tile[3] < height:\n                 # The downloaded image region will have smaller dimensions\n                 # than the specified width x height.\n@@ -162,7 +214,7 @@\n                     image_warning_id\n                 )\n \n-            ori_z, z_stack = z_stack, confine_plane(image, z_stack)\n+            # z-stack sanity checks and warnings\n             if z_stack != ori_z:\n                 warn(\n                     \'Specified image plane ({0}) is out of bounds. Using {1} \'\n@@ -171,7 +223,7 @@\n                     image_warning_id\n                 )\n \n-            ori_frame, frame = frame, confine_frame(image, frame)\n+            # frame sanity checks and warnings\n             if frame != ori_frame:\n                 warn(\n                     \'Specified image frame ({0}) is out of bounds. Using \'\n@@ -179,10 +231,9 @@\n                     .format(ori_frame, frame),\n                     image_warning_id\n                 )\n-            # Get the channel index. If the index is not valid, skip the image\n+\n+            # channel index sanity checks and warnings\n             if channel is None:\n-                channel_index = 0\n-                num_channels = image.getSizeC()\n                 if num_channels > 1:\n                     warn(\n                         \'No specific channel selected for multi-channel \'\n@@ -191,18 +242,35 @@\n                         image_warning_id\n                     )\n             else:\n-                channel_index = find_channel_index(image, channel)\n-                if channel_index == -1 or channel_index >= image.getSizeC():\n-                    raise ValueError(\n-                        \'"{0}" is not a known channel name for image {1}\'\n-                        .format(channel, image.getName())\n-                    )\n+                if channel_index == -1 or channel_index >= num_channels:\n+                    if skip_failed:\n+                        warn(\n+                            str(channel)\n+                            + \' is not a known channel name for this image.\',\n+                            image_warning_id,\n+                            warn_skip=True\n+                        )\n+                        continue\n+                    else:\n+                        raise ValueError(\n+                            \'"{0}" is not a known channel name for image {1}. \'\n+                            \'Aborting!\'\n+                            .format(channel, image_warning_id)\n+                        )\n \n             # download and save the region as TIFF\n             fname = \'__\'.join(\n                 [image_name, str(image_id)] + [str(x) for x in tile]\n             )\n-            download_plane_as_tiff(image, tile, z_stack, channel_index, frame, fname)\n+            try:\n+                download_plane_as_tiff(image, tile, z_stack, channel_index, frame, fname)\n+            except Exception as e:\n+                if skip_failed:\n+                    # respect skip_failed on unexpected errors\n+                    warn(str(e), image_warning_id, warn_skip=True)\n+                    continue\n+                else:\n+                    raise\n     finally:\n         # Close the connection\n         conn.close()\n'
b
diff -r 17b1cd0f4812 -r 381f248febba idr_download_by_ids.xml
--- a/idr_download_by_ids.xml Tue Apr 14 10:27:25 2020 -0400
+++ b/idr_download_by_ids.xml Wed Apr 22 11:43:18 2020 -0400
b
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<tool id="idr_download_by_ids" name="IDR Download" version="0.20" profile="18.09">
+<tool id="idr_download_by_ids" name="IDR Download" version="0.30" profile="18.09">
     <description>- download images from the Image Data Resource using image IDs</description>
     <macros>
         <xml name="region_spec" token_pos="upper-left corner">
@@ -218,10 +218,13 @@
 
 A set of image IDs as can be obtained from the IDR webclient_ like this:
 
-1. select the images you want to download
-2. click on the 'Link' button on the top right of the page and copy the provided
-   URL
-3. paste the URL into the input field of this tool, for example: ::
+1. Select the wells you want to download in the thumbnails.
+
+2. Select at the bottom the images in those wells that you want to download (one well might contain several images).
+
+3. Click on the 'Link' button on the top right of the page and copy the provided URL.
+
+4. Paste the URL into the input field of this tool, for example:
 
     https://idr.openmicroscopy.org/webclient/?show=image-9036708|image-9036710|image-9036711
 
b
diff -r 17b1cd0f4812 -r 381f248febba test-data/test_output.log
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test_output.log Wed Apr 22 11:43:18 2020 -0400
b
@@ -0,0 +1,1 @@
+ImageSpecWarning for Image-ID: 9036708999: Some random error