Mercurial > repos > imgteam > imagej2_find_maxima
annotate imagej2_analyze_skeleton.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 | 
| rev | line source | 
|---|---|
| 0 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 1 #!/usr/bin/env python | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 2 import argparse | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 3 import os | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 4 import shutil | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 5 import subprocess | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 6 import tempfile | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 7 import imagej2_base_utils | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 8 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 9 parser = argparse.ArgumentParser() | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 10 parser.add_argument( '--input', dest='input', help='Path to the input file' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 11 parser.add_argument( '--input_datatype', dest='input_datatype', help='Datatype of the input image' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 12 parser.add_argument( '--black_background', dest='black_background', help='Black background' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 13 parser.add_argument( '--prune_cycle_method', dest='prune_cycle_method', default='none', help='Prune cycle method' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 14 parser.add_argument( '--prune_ends', dest='prune_ends', default='no', help='Prune ends' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 15 parser.add_argument( '--calculate_largest_shortest_path', dest='calculate_largest_shortest_path', default='no', help='Calculate largest shortest path' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 16 parser.add_argument( '--show_detailed_info', dest='show_detailed_info', default='no', help='Show detailed info' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 17 parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 18 parser.add_argument( '--output', dest='output', help='Path to the output file' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 19 args = parser.parse_args() | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 20 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 21 tmp_dir = imagej2_base_utils.get_temp_dir() | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 22 # ImageJ expects valid image file extensions, so the Galaxy .dat extension does not | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 23 # work for some features. The following creates a symlink with an appropriate file | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 24 # extension that points to the Galaxy dataset. This symlink is used by ImageJ. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 25 tmp_input_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.input, args.input_datatype ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 26 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 27 # Define command response buffers. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 28 tmp_out = tempfile.NamedTemporaryFile().name | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 29 tmp_stdout = open( tmp_out, 'wb' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 30 tmp_err = tempfile.NamedTemporaryFile().name | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 31 tmp_stderr = open( tmp_err, 'wb' ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 32 # Java writes a lot of stuff to stderr, so we'll specify a file for handling actual errors. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 33 error_log = tempfile.NamedTemporaryFile( delete=False ).name | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 34 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 35 # Build the command line. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 36 cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 37 if cmd is None: | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 38 imagej2_base_utils.stop_err( "ImageJ not found!" ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 39 cmd += ' %s' % error_log | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 40 cmd += ' %s' % tmp_input_path | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 41 cmd += ' %s' % args.black_background | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 42 cmd += ' %s' % args.prune_cycle_method | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 43 cmd += ' %s' % args.prune_ends | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 44 cmd += ' %s' % args.calculate_largest_shortest_path | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 45 cmd += ' %s' % args.show_detailed_info | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 46 cmd += ' %s' % args.output | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 47 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 48 # Run the command. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 49 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 50 rc = proc.wait() | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 51 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 52 # Handle execution errors. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 53 if rc != 0: | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 54 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 55 imagej2_base_utils.stop_err( error_message ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 56 # Handle processing errors. | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 57 if os.path.getsize( error_log ) > 0: | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 58 error_message = open( error_log, 'r' ).read() | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 59 imagej2_base_utils.stop_err( error_message ) | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 60 | 
| 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 61 imagej2_base_utils.cleanup_before_exit( tmp_dir ) | 
