changeset 2:17b1cd0f4812 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
author iuc
date Tue, 14 Apr 2020 10:27:25 -0400
parents 9340cbc7796c
children 381f248febba
files idr_download_by_ids.py idr_download_by_ids.xml test-data/test1.tiff
diffstat 3 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/idr_download_by_ids.py	Tue Mar 24 13:48:46 2020 -0400
+++ b/idr_download_by_ids.py	Tue Apr 14 10:27:25 2020 -0400
@@ -2,7 +2,7 @@
 import os
 import sys
 
-from matplotlib import pyplot as plt
+from libtiff import TIFF
 from omero.gateway import BlitzGateway  # noqa
 from omero.constants.namespaces import NSBULKANNOTATIONS  # noqa
 
@@ -17,8 +17,8 @@
 
 def find_channel_index(image, channel_name):
     channel_name = channel_name.lower()
-    for n, channel in enumerate(image.getChannels()):
-        if channel_name == channel.getLabel().lower():
+    for n, channel in enumerate(image.getChannelLabels()):
+        if channel_name == channel.lower():
             return n
     # Check map annotation for information (this is necessary for some images)
     for ann in image.listAnnotations(NSBULKANNOTATIONS):
@@ -82,11 +82,21 @@
 
 def download_plane_as_tiff(image, tile, z, c, t, fname):
     pixels = image.getPrimaryPixels()
-    selection = pixels.getTile(theZ=z, theT=t, theC=c, tile=tile)
+    try:
+        selection = pixels.getTile(theZ=z, theT=t, theC=c, tile=tile)
+    except Exception:
+        warning = '{0} (ID: {1})'.format(image.getName(),
+                                         image.getId())
+        warn('Could not download the requested region', warning)
+        return
 
     if fname[-5:] != '.tiff':
         fname += '.tiff'
-    plt.imsave(fname, selection)
+    try:
+        tiff = TIFF.open(fname, mode='w')
+        tiff.write_image(selection)
+    finally:
+        tiff.close()
 
 
 def download_image_data(
@@ -182,7 +192,7 @@
                     )
             else:
                 channel_index = find_channel_index(image, channel)
-                if channel_index == -1:
+                if channel_index == -1 or channel_index >= image.getSizeC():
                     raise ValueError(
                         '"{0}" is not a known channel name for image {1}'
                         .format(channel, image.getName())
--- a/idr_download_by_ids.xml	Tue Mar 24 13:48:46 2020 -0400
+++ b/idr_download_by_ids.xml	Tue Apr 14 10:27:25 2020 -0400
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<tool id="idr_download_by_ids" name="IDR Download" version="0.10" profile="18.09">
+<tool id="idr_download_by_ids" name="IDR Download" version="0.20" 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">
@@ -17,7 +17,7 @@
     </macros>
     <requirements>
         <requirement type="package" version="5.6.0">python-omero</requirement>
-        <requirement type="package" version="3.1.3">matplotlib</requirement>
+        <requirement type="package" version="0.4.2">pylibtiff</requirement>
     </requirements>
     <command detect_errors="exit_code"><![CDATA[
         mkdir downloads && cd downloads &&
@@ -154,7 +154,7 @@
             <output_collection name="output_file" type="list" count="3">
                 <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D__9036711__0__0__1024__1024">
                     <assert_contents>
-                        <has_size value="4194510" />
+                        <has_size value="2097286" />
                     </assert_contents>
                 </element>
             </output_collection>
@@ -191,7 +191,7 @@
             <output_collection name="output_file" type="list" count="2">
                 <element name="171101_LeadingEdgeDeletionPSMMovies01_15_R3D__9036711__0__0__1024__1024">
                     <assert_contents>
-                        <has_size value="4194510" />
+                        <has_size value="2097286" />
                     </assert_contents>
                 </element>
             </output_collection>
Binary file test-data/test1.tiff has changed