Mercurial > repos > bgruening > imagej2_bunwarpj_convert_to_raw
annotate imagej2_bunwarpj_compose_raw.py @ 0:191d574ddd8d draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
author | bgruening |
---|---|
date | Sat, 18 Mar 2017 09:43:20 -0400 |
parents | |
children |
rev | line source |
---|---|
0
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
2 import argparse |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
3 import subprocess |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
4 import tempfile |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
5 import imagej2_base_utils |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
6 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
7 # Parse Command Line. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
8 parser = argparse.ArgumentParser() |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
9 parser.add_argument( '--source_image', dest='source_image', help='Source image' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
10 parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
11 parser.add_argument( '--target_image', dest='target_image', help='Target image' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
12 parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
13 parser.add_argument( '--source_raw_transformation', dest='source_raw_transformation', help='Direct source transformation matrix' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
14 parser.add_argument( '--target_raw_transformation', dest='target_raw_transformation', help='Inverse target transformation matrix' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
15 parser.add_argument( '--output', dest='output', help='Warping index' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
16 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
17 args = parser.parse_args() |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
18 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
19 tmp_dir = imagej2_base_utils.get_temp_dir() |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
20 source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
21 target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
22 source_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_raw_transformation, 'txt' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
23 target_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_raw_transformation, 'txt' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
24 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
25 # Define command response buffers. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
26 tmp_out = tempfile.NamedTemporaryFile().name |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
27 tmp_stdout = open( tmp_out, 'wb' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
28 tmp_err = tempfile.NamedTemporaryFile().name |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
29 tmp_stderr = open( tmp_err, 'wb' ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
30 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
31 # Build the command line to compose the two raw transformations. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
32 cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
33 if cmd is None: |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
34 imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
35 cmd += ' -compose_raw' |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
36 # Target is sent before source. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
37 cmd += ' %s' % target_image_path |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
38 cmd += ' %s' % source_image_path |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
39 cmd += ' %s' % target_raw_transformation_path |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
40 cmd += ' %s' % source_raw_transformation_path |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
41 cmd += ' %s' % args.output |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
42 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
43 # Compose the two raw transformations into another raw transformation using bUnwarpJ. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
44 proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
45 rc = proc.wait() |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
46 if rc != 0: |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
47 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
48 imagej2_base_utils.stop_err( error_message ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
49 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
50 imagej2_base_utils.cleanup_before_exit( tmp_dir ) |