Mercurial > repos > iuc > idr_download_by_ids
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:9340cbc7796c | 2:17b1cd0f4812 |
---|---|
1 import argparse | 1 import argparse |
2 import os | 2 import os |
3 import sys | 3 import sys |
4 | 4 |
5 from matplotlib import pyplot as plt | 5 from libtiff import TIFF |
6 from omero.gateway import BlitzGateway # noqa | 6 from omero.gateway import BlitzGateway # noqa |
7 from omero.constants.namespaces import NSBULKANNOTATIONS # noqa | 7 from omero.constants.namespaces import NSBULKANNOTATIONS # noqa |
8 | 8 |
9 | 9 |
10 def warn(message, image_identifier): | 10 def warn(message, image_identifier): |
15 ) | 15 ) |
16 | 16 |
17 | 17 |
18 def find_channel_index(image, channel_name): | 18 def find_channel_index(image, channel_name): |
19 channel_name = channel_name.lower() | 19 channel_name = channel_name.lower() |
20 for n, channel in enumerate(image.getChannels()): | 20 for n, channel in enumerate(image.getChannelLabels()): |
21 if channel_name == channel.getLabel().lower(): | 21 if channel_name == channel.lower(): |
22 return n | 22 return n |
23 # Check map annotation for information (this is necessary for some images) | 23 # Check map annotation for information (this is necessary for some images) |
24 for ann in image.listAnnotations(NSBULKANNOTATIONS): | 24 for ann in image.listAnnotations(NSBULKANNOTATIONS): |
25 pairs = ann.getValue() | 25 pairs = ann.getValue() |
26 for p in pairs: | 26 for p in pairs: |
80 return t | 80 return t |
81 | 81 |
82 | 82 |
83 def download_plane_as_tiff(image, tile, z, c, t, fname): | 83 def download_plane_as_tiff(image, tile, z, c, t, fname): |
84 pixels = image.getPrimaryPixels() | 84 pixels = image.getPrimaryPixels() |
85 selection = pixels.getTile(theZ=z, theT=t, theC=c, tile=tile) | 85 try: |
86 selection = pixels.getTile(theZ=z, theT=t, theC=c, tile=tile) | |
87 except Exception: | |
88 warning = '{0} (ID: {1})'.format(image.getName(), | |
89 image.getId()) | |
90 warn('Could not download the requested region', warning) | |
91 return | |
86 | 92 |
87 if fname[-5:] != '.tiff': | 93 if fname[-5:] != '.tiff': |
88 fname += '.tiff' | 94 fname += '.tiff' |
89 plt.imsave(fname, selection) | 95 try: |
96 tiff = TIFF.open(fname, mode='w') | |
97 tiff.write_image(selection) | |
98 finally: | |
99 tiff.close() | |
90 | 100 |
91 | 101 |
92 def download_image_data( | 102 def download_image_data( |
93 image_ids, | 103 image_ids, |
94 channel=None, z_stack=0, frame=0, | 104 channel=None, z_stack=0, frame=0, |
180 .format(num_channels), | 190 .format(num_channels), |
181 image_warning_id | 191 image_warning_id |
182 ) | 192 ) |
183 else: | 193 else: |
184 channel_index = find_channel_index(image, channel) | 194 channel_index = find_channel_index(image, channel) |
185 if channel_index == -1: | 195 if channel_index == -1 or channel_index >= image.getSizeC(): |
186 raise ValueError( | 196 raise ValueError( |
187 '"{0}" is not a known channel name for image {1}' | 197 '"{0}" is not a known channel name for image {1}' |
188 .format(channel, image.getName()) | 198 .format(channel, image.getName()) |
189 ) | 199 ) |
190 | 200 |