comparison idr_download_by_ids.py @ 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 97f70f7ed077
children cbd605a24336
comparison
equal deleted inserted replaced
9:80af973c5277 10:4aed70472589
108 108
109 return selection 109 return selection
110 110
111 111
112 def download_image_data( 112 def download_image_data(
113 image_ids, 113 image_ids_or_dataset_id, dataset=False,
114 channel=None, z_stack=0, frame=0, 114 channel=None, z_stack=0, frame=0,
115 coord=(0, 0), width=0, height=0, region_spec='rectangle', 115 coord=(0, 0), width=0, height=0, region_spec='rectangle',
116 skip_failed=False, download_tar=False, omero_host='idr.openmicroscopy.org', omero_secured=False, config_file=None 116 skip_failed=False, download_tar=False, omero_host='idr.openmicroscopy.org', omero_secured=False, config_file=None
117 ): 117 ):
118 118
126 omero_password = cfg['password'] 126 omero_password = cfg['password']
127 127
128 if omero_username == "" or omero_password == "": 128 if omero_username == "" or omero_password == "":
129 omero_username = 'public' 129 omero_username = 'public'
130 omero_password = 'public' 130 omero_password = 'public'
131
132 # basic argument sanity checks and adjustments
133 prefix = 'image-'
134 # normalize image ids by stripping off prefix if it exists
135 image_ids = [
136 iid[len(prefix):] if iid[:len(prefix)] == prefix else iid
137 for iid in image_ids
138 ]
139 131
140 if region_spec not in ['rectangle', 'center']: 132 if region_spec not in ['rectangle', 'center']:
141 raise ValueError( 133 raise ValueError(
142 'Got unknown value "{0}" as region_spec argument' 134 'Got unknown value "{0}" as region_spec argument'
143 .format(region_spec) 135 .format(region_spec)
158 ) 150 )
159 tempdir = exit_stack.enter_context( 151 tempdir = exit_stack.enter_context(
160 TemporaryDirectory() 152 TemporaryDirectory()
161 ) 153 )
162 154
155 if dataset:
156 dataset_warning_id = 'Dataset-ID: {0}'.format(image_ids_or_dataset_id[0])
157 try:
158 dataset_id = int(image_ids_or_dataset_id[0])
159 except ValueError:
160 image_ids = None
161 else:
162 try:
163 dataset = conn.getObject("Dataset", dataset_id)
164 except Exception as e:
165 # respect skip_failed on unexpected errors
166 if skip_failed:
167 warn(str(e), dataset_warning_id, warn_skip=True)
168 else:
169 raise
170 else:
171 image_ids = [image.id for image in dataset.listChildren()]
172
173 if image_ids is None:
174 if skip_failed:
175 warn(
176 'Unable to find a dataset with this ID in the '
177 'database.',
178 dataset_warning_id,
179 warn_skip=True
180 )
181 else:
182 raise ValueError(
183 '{0}: Unable to find a dataset with this ID in the '
184 'database. Aborting!'
185 .format(dataset_warning_id)
186 )
187
188 else:
189 # basic argument sanity checks and adjustments
190 prefix = 'image-'
191 # normalize image ids by stripping off prefix if it exists
192 image_ids = [
193 iid[len(prefix):] if iid[:len(prefix)] == prefix else iid
194 for iid in image_ids_or_dataset_id
195 ]
163 for image_id in image_ids: 196 for image_id in image_ids:
164 image_warning_id = 'Image-ID: {0}'.format(image_id) 197 image_warning_id = 'Image-ID: {0}'.format(image_id)
165 try: 198 try:
166 image_id = int(image_id) 199 image_id = int(image_id)
167 except ValueError: 200 except ValueError:
328 361
329 362
330 if __name__ == "__main__": 363 if __name__ == "__main__":
331 p = argparse.ArgumentParser() 364 p = argparse.ArgumentParser()
332 p.add_argument( 365 p.add_argument(
333 'image_ids', nargs='*', default=[], 366 'image_ids_or_dataset_id', nargs='*', default=[],
334 help='one or more IDR image ids for which to retrieve data (default: ' 367 help='one or more IDR image ids or a single dataset id'
368 'for which to retrieve data (default: '
335 'read ids from stdin).' 369 'read ids from stdin).'
336 ) 370 )
337 p.add_argument( 371 p.add_argument(
338 '-c', '--channel', 372 '-c', '--channel',
339 help='name of the channel to retrieve data for ' 373 help='name of the channel to retrieve data for '
376 '--omero-secured', action='store_true', default=True 410 '--omero-secured', action='store_true', default=True
377 ) 411 )
378 p.add_argument( 412 p.add_argument(
379 '-cf', '--config-file', dest='config_file', default=None 413 '-cf', '--config-file', dest='config_file', default=None
380 ) 414 )
415 p.add_argument(
416 '--dataset', action='store_true'
417 )
381 args = p.parse_args() 418 args = p.parse_args()
382 if not args.image_ids: 419 if not args.image_ids_or_dataset_id:
383 args.image_ids = sys.stdin.read().split() 420 args.image_ids_or_dataset_id = sys.stdin.read().split()
421 if args.dataset and len(args.image_ids_or_dataset_id) > 1:
422 warn("Multiple dataset ids provided. Only the first one will be used.")
384 if 'center' in args: 423 if 'center' in args:
385 args.coord, args.width, args.height = ( 424 args.coord, args.width, args.height = (
386 args.center[:2], args.center[2], args.center[3] 425 args.center[:2], args.center[2], args.center[3]
387 ) 426 )
388 args.region_spec = 'center' 427 args.region_spec = 'center'