view display_data_on_image.xml @ 0:c49a557b4e3e draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 6d73056a625002d0275b5a9a90a9fae329ce47f1"
author bgruening
date Thu, 26 Mar 2020 17:45:44 -0400
parents
children 7c70e5268acd
line wrap: on
line source

<tool id="cp_display_data_on_image" name="DisplayDataOnImage" version="@CP_VERSION@">
    <description>produces an image with measured data on top of identified objects</description>
    <macros>
        <import>macros.xml</import>
        <xml name="display_object">
            <param name="select_input_obj" label="Select the input objects" type="text" />
            <conditional name="con_obj_measurement_category">
                <param name="measurement_category" label="Measurement category" type="select">
                    <option value="Location">Location</option>
                    <option value="Number">Number</option>
                </param>
                <when value="Number">
                    <param name="measurement" label="Measurement" type="select">
                        <option value="Object_Number">Object_Number</option>
                    </param>
                </when>
                <when value="Location">
                    <param name="obj_measurement" label="Measurement" type="select">
                        <option value="Center_X">Center_X</option>
                        <option value="Center_Y">Center_Y</option>
                        <option value="Center_Z">Center_Z</option>
                    </param>
                </when>
            </conditional>
        </xml>
        <xml name="display_image">
            <conditional name="con_obj_measurement_category">
                <param name="measurement_category" label="Measurement category" type="select">
                    <option value="Count">Count</option>
                    <option value="FileName">FileName</option>
                    <option value="Frame">Frame</option>
                    <option value="Height">Height</option>
                    <option value="MD5Digest">MD5Digest</option>
                    <option value="Metadata">Metadata</option>
                    <option value="PathName">PathName</option>
                    <option value="Scaling">Scaling</option>
                    <option value="Series">Series</option>
                    <option value="PathName">PathName</option>
                    <option value="Threshold">Threshold</option>
                    <option value="URL">URL</option>
                    <option value="Width">Width</option>
                </param>
                <when value="Count">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="FileName">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Frame">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Height">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="MD5Digest">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Metadata">
                    <param name="measurement" label="Measurement" type="select">
                        <option value="FileLocation">FileLocation</option>
                        <option value="Frame">Frame</option>
                        <option value="ImageId">ImageId</option>
                        <option value="Screen">Screen</option>
                        <option value="Series">Series</option>
                    </param>
                </when>                                        
                <when value="PathName">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Scaling">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Series">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="PathName">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Threshold">
                    <param name="measurement" label="Measurement" type="text" />
                    <param name="image_thresh_objects" label="Objects" type="text"/>
                </when>
                <when value="URL">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
                <when value="Width">
                    <param name="measurement" label="Measurement" type="text" />
                </when>
            </conditional>
        </xml>
    </macros>
    
    <expand macro="py_requirements"/>
    <expand macro="cmd_modules" /> 

    <configfiles>
        <inputs name="inputs" />
        <configfile name="script_file">
import json
import sys
import os

FOURSPACES=@SPACES@

input_json_path = sys.argv[1]
input_pipeline= sys.argv[2]

params = json.load(open(input_json_path, "r"))

def writemi():
    _str = "\nDisplayDataOnImage:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:6|show_window:False|notes:\\x5B\\'Add nuclei id as label\\'\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count

    obj_img_params = params['con_display_obj_image']
    display_mode_params = params['con_display_mode']

    _str += FOURSPACES + "Display object or image measurements?:%s\n" % obj_img_params['display_obj_image']

    input_obj = obj_img_params['select_input_obj'] if obj_img_params['display_obj_image'] == "Object" else "None"

    _str += FOURSPACES + "Select the input objects:%s\n" % input_obj
    _str += FOURSPACES + "Measurement to display:%s_%s\n" % (obj_img_params['con_obj_measurement_category'][
        'measurement_category'],obj_img_params['con_obj_measurement_category']['measurement'])
    _str += FOURSPACES + "Select the image on which to display the measurements:%s\n" %  params[
        'image_to_display_measurements']

    display_mode = display_mode_params['display_mode']

    if display_mode == "Text":
        text_color = display_mode_params['text_color']
        font_size = display_mode_params['font_size']
        no_of_decimals = display_mode_params['number_of_decimals']
        annotation_offset = display_mode_params['annotation_offset']
        color_map = "Default"
        color_map_scale = "Use this image's measurement range"
        color_map_range = "0.0,1.0"
    else:
        text_color = "#ff0000"
        font_size = 11
        no_of_decimals = 0
        annotation_offset = 0
        color_map = display_mode_params['color_map']
        color_map_scale = display_mode_params['con_color_map_scale']['color_map_scale']
        if color_map_scale == "Manual":
            color_map_range ="%.1f,%.1f" % (display_mode_params['con_color_map_scale']['min_color_map_range'], display_mode_params['con_color_map_scale']['max_color_map_range'])
        else:
            color_map_range = "0.0,1.0"

    _str += FOURSPACES + "Text color:%s\n" % text_color
    _str += FOURSPACES + "Name the output image that has the measurements displayed:%s\n" % params['name_output_image']
    _str += FOURSPACES + "Font size (points):%d\n" % font_size
    _str += FOURSPACES + "Number of decimals:%d\n" % no_of_decimals
    _str += FOURSPACES + "Image elements to save:%s\n" % params['element_to_save']
    _str += FOURSPACES + "Annotation offset (in pixels):%d\n" % annotation_offset
    _str += FOURSPACES + "Display mode:%s\n" % display_mode
    _str += FOURSPACES + "Color map:%s\n" % color_map
    _str += FOURSPACES + "Display background image?:%s\n" % params['display_background_image']
    _str += FOURSPACES + "Color map scale:%s\n" % color_map_scale
    _str += FOURSPACES + "Color map range:%s\n" % color_map_range

    return _str


with open(input_pipeline) as fin:
    lines = fin.readlines()

    k, v = lines[4].strip().split(':')

    module_count = int(v)
    new_count = module_count + 1
    lines[4] = k + ":%d\n" % new_count

    with open("output", "w") as f:
        f.writelines(lines)
        f.write(writemi())

f.close()
        </configfile>
    </configfiles>

    <inputs>
        <expand macro="input_pipeline_macro" />
        <conditional name="con_display_obj_image">
            <param name="display_obj_image" type="select" label="Display object or image measurements?">
                <option value="Object">Object</option>
                <option value="Image">Image</option>
            </param>
            <when value="Object">
                <expand macro="display_object" />
            </when>
            <when value="Image">
                <expand macro="display_image" />
            </when>
        </conditional>

        <param name="display_background_image" label="Display background image?" type="select" display="radio">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>

        <param name="image_to_display_measurements" label="Select the image on which to display the measurements" type="text">
            <expand macro="text_validator" />
        </param>

        <conditional name="con_display_mode">
            <param name="display_mode" type="select" label="Display mode">
                <option value="Text">Text</option>
                <option value="Color">Color</option>
            </param>
            <when value="Text">
                <param name="text_color" type="color" label="Text color" />
                <param name="font_size" type="integer" label="Font size(points)" value="11" min="8">
                </param>
                <param name="number_of_decimals" type="integer" label="Number of decimals" value="0"/>
                <param name="annotation_offset" type="integer" label="Annotation offset (in pixels)" value="0" />
            </when>
            <when value="Color">
                <param name="color_map" label="Color map" type="select" help="DisplayDataOnImage assigns a color to each object’s measurement value from a colormap when in colormap-mode, mapping the value to a color along the colormap’s continuum. This mapping has implicit upper and lower bounds to its range which are the extremes of the colormap. This setting determines whether the extremes are the minimum and maximum ">
                    <option value="Default">Default</option>
                </param>
                <conditional name="con_color_map_scale">
                    <param name="color_map_scale" label="Color map scale" type="select" help="assigns a color to each object’s measurement value from a colormap when in colormap-mode, mapping the value to a color along the colormap’s continuum. This mapping has implicit upper and lower bounds to its range which are the extremes of the colormap. This setting determines whether the extremes are the minimum and maximum values of the measurement from among the objects in the current image or manually-entered extremes">
                        <option value="Use this image's measurement range">Use this image's measurement range</option>
                        <option value="Manual">Manual</option>
                        <sanitizer sanitize="false"/>
                    </param>        
                    <when value="Manual">
                        <param name="min_color_map_range" label="Min. color map range" type="float" help="This setting determines the lower bounds of the values for the color map" value="0.0" min="0.0" />
                        <param name="max_color_map_range" label="Max. color map range" type="float" help="This setting determines the upper bounds of the values for the color map" value="1.0" max="1.0" />
                    </when>
                    <when value="Use this image's measurement range" />
                </conditional>
            </when>
        </conditional>

        <param name="name_output_image" label="Name the output image that has the measurements displayed" type="text">
            <expand macro="text_validator" />
        </param>
        <param name="element_to_save" type="select" label="Image elements to save">
            <option value="Image">Image</option>
            <option value="Figure">Figure</option>
            <option value="Axes">Axes</option>
        </param>
    </inputs>

    <outputs>
        <expand macro="output_pipeline_macro" />
    </outputs>

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />
            <conditional name="con_display_obj_image">
                <param name="display_obj_image" value="Object" />
                <param name="select_input_obj" value="Nuclei" />
                <conditional name="con_obj_measurement_category">
                    <param name="measurement_category" value="Number" />
                    <param name="measurement" value="Object_Number" />
                </conditional>
            </conditional>
            <param name="display_background_image" value="Yes" />
            <param name="image_to_display_measurements" value="DNA" />
            <conditional name="con_display_mode">
                <param name="display_mode" value="Text" />
                <param name="text_color" value="#ff0000"/>
                <param name="font_size" value="11" />
                <param name="number_of_decimals" value="0" />
                <param name="annotation_offset" value="0" />
            </conditional>
            <param name="name_output_image" value="ImageDisplay" />
            <param name="element_to_save" value="Image" />

            <expand macro="test_out_file" file="display_data_on_image.txt" />
        </test>
    </tests>
    <expand macro="help" module="DisplayDataOnImage"/>
    <expand macro="citations" />
</tool>