Mercurial > repos > iuc > idr_download_by_ids
annotate 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 |
rev | line source |
---|---|
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
1 import argparse |
8
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
2 import json |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
3 import os |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
4 import sys |
4
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
5 import tarfile |
6
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
6 from contextlib import ExitStack |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
7 from tempfile import TemporaryDirectory |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
8 |
2
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
9 from libtiff import TIFF |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
10 from omero.gateway import BlitzGateway # noqa |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
11 from omero.constants.namespaces import NSBULKANNOTATIONS # noqa |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
12 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
13 |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
14 def warn(message, image_identifier, warn_skip=False): |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
15 message = message.rstrip() |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
16 if warn_skip: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
17 if message[-1] in ['.', '!', '?']: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
18 skip_msg = ' Skipping download!' |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
19 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
20 skip_msg = '. Skipping download!' |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
21 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
22 skip_msg = '' |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
23 print( |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
24 'ImageSpecWarning for {0}: {1}{2}' |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
25 .format( |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
26 image_identifier, |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
27 message, |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
28 skip_msg |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
29 ), |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
30 file=sys.stderr |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
31 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
32 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
33 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
34 def find_channel_index(image, channel_name): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
35 channel_name = channel_name.lower() |
2
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
36 for n, channel in enumerate(image.getChannelLabels()): |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
37 if channel_name == channel.lower(): |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
38 return n |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
39 # Check map annotation for information (this is necessary for some images) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
40 for ann in image.listAnnotations(NSBULKANNOTATIONS): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
41 pairs = ann.getValue() |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
42 for p in pairs: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
43 if p[0] == "Channels": |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
44 channels = p[1].replace(" ", "").split(";") |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
45 for n, c in enumerate(channels): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
46 for value in c.split(':'): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
47 if channel_name == value.lower(): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
48 return n |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
49 return -1 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
50 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
51 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
52 def get_clipping_region(image, x, y, w, h): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
53 # If the (x, y) coordinate falls outside the image boundaries, we |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
54 # cannot just shift it because that would render the meaning of |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
55 # w and h undefined (should width and height be decreased or the whole |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
56 # region be shifted to keep them fixed?). |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
57 # It may be better to abort in this situation. |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
58 if x < 0 or y < 0: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
59 raise ValueError( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
60 'Too small upper left coordinate ({0}, {1}) for clipping region.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
61 .format(x, y) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
62 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
63 size_x = image.getSizeX() |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
64 size_y = image.getSizeY() |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
65 if x >= size_x or y >= size_y: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
66 raise ValueError( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
67 'Upper left coordinate ({0}, {1}) of clipping region lies ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
68 'outside of image.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
69 .format(x, y) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
70 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
71 # adjust width and height to the image dimensions |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
72 if w <= 0 or x + w > size_x: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
73 w = size_x - x |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
74 if h <= 0 or y + h > size_y: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
75 h = size_y - y |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
76 return [x, y, w, h] |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
77 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
78 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
79 def confine_plane(image, z): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
80 if z < 0: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
81 z = 0 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
82 else: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
83 max_z = image.getSizeZ() - 1 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
84 if z > max_z: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
85 z = max_z |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
86 return z |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
87 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
88 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
89 def confine_frame(image, t): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
90 if t < 0: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
91 t = 0 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
92 else: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
93 max_t = image.getSizeT() - 1 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
94 if t > max_t: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
95 t = max_t |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
96 return t |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
97 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
98 |
4
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
99 def get_image_array(image, tile, z, c, t): |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
100 pixels = image.getPrimaryPixels() |
2
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
101 try: |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
102 selection = pixels.getTile(theZ=z, theT=t, theC=c, tile=tile) |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
103 except Exception: |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
104 warning = '{0} (ID: {1})'.format(image.getName(), |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
105 image.getId()) |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
106 warn('Could not download the requested region', warning) |
17b1cd0f4812
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 7d7d50f41a9da71b0f45f8b710e52696689a8d85"
iuc
parents:
1
diff
changeset
|
107 return |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
108 |
4
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
109 return selection |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
110 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
111 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
112 def download_image_data( |
10
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
113 image_ids_or_dataset_id, dataset=False, |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
114 channel=None, z_stack=0, frame=0, |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
115 coord=(0, 0), width=0, height=0, region_spec='rectangle', |
8
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
116 skip_failed=False, download_tar=False, omero_host='idr.openmicroscopy.org', omero_secured=False, config_file=None |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
117 ): |
8
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
118 |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
119 if config_file is None: # IDR connection |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
120 omero_username = 'public' |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
121 omero_password = 'public' |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
122 else: # other omero instance |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
123 with open(config_file) as f: |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
124 cfg = json.load(f) |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
125 omero_username = cfg['username'] |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
126 omero_password = cfg['password'] |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
127 |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
128 if omero_username == "" or omero_password == "": |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
129 omero_username = 'public' |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
130 omero_password = 'public' |
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
131 |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
132 if region_spec not in ['rectangle', 'center']: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
133 raise ValueError( |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
134 'Got unknown value "{0}" as region_spec argument' |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
135 .format(region_spec) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
136 ) |
6
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
137 with ExitStack() as exit_stack: |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
138 conn = exit_stack.enter_context( |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
139 BlitzGateway( |
7
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
140 omero_username, omero_password, |
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
141 host=omero_host, |
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
142 secure=omero_secured |
6
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
143 ) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
144 ) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
145 # exit_stack.callback(conn.connect().close) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
146 if download_tar: |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
147 # create an archive file to write images to |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
148 archive = exit_stack.enter_context( |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
149 tarfile.open('images.tar', mode='w') |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
150 ) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
151 tempdir = exit_stack.enter_context( |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
152 TemporaryDirectory() |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
153 ) |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
154 |
10
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
155 if dataset: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
156 dataset_warning_id = 'Dataset-ID: {0}'.format(image_ids_or_dataset_id[0]) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
157 try: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
158 dataset_id = int(image_ids_or_dataset_id[0]) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
159 except ValueError: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
160 image_ids = None |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
161 else: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
162 try: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
163 dataset = conn.getObject("Dataset", dataset_id) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
164 except Exception as e: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
165 # respect skip_failed on unexpected errors |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
166 if skip_failed: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
167 warn(str(e), dataset_warning_id, warn_skip=True) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
168 else: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
169 raise |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
170 else: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
171 image_ids = [image.id for image in dataset.listChildren()] |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
172 |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
173 if image_ids is None: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
174 if skip_failed: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
175 warn( |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
176 'Unable to find a dataset with this ID in the ' |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
177 'database.', |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
178 dataset_warning_id, |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
179 warn_skip=True |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
180 ) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
181 else: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
182 raise ValueError( |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
183 '{0}: Unable to find a dataset with this ID in the ' |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
184 'database. Aborting!' |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
185 .format(dataset_warning_id) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
186 ) |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
187 |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
188 else: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
189 # basic argument sanity checks and adjustments |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
190 prefix = 'image-' |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
191 # normalize image ids by stripping off prefix if it exists |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
192 image_ids = [ |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
193 iid[len(prefix):] if iid[:len(prefix)] == prefix else iid |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
194 for iid in image_ids_or_dataset_id |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
195 ] |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
196 for image_id in image_ids: |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
197 image_warning_id = 'Image-ID: {0}'.format(image_id) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
198 try: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
199 image_id = int(image_id) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
200 except ValueError: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
201 image = None |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
202 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
203 try: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
204 image = conn.getObject("Image", image_id) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
205 except Exception as e: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
206 # respect skip_failed on unexpected errors |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
207 if skip_failed: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
208 warn(str(e), image_warning_id, warn_skip=True) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
209 continue |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
210 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
211 raise |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
212 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
213 if image is None: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
214 if skip_failed: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
215 warn( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
216 'Unable to find an image with this ID in the ' |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
217 'database.', |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
218 image_warning_id, |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
219 warn_skip=True |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
220 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
221 continue |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
222 raise ValueError( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
223 '{0}: Unable to find an image with this ID in the ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
224 'database. Aborting!' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
225 .format(image_warning_id) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
226 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
227 |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
228 try: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
229 # try to extract image properties |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
230 # if anything goes wrong here skip the image |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
231 # or abort. |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
232 image_name = os.path.splitext(image.getName())[0] |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
233 image_warning_id = '{0} (ID: {1})'.format( |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
234 image_name, image_id |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
235 ) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
236 |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
237 if region_spec == 'rectangle': |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
238 tile = get_clipping_region(image, *coord, width, height) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
239 elif region_spec == 'center': |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
240 tile = get_clipping_region( |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
241 image, |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
242 *_center_to_ul(*coord, width, height) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
243 ) |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
244 |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
245 ori_z, z_stack = z_stack, confine_plane(image, z_stack) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
246 ori_frame, frame = frame, confine_frame(image, frame) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
247 num_channels = image.getSizeC() |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
248 if channel is None: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
249 channel_index = 0 |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
250 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
251 channel_index = find_channel_index(image, channel) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
252 except Exception as e: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
253 # respect skip_failed on unexpected errors |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
254 if skip_failed: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
255 warn(str(e), image_warning_id, warn_skip=True) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
256 continue |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
257 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
258 raise |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
259 |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
260 # region sanity checks and warnings |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
261 if tile[2] < width or tile[3] < height: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
262 # The downloaded image region will have smaller dimensions |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
263 # than the specified width x height. |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
264 warn( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
265 'Downloaded image dimensions ({0} x {1}) will be smaller ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
266 'than the specified width and height ({2} x {3}).' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
267 .format(tile[2], tile[3], width, height), |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
268 image_warning_id |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
269 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
270 |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
271 # z-stack sanity checks and warnings |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
272 if z_stack != ori_z: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
273 warn( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
274 'Specified image plane ({0}) is out of bounds. Using {1} ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
275 'instead.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
276 .format(ori_z, z_stack), |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
277 image_warning_id |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
278 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
279 |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
280 # frame sanity checks and warnings |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
281 if frame != ori_frame: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
282 warn( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
283 'Specified image frame ({0}) is out of bounds. Using ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
284 'frame {1} instead.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
285 .format(ori_frame, frame), |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
286 image_warning_id |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
287 ) |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
288 |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
289 # channel index sanity checks and warnings |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
290 if channel is None: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
291 if num_channels > 1: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
292 warn( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
293 'No specific channel selected for multi-channel ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
294 'image. Using first of {0} channels.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
295 .format(num_channels), |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
296 image_warning_id |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
297 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
298 else: |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
299 if channel_index == -1 or channel_index >= num_channels: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
300 if skip_failed: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
301 warn( |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
302 str(channel) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
303 + ' is not a known channel name for this image.', |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
304 image_warning_id, |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
305 warn_skip=True |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
306 ) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
307 continue |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
308 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
309 raise ValueError( |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
310 '"{0}" is not a known channel name for image {1}. ' |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
311 'Aborting!' |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
312 .format(channel, image_warning_id) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
313 ) |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
314 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
315 # download and save the region as TIFF |
1
9340cbc7796c
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit c496b34c7f6265cccd9326fd239542d9e625c1a4"
iuc
parents:
0
diff
changeset
|
316 fname = '__'.join( |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
317 [image_name, str(image_id)] + [str(x) for x in tile] |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
318 ) |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
319 try: |
4
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
320 if fname[-5:] != '.tiff': |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
321 fname += '.tiff' |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
322 |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
323 fname = fname.replace(' ', '_') |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
324 |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
325 im_array = get_image_array(image, tile, z_stack, channel_index, frame) |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
326 |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
327 if download_tar: |
6
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
328 fname = os.path.join(tempdir, fname) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
329 try: |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
330 tiff = TIFF.open(fname, mode='w') |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
331 tiff.write_image(im_array) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
332 finally: |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
333 tiff.close() |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
334 # move image into tarball |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
335 if download_tar: |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
336 archive.add(fname, os.path.basename(fname)) |
5c743356df83
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bf331f8e60e7bc1daf1cd71d2068062d925e7ffa"
iuc
parents:
5
diff
changeset
|
337 os.remove(fname) |
3
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
338 except Exception as e: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
339 if skip_failed: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
340 # respect skip_failed on unexpected errors |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
341 warn(str(e), image_warning_id, warn_skip=True) |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
342 continue |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
343 else: |
381f248febba
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 0ae8913ec1c14caedc9836d4889650ea836a1d70"
iuc
parents:
2
diff
changeset
|
344 raise |
4
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
345 |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
346 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
347 def _center_to_ul(center_x, center_y, width, height): |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
348 if width > 0: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
349 ext_x = (width - 1) // 2 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
350 ul_x = max([center_x - ext_x, 0]) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
351 width = center_x + ext_x + 1 - ul_x |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
352 else: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
353 ul_x = 0 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
354 if height > 0: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
355 ext_y = (height - 1) // 2 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
356 ul_y = max([center_y - ext_y, 0]) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
357 height = center_y + ext_y + 1 - ul_y |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
358 else: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
359 ul_y = 0 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
360 return ul_x, ul_y, width, height |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
361 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
362 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
363 if __name__ == "__main__": |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
364 p = argparse.ArgumentParser() |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
365 p.add_argument( |
10
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
366 'image_ids_or_dataset_id', nargs='*', default=[], |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
367 help='one or more IDR image ids or a single dataset id' |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
368 'for which to retrieve data (default: ' |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
369 'read ids from stdin).' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
370 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
371 p.add_argument( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
372 '-c', '--channel', |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
373 help='name of the channel to retrieve data for ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
374 '(note: the first channel of each image will be downloaded if ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
375 'left unspecified)' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
376 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
377 region = p.add_mutually_exclusive_group() |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
378 region.add_argument( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
379 '--rectangle', nargs=4, type=int, default=argparse.SUPPRESS, |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
380 help='specify a clipping region for the image as x y width height, ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
381 'where x and y give the upper left coordinate of the rectangle ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
382 'to clip to. Set width and height to 0 to extend the rectangle ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
383 'to the actual size of the image.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
384 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
385 region.add_argument( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
386 '--center', nargs=4, type=int, default=argparse.SUPPRESS, |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
387 help='specify a clipping region for the image as x y width height, ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
388 'where x and y define the center of a width x height rectangle. ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
389 'Set either width or height to 0 to extend the region to the ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
390 'actual size of the image along the x- or y-axis.\n' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
391 'Note: Even values for width and height will be rounded down to ' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
392 'the nearest odd number.' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
393 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
394 p.add_argument( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
395 '-f', '--frame', type=int, default=0 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
396 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
397 p.add_argument( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
398 '-z', '--z-stack', type=int, default=0 |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
399 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
400 p.add_argument( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
401 '--skip-failed', action='store_true' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
402 ) |
4
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
403 p.add_argument( |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
404 '--download-tar', action='store_true' |
11036f6197d6
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 3c3f1023af1edb4c63f59f4311cc078d9e88923f"
iuc
parents:
3
diff
changeset
|
405 ) |
7
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
406 p.add_argument( |
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
407 '-oh', '--omero-host', type=str, default="idr.openmicroscopy.org" |
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
408 ) |
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
409 p.add_argument( |
8
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
410 '--omero-secured', action='store_true', default=True |
7
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
411 ) |
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
412 p.add_argument( |
8
97f70f7ed077
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit e337464c8219abdb7e8664ba94cff46025070664"
iuc
parents:
7
diff
changeset
|
413 '-cf', '--config-file', dest='config_file', default=None |
7
f067504aa92a
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 6b9df5f3cf2518e48eced93a2904a89776bde02d"
iuc
parents:
6
diff
changeset
|
414 ) |
10
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
415 p.add_argument( |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
416 '--dataset', action='store_true' |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
417 ) |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
418 args = p.parse_args() |
10
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
419 if not args.image_ids_or_dataset_id: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
420 args.image_ids_or_dataset_id = sys.stdin.read().split() |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
421 if args.dataset and len(args.image_ids_or_dataset_id) > 1: |
4aed70472589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit bb22e94226d3bcf241a6fe27e426b541a36a0815"
iuc
parents:
8
diff
changeset
|
422 warn("Multiple dataset ids provided. Only the first one will be used.") |
0
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
423 if 'center' in args: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
424 args.coord, args.width, args.height = ( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
425 args.center[:2], args.center[2], args.center[3] |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
426 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
427 args.region_spec = 'center' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
428 del args.center |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
429 elif 'rectangle' in args: |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
430 args.coord, args.width, args.height = ( |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
431 args.rectangle[:2], args.rectangle[2], args.rectangle[3] |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
432 ) |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
433 args.region_spec = 'rectangle' |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
434 del args.rectangle |
57aa9597cd31
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/idr_download commit 253efabdfea3a1fecc4c0f2c54c0e97a7d7960ab"
iuc
parents:
diff
changeset
|
435 download_image_data(**vars(args)) |