Mercurial > repos > imgteam > imagej2_bunwarpj_compose_raw
comparison imagej2_find_maxima.py @ 0:93b416f8e9e3 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:00:19 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:93b416f8e9e3 |
---|---|
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( '--scale_when_converting', dest='scale_when_converting', help='Scale when converting RGB image' ) | |
13 parser.add_argument( '--weighted_rgb_conversions', dest='weighted_rgb_conversions', help='Weighted RGB conversions for RGB image' ) | |
14 parser.add_argument( '--noise_tolerance', dest='noise_tolerance', type=int, help='Noise tolerance' ) | |
15 parser.add_argument( '--output_type', dest='output_type', help='Output type' ) | |
16 parser.add_argument( '--exclude_edge_maxima', dest='exclude_edge_maxima', help='Exclude edge maxima' ) | |
17 parser.add_argument( '--light_background', dest='light_background', help='Light background' ) | |
18 parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) | |
19 parser.add_argument( '--output', dest='output', help='Path to the output file' ) | |
20 parser.add_argument( '--output_datatype', dest='output_datatype', help='Datatype of the output image' ) | |
21 args = parser.parse_args() | |
22 | |
23 tmp_dir = imagej2_base_utils.get_temp_dir() | |
24 # ImageJ expects valid image file extensions, so the Galaxy .dat extension does not | |
25 # work for some features. The following creates a symlink with an appropriate file | |
26 # extension that points to the Galaxy dataset. This symlink is used by ImageJ. | |
27 tmp_input_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.input, args.input_datatype ) | |
28 tmp_output_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.output_datatype ) | |
29 | |
30 # Define command response buffers. | |
31 tmp_out = tempfile.NamedTemporaryFile().name | |
32 tmp_stdout = open( tmp_out, 'wb' ) | |
33 tmp_err = tempfile.NamedTemporaryFile().name | |
34 tmp_stderr = open( tmp_err, 'wb' ) | |
35 # Java writes a lot of stuff to stderr, so we'll specify a file for handling actual errors. | |
36 error_log = tempfile.NamedTemporaryFile( delete=False ).name | |
37 | |
38 # Build the command line. | |
39 cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script ) | |
40 if cmd is None: | |
41 imagej2_base_utils.stop_err( "ImageJ not found!" ) | |
42 cmd += ' %s' % error_log | |
43 cmd += ' %s' % tmp_input_path | |
44 cmd += ' %s' % args.scale_when_converting | |
45 cmd += ' %s' % args.weighted_rgb_conversions | |
46 cmd += ' %d' % args.noise_tolerance | |
47 cmd += ' %s' % args.output_type | |
48 cmd += ' %s' % args.exclude_edge_maxima | |
49 cmd += ' %s' % args.light_background | |
50 cmd += ' %s' % tmp_output_path | |
51 cmd += ' %s' % args.output_datatype | |
52 | |
53 # Run the command. | |
54 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) | |
55 rc = proc.wait() | |
56 | |
57 # Handle execution errors. | |
58 if rc != 0: | |
59 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | |
60 imagej2_base_utils.stop_err( error_message ) | |
61 | |
62 # Handle processing errors. | |
63 if os.path.getsize( error_log ) > 0: | |
64 error_message = open( error_log, 'r' ).read() | |
65 imagej2_base_utils.stop_err( error_message ) | |
66 | |
67 # Save the output image. | |
68 shutil.move( tmp_output_path, args.output ) | |
69 imagej2_base_utils.cleanup_before_exit( tmp_dir ) |