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

Changeset 13:f92941d1a85e (2024-09-26)
Previous changeset 12:4b794652dcdc (2023-11-08)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit a9a143bae95eb6c553fd3d5955c2adb34352480f
modified:
idr_download_by_ids.py
idr_download_by_ids.xml
b
diff -r 4b794652dcdc -r f92941d1a85e idr_download_by_ids.py
--- a/idr_download_by_ids.py Wed Nov 08 12:57:25 2023 +0000
+++ b/idr_download_by_ids.py Thu Sep 26 12:32:17 2024 +0000
[
b'@@ -4,35 +4,50 @@\n import sys\n import tarfile\n from contextlib import ExitStack\n+from itertools import product\n from tempfile import TemporaryDirectory\n \n-from libtiff import TIFF\n+import numpy\n from omero.cli import cli_login\n-from omero.gateway import BlitzGateway  # noqa\n-from omero.constants.namespaces import NSBULKANNOTATIONS  # noqa\n+from omero.constants.namespaces import NSBULKANNOTATIONS\n+from omero.gateway import _ImageWrapper, BlitzGateway\n+from tifffile import imwrite\n \n \n-def warn(message, image_identifier, warn_skip=False):\n+def warn(message: str, image_identifier: str, warn_skip: bool = False) -> None:\n+    """Print an error `message` to stderr and\n+    - prefix with the `image_identifier`\n+    - suffix with \'Skipping download!\' if `warn_skip` is True\n+\n+    Args:\n+        message (string): Message to print to stderr\n+        image_identifier (string): Image identifier\n+        warn_skip (bool, optional): Whether \'skipping download\' should be suffix to the message. Defaults to False.\n+    """\n     message = message.rstrip()\n     if warn_skip:\n-        if message[-1] in [\'.\', \'!\', \'?\']:\n-            skip_msg = \' Skipping download!\'\n+        if message[-1] in [".", "!", "?"]:\n+            skip_msg = " Skipping download!"\n         else:\n-            skip_msg = \'. Skipping download!\'\n+            skip_msg = ". Skipping download!"\n     else:\n-        skip_msg = \'\'\n+        skip_msg = ""\n     print(\n-        \'ImageSpecWarning for {0}: {1}{2}\'\n-        .format(\n-            image_identifier,\n-            message,\n-            skip_msg\n-        ),\n-        file=sys.stderr\n+        "ImageSpecWarning for {0}: {1}{2}".format(image_identifier, message, skip_msg),\n+        file=sys.stderr,\n     )\n \n \n-def find_channel_index(image, channel_name):\n+def find_channel_index(image: _ImageWrapper, channel_name: str) -> int:\n+    """Identify the channel index from the `image` and the `channel_name`\n+\n+    Args:\n+        image (_ImageWrapper): image wrapper on which the channel should be identified\n+        channel_name (string): name of the channel to look for\n+\n+    Returns:\n+        int: Index of the channel or -1 if was not found.\n+    """\n     channel_name = channel_name.lower()\n     for n, channel in enumerate(image.getChannelLabels()):\n         if channel_name == channel.lower():\n@@ -44,13 +59,31 @@\n             if p[0] == "Channels":\n                 channels = p[1].replace(" ", "").split(";")\n                 for n, c in enumerate(channels):\n-                    for value in c.split(\':\'):\n+                    for value in c.split(":"):\n                         if channel_name == value.lower():\n                             return n\n     return -1\n \n \n-def get_clipping_region(image, x, y, w, h):\n+def get_clipping_region(\n+    image: _ImageWrapper, x: int, y: int, w: int, h: int\n+) -> list[int]:\n+    """Check `x`, `y` and adjust `w`, `h` to image size to be able to crop the `image` with these coordinates\n+\n+    Args:\n+        image (_ImageWrapper): image wrapper on which region want to be cropped\n+        x (int): left x coordinate\n+        y (int): top y coordinate\n+        w (int): width\n+        h (int): height\n+\n+    Raises:\n+        ValueError: if the x or y coordinates are negative.\n+        ValueError: if the x or y coordinates are larger than the width or height of the image.\n+\n+    Returns:\n+        list[int]: new [x, y, width, height] adjusted to the image\n+    """\n     # If the (x, y) coordinate falls outside the image boundaries, we\n     # cannot just shift it because that would render the meaning of\n     # w and h undefined (should width and height be decreased or the whole\n@@ -58,16 +91,16 @@\n     # It may be better to abort in this situation.\n     if x < 0 or y < 0:\n         raise ValueError(\n-            \'Too small upper left coordinate ({0}, {1}) for clipping region.\'\n-            .format(x, y)\n+            "Too small upper left coordinate ({0}, {1}) for clipping region.".format(\n+                x, y\n+        '..b'a width x height rectangle. \'\n-             \'Set either width or height to 0 to extend the region to the \'\n-             \'actual size of the image along the x- or y-axis.\\n\'\n-             \'Note: Even values for width and height will be rounded down to \'\n-             \'the nearest odd number.\'\n+        "--center",\n+        nargs=4,\n+        type=int,\n+        default=argparse.SUPPRESS,\n+        help="specify a clipping region for the image as x y width height, "\n+        "where x and y define the center of a width x height rectangle. "\n+        "Set either width or height to 0 to extend the region to the "\n+        "actual size of the image along the x- or y-axis.\\n"\n+        "Note: Even values for width and height will be rounded down to "\n+        "the nearest odd number.",\n     )\n-    p.add_argument(\n-        \'-f\', \'--frame\', type=int, default=0\n+    region.add_argument(\n+        "--download-original",\n+        dest="download_original",\n+        action="store_true",\n+        help="download the original file uploaded to omero",\n+    )\n+    region.add_argument(\n+        "--download-full",\n+        dest="download_full",\n+        action="store_true",\n+        help="download the full image on omero",\n     )\n     p.add_argument(\n-        \'-z\', \'--z-stack\', type=int, default=0\n-    )\n-    p.add_argument(\n-        \'--skip-failed\', action=\'store_true\'\n-    )\n-    p.add_argument(\n-        \'--download-tar\', action=\'store_true\'\n+        "-c",\n+        "--channel",\n+        help="name of the channel to retrieve data for "\n+        "(note: the first channel of each image will be downloaded if "\n+        "left unspecified), ignored with `--download-original` and "\n+        "`--download-full`",\n     )\n     p.add_argument(\n-        \'-oh\', \'--omero-host\', type=str, default="idr.openmicroscopy.org"\n-    )\n-    p.add_argument(\n-        \'--omero-secured\', action=\'store_true\', default=True\n+        "-f",\n+        "--frame",\n+        type=int,\n+        default=0,\n+        help="index of the frame to retrive data for (first frame is 0),"\n+        " ignored with `--download-original` and `--download-full`",\n     )\n     p.add_argument(\n-        \'-cf\', \'--config-file\', dest=\'config_file\', default=None\n+        "-z",\n+        "--z-stack",\n+        type=int,\n+        default=0,\n+        help="index of the slice to retrive data for (first slice is 0),"\n+        " ignored with `--download-original` and `--download-full`",\n     )\n-    p.add_argument(\n-        \'--dataset\', action=\'store_true\'\n-    )\n+    p.add_argument("--skip-failed", action="store_true")\n+    p.add_argument("--download-tar", action="store_true")\n+    p.add_argument("-oh", "--omero-host", type=str, default="idr.openmicroscopy.org")\n+    p.add_argument("--omero-secured", action="store_true", default=True)\n+    p.add_argument("-cf", "--config-file", dest="config_file", default=None)\n+    p.add_argument("--dataset", action="store_true")\n     args = p.parse_args()\n     if not args.image_ids_or_dataset_id:\n         args.image_ids_or_dataset_id = sys.stdin.read().split()\n     if args.dataset and len(args.image_ids_or_dataset_id) > 1:\n         warn("Multiple dataset ids provided. Only the first one will be used.")\n-    if \'center\' in args:\n+    if "center" in args:\n         args.coord, args.width, args.height = (\n-            args.center[:2], args.center[2], args.center[3]\n+            args.center[:2],\n+            args.center[2],\n+            args.center[3],\n         )\n-        args.region_spec = \'center\'\n+        args.region_spec = "center"\n         del args.center\n-    elif \'rectangle\' in args:\n+    elif "rectangle" in args:\n         args.coord, args.width, args.height = (\n-            args.rectangle[:2], args.rectangle[2], args.rectangle[3]\n+            args.rectangle[:2],\n+            args.rectangle[2],\n+            args.rectangle[3],\n         )\n-        args.region_spec = \'rectangle\'\n+        args.region_spec = "rectangle"\n         del args.rectangle\n     download_image_data(**vars(args))\n'
b
diff -r 4b794652dcdc -r f92941d1a85e idr_download_by_ids.xml
--- a/idr_download_by_ids.xml Wed Nov 08 12:57:25 2023 +0000
+++ b/idr_download_by_ids.xml Thu Sep 26 12:32:17 2024 +0000
[
b'@@ -1,5 +1,5 @@\n <?xml version="1.0"?>\n-<tool id="idr_download_by_ids" name="Download IDR/OMERO" version="0.44.1" profile="18.09">\n+<tool id="idr_download_by_ids" name="Download IDR/OMERO" version="0.45" profile="18.09">\n     <description></description>\n     <macros>\n         <xml name="region_spec" token_pos="upper-left corner">\n@@ -19,8 +19,8 @@\n         <edam_operation>operation_3443</edam_operation>\n     </edam_operations>\n     <requirements>\n-        <requirement type="package" version="5.10.1">omero-py</requirement>\n-        <requirement type="package" version="0.4.2">pylibtiff</requirement>\n+        <requirement type="package" version="5.19.4">omero-py</requirement>\n+        <requirement type="package" version="2024.9.20">tifffile</requirement>\n     </requirements>\n     <command detect_errors="exit_code"><![CDATA[\n         \n@@ -51,6 +51,8 @@\n         #end if\n         #if $image_region.original == "original":\n             --download-original\n+        #elif $image_region.original == "full":\n+            --download-full\n         #else:\n             #set $channel = str($image_region.channel).strip()\n             #if $channel:\n@@ -87,7 +89,7 @@\n }\n         ]]></configfile>\n     </configfiles>\n-<inputs>\n+    <inputs>\n         <conditional name="omero_instance_type">\n             <param name="omero_instance" type="select" label="Which OMERO instance to connect?"\n                    help="By default, the tool will download a tarball containing individual images from IDR into your Galaxy history. If you \n@@ -135,9 +137,11 @@\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="full">Whole TIFF (all channels, all frames, all stacks)</option>\n                 <option value="original">Original file (file uploaded to omero, only available for private instances)</option>\n             </param>\n             <when value="original"/>\n+            <when value="full"/>\n             <when value="TIFF">\n                 <param name="channel" type="text"\n                     label="Name of the channel to download"\n@@ -182,7 +186,7 @@\n         </data> \n     </outputs>\n     <tests>\n-        <test>\n+        <test expect_num_outputs="2">\n             <conditional name="omero_instance_type">\n                  <param name="omero_instance" value="idr" />\n             </conditional>\n@@ -202,10 +206,10 @@\n             </conditional>\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" ftype="tiff" file="test0.tiff"/>\n+                <element name="Centrin_PCNT_Cep215_20110506_Fri-1545_0_SIR_PRJ__1884807__3__3__5__5" ftype="tiff" file="test0.tiff" compare="image_diff" />\n             </output_collection>\n         </test>\n-        <test>\n+        <test expect_num_outputs="2">\n             <conditional name="omero_instance_type">\n                  <param name="omero_instance" value="idr" />\n             </conditional>\n@@ -225,10 +229,10 @@\n             </conditional>\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" ftype="tiff" file="test1.tiff"/>\n+                <element name="Centrin_PCNT_Cep215_20110506_Fri-1545_0_SIR_PRJ__1884807__3__3__5__5" ftype="tiff" file="test1.tiff" compare="image_diff"/>\n             </output_collection>\n         </test>\n-        <test>\n+        <test expect_num_outputs="2">\n             <conditional name="omero_instance_type">\n                  <param name="omero_instance" value="idr" />\n             </conditional>\n@@ -248,10 +252,10 @@\n             </conditiona'..b'ro_instance_type">\n                  <param name="omero_instance" value="idr" />\n             </conditional>\n@@ -426,27 +446,43 @@\n             <output_collection name="output_file" type="list" count="4">\n                 <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D__9036711__0__0__1024__1024">\n                     <assert_contents>\n-                        <has_size value="2097286" />\n+                        <has_size size="2097286" />\n+                        <has_image_width width="1024" />\n+                        <has_image_height height="1024" />\n+                        <has_image_mean_intensity mean_intensity="145.310" />\n+                        <has_image_center_of_mass center_of_mass="527.499, 480.704" />\n                     </assert_contents>\n                 </element>\n                 <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D_D3D__9036708__0__0__1024__1024">\n                     <assert_contents>\n-                        <has_size value="2097286" />\n+                        <has_size size="2097286" />\n+                        <has_image_width width="1024" />\n+                        <has_image_height height="1024" />\n+                        <has_image_mean_intensity mean_intensity="147.025" />\n+                        <has_image_center_of_mass center_of_mass="528.977, 480.691" />\n                     </assert_contents>\n                 </element>\n                 <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D_D3D_zproj__9036710__0__0__1024__1024">\n                     <assert_contents>\n-                        <has_size value="2097286" />\n+                        <has_size size="2097286" />\n+                        <has_image_width width="1024" />\n+                        <has_image_height height="1024" />\n+                        <has_image_mean_intensity mean_intensity="210.787" />\n+                        <has_image_center_of_mass center_of_mass="534.629, 473.267" />\n                     </assert_contents>\n                 </element>\n                 <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D_REF__9036709__0__0__1024__1024">\n                     <assert_contents>\n-                        <has_size value="2097286" />\n+                        <has_size size="2097286" />\n+                        <has_image_width width="1024" />\n+                        <has_image_height height="1024" />\n+                        <has_image_mean_intensity mean_intensity="3816.051" />\n+                        <has_image_center_of_mass center_of_mass="512.274, 503.186" />\n                     </assert_contents>\n                 </element>\n             </output_collection>\n         </test>\n-        <test>\n+        <test expect_num_outputs="2">\n             <conditional name="omero_instance_type">\n                  <param name="omero_instance" value="idr" />\n             </conditional>\n@@ -462,6 +498,24 @@\n             <output_collection name="output_file" type="list" count="0">\n             </output_collection>\n         </test>\n+        <test expect_num_outputs="2">\n+            <conditional name="omero_instance_type">\n+                 <param name="omero_instance" value="idr" />\n+            </conditional>\n+            <param name="source" value="link" />\n+            <param name="id_spec" value="1229801" />\n+            <param name="download_tar" value="false" />\n+            <conditional name="image_region">\n+                <param name="original" value="full"/> \n+            </conditional>\n+            <output_collection name="output_file" type="list" count="1">\n+                <element name="JL_120731_S6A_[Well_A-1;_Field_#1]__1229801__full">\n+                    <assert_contents>\n+                        <has_size size="91592058" />\n+                    </assert_contents>\n+                </element>\n+            </output_collection>\n+        </test>\n     </tests>\n     <help><![CDATA[\n Download image data from the IDR_ (Image Data Resource) - a public repository\n'