Mercurial > repos > imgteam > imagej2_sharpen
annotate imagej2_bunwarpj_align.py @ 0:855fa4bb8a44 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 17:03:40 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"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 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 8 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 9 # Parse Command Line. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 10 parser = argparse.ArgumentParser() | 
| 
855fa4bb8a44
"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( '--source_image', dest='source_image', help='Source image' ) | 
| 
855fa4bb8a44
"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( '--source_image_format', dest='source_image_format', help='Source image format' ) | 
| 
855fa4bb8a44
"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( '--source_mask', dest='source_mask', default=None, help='Source mask' ) | 
| 
855fa4bb8a44
"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( '--source_mask_format', dest='source_mask_format', default=None, help='Source mask image format' ) | 
| 
855fa4bb8a44
"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( '--target_image', dest='target_image', help='Target image' ) | 
| 
855fa4bb8a44
"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( '--target_image_format', dest='target_image_format', help='Target image format' ) | 
| 
855fa4bb8a44
"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( '--target_mask', dest='target_mask', default=None, help='Target mask' ) | 
| 
855fa4bb8a44
"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( '--target_mask_format', dest='target_mask_format', default=None, help='Target mask image format' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 19 parser.add_argument( '--min_scale_def', dest='min_scale_def', type=int, help='Initial deformation' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 20 parser.add_argument( '--max_scale_def', dest='max_scale_def', type=int, help='Final deformation' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 21 parser.add_argument( '--max_subsamp_fact', dest='max_subsamp_fact', type=int, help='Image sub-sample factor' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 22 parser.add_argument( '--divergence_weight', dest='divergence_weight', type=float, help='Divergence weight' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 23 parser.add_argument( '--curl_weight', dest='curl_weight', type=float, help='Curl weight' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 24 parser.add_argument( '--image_weight', dest='image_weight', type=float, help='Image weight' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 25 parser.add_argument( '--consistency_weight', dest='consistency_weight', type=float, help='Consistency weight' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 26 parser.add_argument( '--landmarks_weight', dest='landmarks_weight', type=float, help='Landmarks weight' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 27 parser.add_argument( '--landmarks_file', dest='landmarks_file', default=None, help='Landmarks file' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 28 parser.add_argument( '--source_affine_file', dest='source_affine_file', default=None, help='Initial source affine matrix transformation' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 29 parser.add_argument( '--target_affine_file', dest='target_affine_file', default=None, help='Initial target affine matrix transformation' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 30 parser.add_argument( '--mono', dest='mono', default=False, help='Unidirectional registration (source to target)' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 31 parser.add_argument( '--source_trans_out', dest='source_trans_out', default=None, help='Direct source transformation matrix' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 32 parser.add_argument( '--target_trans_out', dest='target_trans_out', default=None, help='Inverse target transformation matrix' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 33 parser.add_argument( '--source_out', help='Output source image' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 34 parser.add_argument( '--source_out_datatype', help='Output registered source image format' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 35 parser.add_argument( '--target_out', default=None, help='Output target image' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 36 parser.add_argument( '--target_out_datatype', default=None, help='Output registered target image format' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 37 parser.add_argument( '--jython_script', dest='jython_script', help='Path to the Jython script' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 38 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 39 args = parser.parse_args() | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 40 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 41 if args.source_trans_out is not None and args.target_trans_out is not None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 42 save_transformation = True | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 43 else: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 44 save_transformation = False | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 45 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 46 tmp_dir = imagej2_base_utils.get_temp_dir() | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 47 source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 48 tmp_source_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 49 tmp_source_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.source_out_datatype ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 50 target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 51 if not args.mono: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 52 tmp_target_out_tiff_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'tiff' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 53 tmp_target_out_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.target_out_datatype ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 54 if args.source_mask is not None and args.target_mask is not None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 55 tmp_source_mask_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_mask, args.source_mask_format ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 56 tmp_target_mask_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_mask, args.target_mask_format ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 57 if save_transformation: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 58 # bUnwarpJ automatically names the transformation files based on the names | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 59 # of the source and target image file names. We've defined symlinks to | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 60 # temporary files with valid image extensions since ImageJ does not handle | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 61 # the Galaxy "dataset.dat" file extensions. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 62 source_file_name = imagej2_base_utils.get_file_name_without_extension( tmp_source_out_tiff_path ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 63 tmp_source_out_transf_path = os.path.join( tmp_dir, '%s_transf.txt' % source_file_name ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 64 target_file_name = imagej2_base_utils.get_file_name_without_extension( tmp_target_out_tiff_path ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 65 tmp_target_out_transf_path = os.path.join( tmp_dir, '%s_transf.txt' % target_file_name ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 66 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 67 # Define command response buffers. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 68 tmp_out = tempfile.NamedTemporaryFile().name | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 69 tmp_stdout = open( tmp_out, 'wb' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 70 tmp_err = tempfile.NamedTemporaryFile().name | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 71 tmp_stderr = open( tmp_err, 'wb' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 72 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 73 # Build the command line to align the two images. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 74 cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 75 if cmd is None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 76 imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 77 cmd += ' -align' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 78 # Target is sent before source. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 79 cmd += ' %s' % target_image_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 80 if args.target_mask is None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 81 target_mask_str = ' NULL' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 82 else: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 83 target_mask_str = ' %s' % tmp_target_mask_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 84 cmd += target_mask_str | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 85 cmd += ' %s' % source_image_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 86 if args.source_mask is None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 87 source_mask_str = ' NULL' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 88 else: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 89 source_mask_str = ' %s' % tmp_source_mask_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 90 cmd += source_mask_str | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 91 cmd += ' %d' % args.min_scale_def | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 92 cmd += ' %d' % args.max_scale_def | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 93 cmd += ' %d' % args.max_subsamp_fact | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 94 cmd += ' %.1f' % args.divergence_weight | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 95 cmd += ' %.1f' % args.curl_weight | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 96 cmd += ' %.1f' % args.image_weight | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 97 cmd += ' %.1f' % args.consistency_weight | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 98 # Source is produced before target. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 99 cmd += ' %s' % tmp_source_out_tiff_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 100 if not args.mono: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 101 cmd += ' %s' % tmp_target_out_tiff_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 102 if args.landmarks_file is not None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 103 # We have to create a temporary file with a .txt extension here so that | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 104 # bUnwarpJ will not ignore the Galaxy "dataset.dat" file. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 105 tmp_landmarks_file_path = imagej2_base_utils.get_input_image_path( tmp_dir, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 106 args.landmarks_file, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 107 'txt' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 108 cmd += ' -landmarks' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 109 cmd += ' %.1f' % args.landmarks_weight | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 110 cmd += ' %s' % tmp_landmarks_file_path | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 111 if args.source_affine_file is not None and args.target_affine_file is not None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 112 # Target is sent before source. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 113 cmd += ' -affine' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 114 cmd += ' %s' % args.target_affine_file | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 115 cmd += ' %s' % args.source_affine_file | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 116 if args.mono: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 117 cmd += ' -mono' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 118 if save_transformation: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 119 cmd += ' -save_transformation' | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 120 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 121 # Align the two images using bUnwarpJ. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 122 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 123 rc = proc.wait() | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 124 if rc != 0: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 125 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 126 imagej2_base_utils.stop_err( error_message ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 127 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 128 # bUnwarpJ produces tiff image stacks consisting of 3 slices which can be viewed in ImageJ. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 129 # The 3 slices are:: 1) the registered image, 2) the target image and 3) the black/white | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 130 # warp image. Galaxy supports only single-layered images, so we'll convert the images so they | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 131 # can be viewed in Galaxy. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 132 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 133 # Define command response buffers. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 134 tmp_out = tempfile.NamedTemporaryFile().name | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 135 tmp_stdout = open( tmp_out, 'wb' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 136 tmp_err = tempfile.NamedTemporaryFile().name | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 137 tmp_stderr = open( tmp_err, 'wb' ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 138 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 139 # Build the command line to handle the multi-slice tiff images. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 140 cmd = imagej2_base_utils.get_base_command_imagej2( None, jython_script=args.jython_script ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 141 if cmd is None: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 142 imagej2_base_utils.stop_err( "ImageJ not found!" ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 143 if args.mono: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 144 # bUnwarpJ will produce only a registered source image. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 145 cmd += ' %s %s %s %s' % ( tmp_source_out_tiff_path, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 146 args.source_out_datatype, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 147 tmp_source_out_path, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 148 args.mono ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 149 else: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 150 # bUnwarpJ will produce registered source and target images. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 151 cmd += ' %s %s %s %s %s %s %s' % ( tmp_source_out_tiff_path, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 152 args.source_out_datatype, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 153 tmp_source_out_path, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 154 tmp_target_out_tiff_path, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 155 args.target_out_datatype, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 156 tmp_target_out_path, | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 157 args.mono ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 158 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 159 # Merge the multi-slice tiff layers into an image that can be viewed in Galaxy. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 160 proc = subprocess.Popen( args=cmd, stderr=tmp_stderr, stdout=tmp_stdout, shell=True ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 161 rc = proc.wait() | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 162 if rc != 0: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 163 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 164 imagej2_base_utils.stop_err( error_message ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 165 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 166 # Save the Registered Source Image to the output dataset. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 167 shutil.move( tmp_source_out_path, args.source_out ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 168 if not args.mono: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 169 # Move the Registered Target Image to the output dataset. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 170 shutil.move( tmp_target_out_path, args.target_out ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 171 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 172 # If requested, save matrix transformations as additional datasets. | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 173 if save_transformation: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 174 shutil.move( tmp_source_out_transf_path, args.source_trans_out ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 175 if not args.mono: | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 176 shutil.move( tmp_target_out_transf_path, args.target_trans_out ) | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 177 | 
| 
855fa4bb8a44
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 imgteam parents: diff
changeset | 178 imagej2_base_utils.cleanup_before_exit( tmp_dir ) | 
