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

Changeset 11:cbd605a24336 (2022-01-15)
Previous changeset 10:4aed70472589 (2021-11-24) Next changeset 12:4b794652dcdc (2023-11-08)
Commit message:
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit b68715960d1107593db13dd9e1dbd8d4b905cc6f"
modified:
idr_download_by_ids.py
idr_download_by_ids.xml
b
diff -r 4aed70472589 -r cbd605a24336 idr_download_by_ids.py
--- a/idr_download_by_ids.py Wed Nov 24 21:01:02 2021 +0000
+++ b/idr_download_by_ids.py Sat Jan 15 12:25:29 2022 +0000
[
b'@@ -7,6 +7,7 @@\n from tempfile import TemporaryDirectory\n \n from libtiff import TIFF\n+from omero.cli import cli_login\n from omero.gateway import BlitzGateway  # noqa\n from omero.constants.namespaces import NSBULKANNOTATIONS  # noqa\n \n@@ -111,6 +112,7 @@\n \n def download_image_data(\n     image_ids_or_dataset_id, dataset=False,\n+    download_original=False,\n     channel=None, z_stack=0, frame=0,\n     coord=(0, 0), width=0, height=0, region_spec=\'rectangle\',\n     skip_failed=False, download_tar=False, omero_host=\'idr.openmicroscopy.org\', omero_secured=False, config_file=None\n@@ -129,7 +131,7 @@\n                 omero_username = \'public\'\n                 omero_password = \'public\'\n \n-    if region_spec not in [\'rectangle\', \'center\']:\n+    if not download_original and region_spec not in [\'rectangle\', \'center\']:\n         raise ValueError(\n             \'Got unknown value "{0}" as region_spec argument\'\n             .format(region_spec)\n@@ -224,124 +226,159 @@\n                     \'database. Aborting!\'\n                     .format(image_warning_id)\n                 )\n+            if not download_original:\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-            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+                    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+                    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-                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+                # 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+                    warn(\n+                        \'Downloaded image dimensions ({0} x {1}) will be smaller \'\n+                        \'than the specified width and height ({2} x {3}).\'\n+                        .format(tile[2], tile[3], width, height),\n+                        image_warning_id\n+                    )\n+\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} \''..b'     # respect skip_failed on unexpected errors\n+                        warn(str(e), image_warning_id, warn_skip=True)\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-            try:\n-                if fname[-5:] != \'.tiff\':\n-                    fname += \'.tiff\'\n-\n-                fname = fname.replace(\' \', \'_\')\n-\n-                im_array = get_image_array(image, tile, z_stack, channel_index, frame)\n-\n-                if download_tar:\n-                    fname = os.path.join(tempdir, fname)\n+                        raise\n+            else:\n                 try:\n-                    tiff = TIFF.open(fname, mode=\'w\')\n-                    tiff.write_image(im_array)\n-                finally:\n-                    tiff.close()\n-                # move image into tarball\n-                if download_tar:\n-                    archive.add(fname, os.path.basename(fname))\n-                    os.remove(fname)\n-            except Exception as e:\n-                if skip_failed:\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+                    original_image_name = image.getFileset().listFiles()[0].getName()\n+                    fname = image_name + "__" + str(image_id) + os.path.splitext(original_image_name)[1]\n+                    fname = fname.replace(\' \', \'_\')\n+                    fname = fname.replace(\'/\', \'_\')\n+                    download_directory = "./"\n+                    if download_tar:\n+                        download_directory = tempdir\n+                    with cli_login("-u", omero_username, "-s", omero_host, "-w", omero_password) as cli:\n+                        cli.invoke(["download", f"Image:{image_id}", download_directory])\n+                        if cli.rv != 0:\n+                            raise Exception("Download failed.")\n+                    # This will download to download_directory/original_image_name\n+                    os.rename(os.path.join(download_directory, original_image_name),\n+                              os.path.join(download_directory, fname))\n+                    # move image into tarball\n+                    if download_tar:\n+                        archive.add(os.path.join(download_directory, fname),\n+                                    os.path.basename(fname))\n+                        os.remove(os.path.join(download_directory, fname))\n+                except Exception as e:\n                     # respect skip_failed on unexpected errors\n-                    warn(str(e), image_warning_id, warn_skip=True)\n-                    continue\n-                else:\n-                    raise\n+                    if skip_failed:\n+                        warn(str(e), image_warning_id, warn_skip=True)\n+                        continue\n+                    else:\n+                        raise\n \n \n def _center_to_ul(center_x, center_y, width, height):\n@@ -369,6 +406,10 @@\n              \'read ids from stdin).\'\n     )\n     p.add_argument(\n+        \'--download-original\', dest=\'download_original\', action=\'store_true\',\n+        help="download the original file uploaded to omero"\n+    )\n+    p.add_argument(\n         \'-c\', \'--channel\',\n         help=\'name of the channel to retrieve data for \'\n              \'(note: the first channel of each image will be downloaded if \'\n'
b
diff -r 4aed70472589 -r cbd605a24336 idr_download_by_ids.xml
--- a/idr_download_by_ids.xml Wed Nov 24 21:01:02 2021 +0000
+++ b/idr_download_by_ids.xml Sat Jan 15 12:25:29 2022 +0000
[
b'@@ -1,5 +1,5 @@\n <?xml version="1.0"?>\n-<tool id="idr_download_by_ids" name="IDR/OMERO Download" version="0.43" profile="18.09">\n+<tool id="idr_download_by_ids" name="IDR/OMERO Download" version="0.44" profile="18.09">\n     <description>- download images from any OMERO instance using image IDs</description>\n     <macros>\n         <xml name="region_spec" token_pos="upper-left corner">\n@@ -46,14 +46,18 @@\n         #if str($image_ids.source) == \'omeroDatasetID\':\n             --dataset\n         #end if\n-        #set $channel = str($channel).strip()\n-        #if $channel:\n-            -c \'$channel\'\n-        #end if\n-        -f $frame\n-        -z $z_section\n-        #if str($clip_image.select):\n-            ${clip_image.select} ${clip_image.x_coord} ${clip_image.y_coord} ${clip_image.width} ${clip_image.height}\n+        #if $image_region.original == "original":\n+            --download-original\n+        #else:\n+            #set $channel = str($image_region.channel).strip()\n+            #if $channel:\n+                -c \'$channel\'\n+            #end if\n+            -f $image_region.frame\n+            -z $image_region.z_section\n+            #if str($image_region.clip_image.select):\n+                ${image_region.clip_image.select} ${image_region.clip_image.x_coord} ${image_region.clip_image.y_coord} ${image_region.clip_image.width} ${image_region.clip_image.height}\n+            #end if\n         #end if\n         $skip_failed\n         $download_tar\n@@ -124,26 +128,36 @@\n                 <param name="id_dataset_omero" type="integer" min = "0" value = "9059" label="Dataset ID"/>\n             </when>\n         </conditional>\n-        <param name="channel" type="text"\n-        label="Name of the channel to download"\n-        help="For all image IDs only the specified channel will be downloaded. If left empty, the first channel (whatever this is) will be downloaded by default." />\n-        <param name="z_section" type="integer" value="0" min="0"\n-        label="z-plane of images to download" />\n-        <param name="frame" type="integer" value="0" min="0"\n-        label="Image frame to download" />\n-        <conditional name="clip_image">\n-            <param name="select" type="select"\n-            label="Limit the download to a selected region of the image?">\n-                <option value="">No, download the entire image plane</option>\n-                <option value="--rectangle">Specify a region using its upper-left corner</option>\n-                <option value="--center">Specify a width x height region around a central point</option>\n+\n+        <conditional name="image_region">\n+            <param name="original" type="select" label="Which images do you want to download?">\n+                <option value="TIFF" selected="true">Exported TIFF (single channel, single stack)</option>\n+                <option value="original">Original file (file uploaded to omero, only available for private instances)</option>\n             </param>\n-            <when value="" />\n-            <when value="--rectangle">\n-                <expand macro="region_spec" />\n-            </when>\n-            <when value="--center">\n-                <expand macro="region_spec" pos="center" />\n+            <when value="original"/>\n+            <when value="TIFF">\n+                <param name="channel" type="text"\n+                    label="Name of the channel to download"\n+                    help="For all image IDs only the specified channel will be downloaded. If left empty, the first channel (whatever this is) will be downloaded by default." />\n+                <param name="z_section" type="integer" value="0" min="0"\n+                    label="z-plane of images to download" />\n+                <param name="frame" type="integer" value="0" min="0"\n+                    label="Image frame to download" />\n+                <conditional name="clip_image">\n+                    <param name="select" type="select"\n+                        label="Limit the download to a selected'..b'\n             </conditional>\n-            <param name="frame" value="0" />\n             <output name="output_tar">\n                     <assert_contents>\n                         <has_size value="1382400" />\n@@ -335,15 +370,18 @@\n             </conditional>\n             <param name="source" value="dataset" />\n             <param name="id_spec" value="ids.txt" />\n-            <param name="channel" value="PCNT" />\n-            <conditional name="clip_image">\n-                <param name="select" value="--rectangle" />\n-                <param name="x_coord" value="3" />\n-                <param name="y_coord" value="3" />\n-                <param name="width" value="5" />\n-                <param name="height" value="5" />\n+            <conditional name="image_region">\n+                <param name="original" value="TIFF"/> \n+                <param name="channel" value="PCNT" />\n+                <conditional name="clip_image">\n+                    <param name="select" value="--rectangle" />\n+                    <param name="x_coord" value="3" />\n+                    <param name="y_coord" value="3" />\n+                    <param name="width" value="5" />\n+                    <param name="height" value="5" />\n+                </conditional>\n+                <param name="frame" value="0" />\n             </conditional>\n-            <param name="frame" value="0" />\n             <param name="download_tar" value="false" />\n             <output_collection name="output_file" type="list">\n                 <element name="Centrin_PCNT_Cep215_20110506_Fri-1545_0_SIR_PRJ__1884807__3__3__5__5" file="test0.tiff"/>\n@@ -357,15 +395,18 @@\n             </conditional>\n             <param name="source" value="dataset" />\n             <param name="id_spec" value="ids.txt" />\n-            <param name="channel" value="PCNT" />\n-            <conditional name="clip_image">\n-                <param name="select" value="--rectangle" />\n-                <param name="x_coord" value="3" />\n-                <param name="y_coord" value="3" />\n-                <param name="width" value="5" />\n-                <param name="height" value="5" />\n+            <conditional name="image_region">\n+                <param name="original" value="TIFF"/> \n+                <param name="channel" value="PCNT" />\n+                <conditional name="clip_image">\n+                    <param name="select" value="--rectangle" />\n+                    <param name="x_coord" value="3" />\n+                    <param name="y_coord" value="3" />\n+                    <param name="width" value="5" />\n+                    <param name="height" value="5" />\n+                </conditional>\n+                <param name="frame" value="0" />\n             </conditional>\n-            <param name="frame" value="0" />\n             <param name="download_tar" value="false" />\n             <assert_stderr>\n                 <has_text text="OMERO connection credentials are empty. Set your credentials via: User -> Preferences -> Manage Information" />\n@@ -402,6 +443,22 @@\n                 </element>\n             </output_collection>\n         </test>\n+        <test>\n+            <conditional name="omero_instance_type">\n+                 <param name="omero_instance" value="idr" />\n+            </conditional>\n+            <!-- Test for download all original files from a dataset -->\n+            <!-- Impossible in idr: -->\n+            <param name="source" value="omeroDatasetID" />\n+            <param name="id_dataset_omero" value="9059" />\n+            <param name="skip_failed" value="true" />\n+            <param name="download_tar" value="false" />\n+            <conditional name="image_region">\n+                <param name="original" value="original"/> \n+            </conditional>\n+            <output_collection name="output_file" type="list" count="0">\n+            </output_collection>\n+        </test>\n     </tests>\n     <help><![CDATA[\n Download image data from the IDR_ (Image Data Resource) - a public repository\n'