Mercurial > repos > iuc > idr_download_by_ids
diff idr_download_by_ids.py @ 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 |
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())