comparison imagej2_bunwarpj_convert_to_raw.py @ 0:f6df6830d5ec draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
author imgteam
date Tue, 17 Sep 2019 16:57:15 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f6df6830d5ec
1 #!/usr/bin/env python
2 import argparse
3 import subprocess
4 import tempfile
5 import imagej2_base_utils
6
7 # Parse Command Line.
8 parser = argparse.ArgumentParser()
9 parser.add_argument( '--source_image', dest='source_image', help='Source image' )
10 parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' )
11 parser.add_argument( '--target_image', dest='target_image', help='Target image' )
12 parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' )
13 parser.add_argument( '--elastic_transformation', dest='elastic_transformation', help='Elastic transformation as saved by bUnwarpJ in elastic format' )
14 parser.add_argument( '--raw_transformation', dest='raw_transformation', help='Raw transformation' )
15
16 args = parser.parse_args()
17
18 tmp_dir = imagej2_base_utils.get_temp_dir()
19 source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format )
20 target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format )
21 elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.elastic_transformation, 'txt' )
22
23 # Define command response buffers.
24 tmp_out = tempfile.NamedTemporaryFile().name
25 tmp_stdout = open( tmp_out, 'wb' )
26 tmp_err = tempfile.NamedTemporaryFile().name
27 tmp_stderr = open( tmp_err, 'wb' )
28
29 # Build the command line to convert the B-spline (i.e., elastic) transformation to raw.
30 cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None )
31 if cmd is None:
32 imagej2_base_utils.stop_err( "bUnwarpJ not found!" )
33 cmd += ' -convert_to_raw'
34 # Target is sent before source.
35 cmd += ' %s' % target_image_path
36 cmd += ' %s' % source_image_path
37 cmd += ' %s' % elastic_transformation_path
38 cmd += ' %s' % args.raw_transformation
39
40 # Convert the elastic transformation to raw using bUnwarpJ.
41 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True )
42 rc = proc.wait()
43 if rc != 0:
44 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout )
45 imagej2_base_utils.stop_err( error_message )
46
47 imagej2_base_utils.cleanup_before_exit( tmp_dir )