comparison imagej2_create_image.py @ 0:dd20ee3092e3 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 17:04:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dd20ee3092e3
1 #!/usr/bin/env python
2 import argparse
3 import shutil
4 import subprocess
5 import tempfile
6 import imagej2_base_utils
7
8 if __name__=="__main__":
9 # Parse Command Line.
10 parser = argparse.ArgumentParser()
11 parser.add_argument( '--width', dest='width', type=int, help='Image width in pixels' )
12 parser.add_argument( '--height', dest='height', type=int, help='Image height in pixels' )
13 parser.add_argument( '--depth', dest='depth', type=int, help='Image depth (specifies the number of stack slices)' )
14 parser.add_argument( '--image_type', dest='image_type', help='Image type' )
15 parser.add_argument( '--image_title', dest='image_title', default='', help='Image title' )
16 parser.add_argument( '--output_datatype', dest='output_datatype', help='Output image format' )
17 parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' )
18 parser.add_argument( '--out_fname', help='Path to the output file' )
19 args = parser.parse_args()
20
21 tmp_dir = imagej2_base_utils.get_temp_dir()
22 tmp_image_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.output_datatype )
23
24 # Define command response buffers.
25 tmp_out = tempfile.NamedTemporaryFile().name
26 tmp_stdout = open( tmp_out, 'wb' )
27 tmp_err = tempfile.NamedTemporaryFile().name
28 tmp_stderr = open( tmp_err, 'wb' )
29 # Build the command line.
30 cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script )
31 if cmd is None:
32 imagej2_base_utils.stop_err( "ImageJ not found!" )
33 cmd += ' %s %d %d %d %s %s' % ( args.image_title, args.width, args.height, args.depth, args.image_type, tmp_image_path )
34 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True )
35 rc = proc.wait()
36 if rc != 0:
37 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout )
38 imagej2_base_utils.stop_err( error_message )
39 shutil.move( tmp_image_path, args.out_fname )
40 imagej2_base_utils.cleanup_before_exit( tmp_dir )