Mercurial > repos > imgteam > imagej2_find_maxima
comparison imagej2_smooth.py @ 0:2395ccf9ccc1 draft default tip
"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:59 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:2395ccf9ccc1 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 import argparse | |
| 3 import os | |
| 4 import shutil | |
| 5 import subprocess | |
| 6 import tempfile | |
| 7 import imagej2_base_utils | |
| 8 | |
| 9 parser = argparse.ArgumentParser() | |
| 10 parser.add_argument( '--input', dest='input', help='Path to the input file' ) | |
| 11 parser.add_argument( '--input_datatype', dest='input_datatype', help='Datatype of the input image' ) | |
| 12 parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) | |
| 13 parser.add_argument( '--output', dest='output', help='Path to the output file' ) | |
| 14 parser.add_argument( '--output_datatype', dest='output_datatype', help='Datatype of the output image' ) | |
| 15 args = parser.parse_args() | |
| 16 | |
| 17 tmp_dir = imagej2_base_utils.get_temp_dir() | |
| 18 # ImageJ expects valid image file extensions, so the Galaxy .dat extension does not | |
| 19 # work for some features. The following creates a symlink with an appropriate file | |
| 20 # extension that points to the Galaxy dataset. This symlink is used by ImageJ. | |
| 21 tmp_input_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.input, args.input_datatype ) | |
| 22 tmp_output_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 # Java writes a lot of stuff to stderr, so we'll specify a file for handling actual errors. | |
| 30 error_log = tempfile.NamedTemporaryFile( delete=False ).name | |
| 31 | |
| 32 # Build the command line. | |
| 33 cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script ) | |
| 34 if cmd is None: | |
| 35 imagej2_base_utils.stop_err( "ImageJ not found!" ) | |
| 36 cmd += ' %s' % error_log | |
| 37 cmd += ' %s' % tmp_input_path | |
| 38 cmd += ' %s' % tmp_output_path | |
| 39 cmd += ' %s' % args.output_datatype | |
| 40 | |
| 41 # Run the command. | |
| 42 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) | |
| 43 rc = proc.wait() | |
| 44 | |
| 45 # Handle execution errors. | |
| 46 if rc != 0: | |
| 47 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | |
| 48 imagej2_base_utils.stop_err( error_message ) | |
| 49 | |
| 50 # Handle processing errors. | |
| 51 if os.path.getsize( error_log ) > 0: | |
| 52 error_message = open( error_log, 'r' ).read() | |
| 53 imagej2_base_utils.stop_err( error_message ) | |
| 54 | |
| 55 # Save the output image. | |
| 56 shutil.move( tmp_output_path, args.output ) | |
| 57 imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
