Mercurial > repos > imgteam > imagej2_bunwarpj_compose_raw_elastic
comparison imagej2_noise.py @ 0:1bf7e70e67f9 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:56:02 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1bf7e70e67f9 |
---|---|
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 if __name__=="__main__": | |
10 # Parse Command Line. | |
11 parser = argparse.ArgumentParser() | |
12 parser.add_argument( '--input', dest='input', help='Path to the input file' ) | |
13 parser.add_argument( '--input_datatype', dest='input_datatype', help='Datatype of the input image' ) | |
14 parser.add_argument( '--noise', dest='noise', help='Specified noise to add to or remove from the image' ) | |
15 parser.add_argument( '--standard_deviation', dest='standard_deviation', type=float, default=None, help='Standard deviation' ) | |
16 parser.add_argument( '--radius', dest='radius', type=float, default=None, help='Radius' ) | |
17 parser.add_argument( '--threshold', dest='threshold', type=float, default=None, help='Threshold' ) | |
18 parser.add_argument( '--which_outliers', dest='which_outliers', default=None, help='Which outliers' ) | |
19 parser.add_argument( '--randomj', dest='randomj', default=None, help='RandomJ' ) | |
20 parser.add_argument( '--trials', dest='trials', type=float, default=None, help='Trials' ) | |
21 parser.add_argument( '--probability', dest='probability', type=float, default=None, help='Probability' ) | |
22 parser.add_argument( '--lammbda', dest='lammbda', type=float, default=None, help='Lambda' ) | |
23 parser.add_argument( '--order', dest='order', type=int, default=None, help='Order' ) | |
24 parser.add_argument( '--mean', dest='mean', type=float, default=None, help='Mean' ) | |
25 parser.add_argument( '--sigma', dest='sigma', type=float, default=None, help='Sigma' ) | |
26 parser.add_argument( '--min', dest='min', type=float, default=None, help='Min' ) | |
27 parser.add_argument( '--max', dest='max', type=float, default=None, help='Max' ) | |
28 parser.add_argument( '--insertion', dest='insertion', default=None, help='Insertion' ) | |
29 parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) | |
30 parser.add_argument( '--output', dest='output', help='Path to the output file' ) | |
31 args = parser.parse_args() | |
32 | |
33 tmp_dir = imagej2_base_utils.get_temp_dir() | |
34 # ImageJ expects valid image file extensions, so the Galaxy .dat extension does not | |
35 # work for some features. The following creates a symlink with an appropriate file | |
36 # extension that points to the Galaxy dataset. This symlink is used by ImageJ. | |
37 tmp_input_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.input, args.input_datatype ) | |
38 tmp_output_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.input_datatype ) | |
39 | |
40 # Define command response buffers. | |
41 tmp_out = tempfile.NamedTemporaryFile().name | |
42 tmp_stdout = open( tmp_out, 'wb' ) | |
43 tmp_err = tempfile.NamedTemporaryFile().name | |
44 tmp_stderr = open( tmp_err, 'wb' ) | |
45 # Java writes a lot of stuff to stderr, so we'll specify a file for handling actual errors. | |
46 error_log = tempfile.NamedTemporaryFile( delete=False ).name | |
47 # Build the command line. | |
48 cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script ) | |
49 if cmd is None: | |
50 imagej2_base_utils.stop_err( "ImageJ not found!" ) | |
51 cmd += ' %s' % error_log | |
52 cmd += ' %s' % tmp_input_path | |
53 cmd += ' %s' % args.input_datatype | |
54 cmd += ' %s ' % args.noise | |
55 cmd += imagej2_base_utils.handle_none_type( args.standard_deviation ) | |
56 cmd += imagej2_base_utils.handle_none_type( args.radius ) | |
57 cmd += imagej2_base_utils.handle_none_type( args.threshold ) | |
58 cmd += ' %s' % args.which_outliers | |
59 cmd += ' %s' % args.randomj | |
60 cmd += imagej2_base_utils.handle_none_type( args.trials ) | |
61 cmd += imagej2_base_utils.handle_none_type( args.probability ) | |
62 cmd += imagej2_base_utils.handle_none_type( args.lammbda ) | |
63 cmd += imagej2_base_utils.handle_none_type( args.order, val_type='int' ) | |
64 cmd += imagej2_base_utils.handle_none_type( args.mean ) | |
65 cmd += imagej2_base_utils.handle_none_type( args.sigma ) | |
66 cmd += imagej2_base_utils.handle_none_type( args.min ) | |
67 cmd += imagej2_base_utils.handle_none_type( args.max ) | |
68 cmd += ' %s' % args.insertion | |
69 cmd += ' %s' % tmp_output_path | |
70 | |
71 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) | |
72 rc = proc.wait() | |
73 | |
74 # Handle execution errors. | |
75 if rc != 0: | |
76 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | |
77 imagej2_base_utils.stop_err( error_message ) | |
78 # Handle processing errors. | |
79 if os.path.getsize( error_log ) > 0: | |
80 error_message = open( error_log, 'r' ).read() | |
81 imagej2_base_utils.stop_err( error_message ) | |
82 # Save the output image. | |
83 shutil.move( tmp_output_path, args.output ) | |
84 imagej2_base_utils.cleanup_before_exit( tmp_dir ) |