view display_data_on_image.xml @ 5:c79d4121f364 draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 7d7a519c3a2cc612d38695b335d0f6c75a099de3"
author bgruening
date Fri, 26 Feb 2021 13:46:16 +0000
parents 55a3dd321295
children
line wrap: on
line source

<tool id="cp_display_data_on_image" name="DisplayDataOnImage" version="@CP_VERSION@+galaxy@VERSION_SUFFIX@">
    <description>produce an image with data on top of identified objects</description>
    <macros>
        <import>macros.xml</import>
        <token name="@VERSION_SUFFIX@">0</token>
        <xml name="display_object">
            <param name="select_input_obj" label="Enter the name of the input objects" type="text" help="Enter the name of the objects identified by some other tool used upstream in the workflow (such as IdentifyPrimaryObjects or IdentifySecondaryObjects)." />

            <conditional name="con_obj_measurement_category">
                <param name="measurement_category" label="Measurement category" type="select" help="The measurement will be made by some other tool used upstream in the workflow on either the whole image or on the objects you selected.">

                    <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.cppipe", "w") as f:
        f.writelines(lines)
        f.write(writemi())

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

    <inputs>
        <expand macro="input_pipeline_param" />
        <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" help="Usually, you will want to see the image context for the measurements, but it may be useful to save just the overlay of the text measurements and composite the overlay image and the original image later.">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>

        <param name="image_to_display_measurements" label="Enter the name of 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" help="If you choose Text, DisplayDataOnImage will display the numeric value on top of each object. If you choose Color, DisplayDataOnImage will convert the image to grayscale, if necessary, and display the portion of the image within each object using a hue that indicates the measurement value relative to the other objects in the set using the default color map.">
                <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="5">
                </param>
                <param name="number_of_decimals" type="integer" label="Number of decimals" value="2" min="0" max="10"/>
                <param name="annotation_offset" type="integer" label="Annotation offset (in pixels)" value="0" min="0" help="Normally, the text is placed at the object (or image) center, which can obscure relevant features of the object. This setting adds a specified offset to the text, in a random direction." />
            </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>
                            <![CDATA[
                                This tool 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.
                                <br>- Use this image's measurement range: Use the full range of colors to get the maximum contrast within the image.
                                <br>- Manual: Manually set the upper and lower bounds so that images with different maxima and minima can be compared by a uniform color mapping.
                                ]]>
                        </help>
                        <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">
            <help>
                <![CDATA[
                    This setting controls the level of annotation on the image:
                    <br>- Image: Saves the image with the overlaid measurement annotations.
                    <br>- Figure: Adds a title and other decorations.
                    <br>- Axes: Adds axes with tick marks and image coordinates.
                    ]]>
            </help>
            <option value="Image">Image</option>
            <option value="Figure">Figure</option>
            <option value="Axes">Axes</option>
        </param>
    </inputs>

    <outputs>
        <expand macro="output_pipeline_param" />
    </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.cppipe" />
        </test>
    </tests>
    <help>
        <![CDATA[
            .. class:: infomark

            **What it does**

            This module displays either a single image measurement on an image of your choosing, or one object measurement per object on top of every object in an image. The display itself is an image which you can save to a file using *SaveImages*.

            @COMMON_HELP@
            ]]>
    </help>
    <expand macro="citations" />
</tool>