changeset 10:4aed70472589 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
author iuc
date Wed, 24 Nov 2021 21:01:02 +0000
parents 80af973c5277
children cbd605a24336
files idr_download_by_ids.py idr_download_by_ids.xml
diffstat 2 files changed, 97 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/idr_download_by_ids.py	Fri Feb 26 20:12:11 2021 +0000
+++ b/idr_download_by_ids.py	Wed Nov 24 21:01:02 2021 +0000
@@ -110,7 +110,7 @@
 
 
 def download_image_data(
-    image_ids,
+    image_ids_or_dataset_id, dataset=False,
     channel=None, z_stack=0, frame=0,
     coord=(0, 0), width=0, height=0, region_spec='rectangle',
     skip_failed=False, download_tar=False, omero_host='idr.openmicroscopy.org', omero_secured=False, config_file=None
@@ -129,14 +129,6 @@
                 omero_username = 'public'
                 omero_password = 'public'
 
-    # basic argument sanity checks and adjustments
-    prefix = 'image-'
-    # normalize image ids by stripping off prefix if it exists
-    image_ids = [
-        iid[len(prefix):] if iid[:len(prefix)] == prefix else iid
-        for iid in image_ids
-    ]
-
     if region_spec not in ['rectangle', 'center']:
         raise ValueError(
             'Got unknown value "{0}" as region_spec argument'
@@ -160,6 +152,47 @@
                 TemporaryDirectory()
             )
 
+        if dataset:
+            dataset_warning_id = 'Dataset-ID: {0}'.format(image_ids_or_dataset_id[0])
+            try:
+                dataset_id = int(image_ids_or_dataset_id[0])
+            except ValueError:
+                image_ids = None
+            else:
+                try:
+                    dataset = conn.getObject("Dataset", dataset_id)
+                except Exception as e:
+                    # respect skip_failed on unexpected errors
+                    if skip_failed:
+                        warn(str(e), dataset_warning_id, warn_skip=True)
+                    else:
+                        raise
+                else:
+                    image_ids = [image.id for image in dataset.listChildren()]
+
+            if image_ids is None:
+                if skip_failed:
+                    warn(
+                        'Unable to find a dataset with this ID in the '
+                        'database.',
+                        dataset_warning_id,
+                        warn_skip=True
+                    )
+                else:
+                    raise ValueError(
+                        '{0}: Unable to find a dataset with this ID in the '
+                        'database. Aborting!'
+                        .format(dataset_warning_id)
+                    )
+
+        else:
+            # basic argument sanity checks and adjustments
+            prefix = 'image-'
+            # normalize image ids by stripping off prefix if it exists
+            image_ids = [
+                iid[len(prefix):] if iid[:len(prefix)] == prefix else iid
+                for iid in image_ids_or_dataset_id
+            ]
         for image_id in image_ids:
             image_warning_id = 'Image-ID: {0}'.format(image_id)
             try:
@@ -330,8 +363,9 @@
 if __name__ == "__main__":
     p = argparse.ArgumentParser()
     p.add_argument(
-        'image_ids', nargs='*', default=[],
-        help='one or more IDR image ids for which to retrieve data (default: '
+        'image_ids_or_dataset_id', nargs='*', default=[],
+        help='one or more IDR image ids or a single dataset id'
+             'for which to retrieve data (default: '
              'read ids from stdin).'
     )
     p.add_argument(
@@ -378,9 +412,14 @@
     p.add_argument(
         '-cf', '--config-file', dest='config_file', default=None
     )
+    p.add_argument(
+        '--dataset', action='store_true'
+    )
     args = p.parse_args()
-    if not args.image_ids:
-        args.image_ids = sys.stdin.read().split()
+    if not args.image_ids_or_dataset_id:
+        args.image_ids_or_dataset_id = sys.stdin.read().split()
+    if args.dataset and len(args.image_ids_or_dataset_id) > 1:
+        warn("Multiple dataset ids provided. Only the first one will be used.")
     if 'center' in args:
         args.coord, args.width, args.height = (
             args.center[:2], args.center[2], args.center[3]
--- a/idr_download_by_ids.xml	Fri Feb 26 20:12:11 2021 +0000
+++ b/idr_download_by_ids.xml	Wed Nov 24 21:01:02 2021 +0000
@@ -16,7 +16,7 @@
         </xml>
     </macros>
     <requirements>
-        <requirement type="package" version="5.7.1">python-omero</requirement>
+        <requirement type="package" version="5.10.1">omero-py</requirement>
         <requirement type="package" version="0.4.2">pylibtiff</requirement>
     </requirements>
     <command detect_errors="exit_code"><![CDATA[
@@ -37,10 +37,15 @@
         #if str($image_ids.source) == 'link':
             python -c 'print("${image_ids.id_spec}".replace(",", "|").split("?show=")[-1].replace("|", "\n"))'
             ## https://idr.openmicroscopy.org/webclient/?show=image-3426274|image-3426275|image-3426276|image-3426277
+        #elif str($image_ids.source) == 'dataset':
+            cat '${image_ids.id_spec}'
         #else:
-            cat '${image_ids.id_spec}'
+            echo '${image_ids.id_dataset_omero}'
         #end if
         | python '$__tool_directory__/idr_download_by_ids.py' 
+        #if str($image_ids.source) == 'omeroDatasetID':
+            --dataset
+        #end if
         #set $channel = str($channel).strip()
         #if $channel:
             -c '$channel'
@@ -100,6 +105,7 @@
             <param name="source" type="select" label="How would you like to specify the IDs of images to download?">
                 <option value="link">As text (comma-separated list of IDs or a valid IDR link)</option>
                 <option value="dataset">As a dataset (one image ID per line)</option>
+                <option value="omeroDatasetID">All images from a single Dataset ID</option>
             </param>
             <when value="link">
                 <param name="id_spec" type="text"
@@ -114,6 +120,9 @@
                 <param name="id_spec" type="data" format="txt"
                 label="Select a dataset with image IDs (one per line)" />
             </when>
+            <when value="omeroDatasetID">
+                <param name="id_dataset_omero" type="integer" min = "0" value = "9059" label="Dataset ID"/>
+            </when>
         </conditional>
         <param name="channel" type="text"
         label="Name of the channel to download"
@@ -362,6 +371,37 @@
                 <has_text text="OMERO connection credentials are empty. Set your credentials via: User -> Preferences -> Manage Information" />
             </assert_stderr >
         </test>
+        <test>
+            <conditional name="omero_instance_type">
+                 <param name="omero_instance" value="idr" />
+            </conditional>
+            <!-- Test for download all images from a dataset -->
+            <param name="source" value="omeroDatasetID" />
+            <param name="id_dataset_omero" value="9059" />
+            <param name="download_tar" value="false" />
+            <output_collection name="output_file" type="list" count="4">
+                <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D__9036711__0__0__1024__1024">
+                    <assert_contents>
+                        <has_size value="2097286" />
+                    </assert_contents>
+                </element>
+                <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D_D3D__9036708__0__0__1024__1024">
+                    <assert_contents>
+                        <has_size value="2097286" />
+                    </assert_contents>
+                </element>
+                <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D_D3D_zproj__9036710__0__0__1024__1024">
+                    <assert_contents>
+                        <has_size value="2097286" />
+                    </assert_contents>
+                </element>
+                <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D_REF__9036709__0__0__1024__1024">
+                    <assert_contents>
+                        <has_size value="2097286" />
+                    </assert_contents>
+                </element>
+            </output_collection>
+        </test>
     </tests>
     <help><![CDATA[
 Download image data from the IDR_ (Image Data Resource) - a public repository
@@ -391,6 +431,9 @@
 input field (comma or '|'-separated ), or as an input file (each ID on a
 separate line).
 
+Finally, if you want to download all images of a single dataset. Specify the id as 
+All images from a single Dataset ID.
+
 Most images in the IDR have more than two dimensions. Thus, there are
 parameters available which allow you to select a particular recording channel,
 z-plane or time frame to download.