Mercurial > repos > imgteam > imagej2_bunwarpj_align
diff imagej2_bunwarpj_align.xml @ 1:e9243cad1d67 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
author | imgteam |
---|---|
date | Mon, 28 Sep 2020 16:40:20 +0000 |
parents | ab54024c0a88 |
children | 0a0d2dfd17e0 |
line wrap: on
line diff
--- a/imagej2_bunwarpj_align.xml Tue Sep 17 17:02:18 2019 -0400 +++ b/imagej2_bunwarpj_align.xml Mon Sep 28 16:40:20 2020 +0000 @@ -1,67 +1,120 @@ -<?xml version='1.0' encoding='UTF-8'?> <tool id="imagej2_bunwarpj_align" name="Align two images" version="@WRAPPER_VERSION@.0"> <description>with bUnwarpJ</description> <macros> <import>imagej2_macros.xml</import> </macros> - <expand macro="fiji_requirements" /> - <command> -<![CDATA[ - python $__tool_directory__/imagej2_bunwarpj_align.py - --target_image "$target_image" - --target_image_format $target_image.ext - --source_image "$source_image" - --source_image_format $source_image.ext - #if $align_with_mask_cond.align_with_mask == 'yes': - --target_mask "$target_mask" - --target_mask_format $target_mask.ext - --source_mask "$source_mask" - --source_mask_format $source_mask.ext - #end if - --min_scale_def $min_scale_def - --max_scale_def $max_scale_def - --max_subsamp_fact $max_subsamp_fact - --divergence_weight $divergence_weight - --curl_weight $curl_weight - --image_weight $image_weight - --consistency_weight $consistency_weight - #if $advanced_options_cond.advanced_options == 'landmarks': - --landmarks_weight $advanced_options_cond.landmarks_weight - --landmarks_file "$advanced_options_cond.landmarks_file" - #else if $advanced_options_cond.advanced_options == 'affine': - --target_affine_file "$advanced_options_cond.target_affine_file" - --source_affine_file "$advanced_options_cond.source_affine_file" - #else if $advanced_options_cond.advanced_options == 'mono': - --mono "true" - #else if $advanced_options_cond.advanced_options == 'save_transformation': - --target_trans_out "$target_trans_out" - --source_trans_out "$source_trans_out" - #end if - --source_out "$source_out" - --source_out_datatype $source_out_datatype - #if $advanced_options_cond.advanced_options != 'mono': - --target_out "$target_out" - --target_out_datatype $target_out_datatype - #end if - --jython_script $__tool_directory__/imagej2_bunwarpj_align_jython_script.py -]]> - </command> + <expand macro="fiji_requirements"/> + <command detect_errors="exit_code"><![CDATA[ +#import os +#set error_log = 'output_log.txt' +touch '$error_log'; + +## ImageJ2 requires file extensions to be valid image data types. +#set source_out_suffix = '.' + str($source_out_datatype) +#set target_out_suffix = '.' + str($target_out_datatype) +#set source_image_sans_ext = $os.path.splitext($os.path.basename($source_image.file_name))[0] +#set source_image_with_ext = '.'.join([$source_image_sans_ext, $source_image.ext]) +ln -s '$source_image.file_name' '$source_image_with_ext'; +#set target_image_sans_ext = $os.path.splitext($os.path.basename($target_image.file_name))[0] +#set target_image_with_ext = '.'.join([$target_image_sans_ext, $target_image.ext]) +ln -s '$target_image.file_name' '$target_image_with_ext'; + +#set save_transformation = str($advanced_options_cond.advanced_options) == 'save_transformation' +#set mono = str($advanced_options_cond.advanced_options) == 'mono' +#set landmarks = str($advanced_options_cond.advanced_options) == 'landmarks' +#set affine = str($advanced_options_cond.advanced_options) == 'affine' + +#if str($align_with_mask_cond.align_with_mask) == 'yes': + #set source_mask_sans_ext = $os.path.splitext($os.path.basename($align_with_mask_cond.source_mask.file_name))[0] + #set source_mask_with_ext = '.'.join([$source_mask_sans_ext, $source_mask.ext]) + #set source_mask = $source_mask_with_ext + ln -s '$align_with_mask_cond.source_mask.file_name' '$source_mask_with_ext'; + #set target_mask_sans_ext = $os.path.splitext($os.path.basename($align_with_mask_cond.target_mask.file_name))[0] + #set target_mask_with_ext = '.'.join([$target_mask_sans_ext, $target_mask.ext]) + #set target_mask = $target_mask_with_ext + ln -s '$align_with_mask_cond.target_mask.file_name' '$target_mask_with_ext'; +#else: + #set source_mask = 'NULL' + #set target_mask = 'NULL' +#end if + +#if not $mono: + #set tmp_target_out = 'tmp_target_out' + $target_out_suffix + touch '$tmp_target_out'; + + ## bUnwarpJ automatically names the transformation files based + ## on the names of the source and target image file names. + #set tmp_target_out_transf_name_sans_ext = $os.path.splitext($target_out.file_name)[0] + #set tmp_target_out_transf_name = $tmp_target_out_transf_name_sans_ext + '_transf.txt' + touch '$tmp_target_out_transf_name'; +#end if +#set tmp_source_out = 'tmp_source_out' + $source_out_suffix +touch '$tmp_source_out'; + +## bUnwarpJ automatically names the transformation files based +## on the names of the source and target image file names. +#set tmp_source_out_transf_name_sans_ext = $os.path.splitext($source_out.file_name)[0] +#set tmp_source_out_transf_name = $tmp_source_out_transf_name_sans_ext + '_transf.txt' +touch '$tmp_source_out_transf_name'; + +## Align the two images using bUnwarpJ. +bunwarpj -align +'$target_image_with_ext' +'$target_mask' +'$source_image_with_ext' +'$source_mask' +$min_scale_def +$max_scale_def +$max_subsamp_fact +$divergence_weight +$curl_weight +$image_weight +$consistency_weight +'$source_out' +#if not $mono: + '$target_out' +#end if +#if $landmarks: + '-landmarks' + $advanced_options_cond.landmarks_weight + '$landmarks_file' +#end if +#if $affine: + '-affine' + '$advanced_options_cond.target_affine_file' + '$advanced_options_cond.source_affine_file' +#end if +#if $mono: + '-mono' +#end if +#if $save_transformation: + '-save_transformation' +#end if +&>'$error_log'; +#if $save_transformation: + mv '$tmp_source_out_transf_name' '$source_trans_out'; + mv '$tmp_target_out_transf_name' '$target_trans_out'; +#end if +if [[ $? -ne 0 ]]; then + cat '$error_log' >&2; +fi +]]></command> <inputs> - <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="target_image" type="data" label="Target image"/> - <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="source_image" type="data" label="Source image"/> + <expand macro="param_target_image"/> + <expand macro="param_source_image"/> <conditional name="align_with_mask_cond"> <param name="align_with_mask" type="select" label="Align with masks?" help="Source and target mask can be any image format."> - <option value="no" selected="True">No</option> + <option value="no" selected="true">No</option> <option value="yes">Yes</option> </param> - <when value="no" /> + <when value="no"/> <when value="yes"> - <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="target_mask" type="data" label="Target mask"/> - <param format="bmp,eps,gif,jpg,pcx,pgm,png,psd,tiff" name="source_mask" type="data" label="Source mask"/> + <expand macro="param_target_mask"/> + <expand macro="param_source_mask"/> </when> </conditional> <param name="min_scale_def" type="select" label="Initial deformation"> - <option value="0" selected="True">Very Coarse</option> + <option value="0" selected="true">Very Coarse</option> <option value="1">Coarse</option> <option value="2">Fine</option> <option value="3">Very Fine</option> @@ -69,7 +122,7 @@ <param name="max_scale_def" type="select" label="Final deformation"> <option value="0">Very Coarse</option> <option value="1">Coarse</option> - <option value="2" selected="True">Fine</option> + <option value="2" selected="true">Fine</option> <option value="3">Very Fine</option> </param> <param name="max_subsamp_fact" type="integer" value="0" min="0" label="Image sub-sample factor" help="Power of 2: [0, 1, 2 .. 7]"/> @@ -78,10 +131,10 @@ <param name="image_weight" type="float" label="Weight of the image term" value="1.0" help="Value is a floating point number"/> <param name="consistency_weight" type="float" label="Weight of the deformation consistency" value="10.0" help="Value is a floating point number"/> <param name="target_out_datatype" type="select" label="Save registered target image as format"> - <expand macro="image_datatypes" /> + <expand macro="image_datatypes"/> </param> <param name="source_out_datatype" type="select" label="Save registered source image as format"> - <expand macro="image_datatypes" /> + <expand macro="image_datatypes"/> </param> <!-- The following additional options can be added to the advanced_options select @@ -105,10 +158,10 @@ --> <conditional name="advanced_options_cond"> <param name="advanced_options" type="select" label="Advanced options" help="These are mutually exclusive for each execution"> - <option value="none" selected="True">None</option> + <option value="none" selected="true">None</option> <option value="save_transformation">Save calculated transformations</option> </param> - <when value="none" /> + <when value="none"/> <!-- <when value="landmarks"> <param name="landmarks_weight" type="float" label="Landmark weight" value="0.0" help="Value is a floating point number"/> @@ -124,81 +177,55 @@ </conditional> </inputs> <outputs> - <data name="source_out" format="png" label="${tool.name} on ${on_string}: Registered source image"> + <data name="source_out" format="png" label="${tool.name} (registered source) ${on_string}"> <actions> <action type="format"> - <option type="from_param" name="source_out_datatype" /> + <option type="from_param" name="source_out_datatype"/> </action> </actions> </data> - <data name="target_out" format="png" label="${tool.name} on ${on_string}: Registered target image"> + <data name="target_out" format="png" label="${tool.name} (registered target) ${on_string}"> <filter>advanced_options_cond['advanced_options'] != "mono"</filter> <actions> <action type="format"> - <option type="from_param" name="target_out_datatype" /> + <option type="from_param" name="target_out_datatype"/> </action> </actions> </data> - <data format="txt" name="source_trans_out" label="${tool.name} on ${on_string}: Direct source transformation matrix"> + <data format="txt" name="source_trans_out" label="${tool.name} (source transf matrix) ${on_string}"> <filter>advanced_options_cond['advanced_options'] == "save_transformation"</filter> </data> - <data format="txt" name="target_trans_out" label="${tool.name} on ${on_string}: Inverse target transformation matrix"> + <data format="txt" name="target_trans_out" label="${tool.name} (target transf matrix) ${on_string}"> <filter>advanced_options_cond['advanced_options'] == "save_transformation"</filter> </data> </outputs> <tests> <test> <!-- Align two images without landmarks or mask and not saving transformation matrices --> - <param name="target_image" value="dotblot.jpg" /> - <param name="source_image" value="blobs.gif" /> - <param name="min_scale_def" value="0" /> - <param name="max_scale_def" value="2" /> - <param name="max_subsamp_fact" value="1" /> - <param name="divergence_weight" value="0.0" /> - <param name="curl_weight" value="0.0" /> - <param name="image_weight" value="1.0" /> - <param name="consistency_weight" value="10.0" /> - <param name="target_out_datatype" value="png" /> - <param name="source_out_datatype" value="png" /> - <output name="source_out" file="registered_source1.png" compare="sim_size" /> - <output name="target_out" file="registered_target1.png" compare="sim_size" /> + <expand macro="test_target_source_images"/> + <param name="max_subsamp_fact" value="1"/> + <output name="source_out" file="registered_source1.png" compare="sim_size"/> + <output name="target_out" file="registered_target1.png" compare="sim_size"/> </test> <test> <!-- Align two images without landmarks or mask, but saving transformation matrices --> - <param name="target_image" value="dotblot.jpg" /> - <param name="source_image" value="blobs.gif" /> - <param name="min_scale_def" value="0" /> - <param name="max_scale_def" value="2" /> - <param name="max_subsamp_fact" value="1" /> - <param name="divergence_weight" value="0.0" /> - <param name="curl_weight" value="0.0" /> - <param name="image_weight" value="1.0" /> - <param name="consistency_weight" value="10.0" /> - <param name="target_out_datatype" value="png" /> - <param name="source_out_datatype" value="png" /> - <param name="advanced_options" value="save_transformation" /> - <output name="source_out" file="registered_source1.png" compare="sim_size" /> - <output name="target_out" file="registered_target1.png" compare="sim_size" /> - <output name="source_trans_out" file="source_elastic_transformation.txt" /> - <output name="target_trans_out" file="target_elastic_transformation.txt" /> + <expand macro="test_target_source_images"/> + <param name="max_subsamp_fact" value="1"/> + <param name="advanced_options" value="save_transformation"/> + <output name="source_out" file="registered_source1.png" compare="sim_size"/> + <output name="target_out" file="registered_target1.png" compare="sim_size"/> + <output name="source_trans_out" file="source_elastic_transformation_out.txt" compare="contains"/> + <output name="target_trans_out" file="target_elastic_transformation_out.txt" compare="contains"/> </test> <test> <!-- Align two images without landmarks but with mask, not saving transformation matrices --> - <param name="target_image" value="dotblot.jpg" /> - <param name="source_image" value="blobs.gif" /> - <param name="target_mask" value="mask_white.png" /> - <param name="source_mask" value="mask_ramp.gif" /> - <param name="min_scale_def" value="0" /> - <param name="max_scale_def" value="2" /> - <param name="max_subsamp_fact" value="1" /> - <param name="divergence_weight" value="0.0" /> - <param name="curl_weight" value="0.0" /> - <param name="image_weight" value="1.0" /> - <param name="consistency_weight" value="10.0" /> - <param name="target_out_datatype" value="png" /> - <param name="source_out_datatype" value="png" /> - <output name="source_out" file="registered_source2.png" compare="sim_size" /> - <output name="target_out" file="registered_target2.png" compare="sim_size" /> + <expand macro="test_target_source_images"/> + <param name="align_with_mask" value="yes"/> + <param name="target_mask" value="mask_white.png"/> + <param name="source_mask" value="mask_ramp.gif"/> + <param name="max_subsamp_fact" value="1"/> + <output name="source_out" file="registered_source2.png" compare="sim_size"/> + <output name="target_out" file="registered_target2.png" compare="sim_size"/> </test> </tests> <help> @@ -243,5 +270,5 @@ ]]> </help> - <expand macro="bunwarpj_citations" /> + <expand macro="bunwarpj_citations"/> </tool>