view gray_to_color.xml @ 3:bbf1ef17c01b draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit c3917e27eb1c1deeb381aa0dc8161c07699562fb"
author bgruening
date Mon, 11 May 2020 07:56:38 -0400
parents e5870c434f28
children ad271f78a87a
line wrap: on
line source

<tool id="cp_gray_to_color" name="GrayToColor" version="@CP_VERSION@">
    <description>take grayscale images and produces a color image from them</description>
    <macros>
        <import>macros.xml</import>
        <xml name="rgb">
            <param name="rgb_red" label="Enter the name of the image to be colored red" value="Leave this black" type="text"/>
            <param name="rgb_red_weight" label="Relative weight for the red image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />

            <param name="rgb_green" label="Enter the name of the image to be colored green" value="Leave this black" type="text"/>
            <param name="rgb_green_weight" label="Relative weight for the green image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />

            <param name="rgb_blue" label="Enter the name of the image to be colored blue" value="Leave this black" type="text"/>
            <param name="rgb_blue_weight" label="Relative weight for the blue image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />
        </xml>
        <xml name="cmyk">
            <param name="cmyk_cyan" label="Enter the name of the image to be colored cyan" value="Leave this black" type="text"/>
            <param name="cmyk_cyan_weight" label="Relative weight for the cyan image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />

            <param name="cmyk_magenta" label="Enter the name of the image to be colored magenta" value="Leave this black" type="text"/>
            <param name="rgb_green_weight" label="Relative weight for the green image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />

            <param name="cmyk_yellow" label="Enter the name of the image to be colored yellow" value="Leave this black" type="text"/>
            <param name="cmyk_yellow_weight" label="Relative weight for the yellow image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />

            <param name="cmyk_brightness" label="Enter the name of the image that determines brightness" value="Leave this black" type="text"/>
            <param name="cmyk_brightness_weight" label="Relative weight for the brightness image" optional="true" type="float" min="0.0" max="1.0" value="1.0" />
        </xml>
        <xml name="stack">
            <repeat name="rpt_image_name" title="another channel" min="1">
                <param name="image_name" type="text" label="Enter the image name">
                    <expand macro="text_validator" />
                </param>
            </repeat>
        </xml>
        <xml name="composite">
            <repeat name="rpt_image_name" title="another channel" min="1">
                <param name="image_name" type="text" label="Image name">
                    <expand macro="text_validator" />
                </param>
                <param name="color" type="color" label="Color" />
                <param name="weight" type="float" label="Weight" value="1.0" min="0.0" max="1.0"/>
            </repeat>
        </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 writegtc():
    _str = "\nGrayToColor:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:3|show_window:False|notes:\\x5B\\'Combine masks nuclei + nucleoli with colors\\'\\x5D|batch_state:array(\\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count

    color_scheme = params['con_color_scheme']['color_scheme']

    rgb_blue = params['con_color_scheme']['rgb_blue'] if 'rgb_blue' in params['con_color_scheme'] else 'Leave this black'
    rgb_blue_weight = 1.0 if params['con_color_scheme']['rgb_blue_weight'] == "" else params['con_color_scheme']['rgb_blue_weight']

    rgb_green = params['con_color_scheme']['rgb_green'] if 'rgb_green' in params['con_color_scheme'] else 'Leave this black'
    rgb_green_weight = 1.0 if params['con_color_scheme']['rgb_green_weight'] == "" else params['con_color_scheme']['rgb_green_weight']

    rgb_red = params['con_color_scheme']['rgb_red'] if 'rgb_red' in params['con_color_scheme'] else 'Leave this black'
    rgb_red_weight = 1.0 if params['con_color_scheme']['rgb_red_weight'] == "" else params['con_color_scheme']['rgb_red_weight']

    name_output_image = params['name_output_image']

    cmyk_cyan = params['con_color_scheme']['cmyk_cyan'] if 'cmyk_cyan' in params['con_color_scheme'] else 'Leave this black'

    if 'cmyk_cyan_weight' in params['con_color_scheme']:
        if params['con_color_scheme']['cmyk_cyan_weight'] == "":
            cmyk_cyan_weight = 1.0
        else:
            cmyk_cyan_weight = params['con_color_scheme']['cmyk_cyan_weight']
    else:
        cmyk_cyan_weight = 1.0

    cmyk_magenta = params['con_color_scheme']['cmyk_magenta'] if 'cmyk_magenta' in params['con_color_scheme'] else 'Leave this black'

    if 'cmyk_magenta_weight' in params['con_color_scheme']:
        if params['con_color_scheme']['cmyk_magenta_weight'] == "":
            cmyk_magenta_weight = 1.0
        else:
            cmyk_magenta_weight = params['con_color_scheme']['cmyk_cyan_weight']
    else:
        cmyk_magenta_weight = 1.0

    cmyk_yellow = params['con_color_scheme']['cmyk_yellow'] if 'cmyk_yellow' in params['con_color_scheme'] else 'Leave this black'

    if 'cmyk_yellow_weight' in params['con_color_scheme']:
        if params['con_color_scheme']['cmyk_yellow_weight'] == "":
            cmyk_yellow_weight = 1.0
        else:
            cmyk_yellow_weight = params['con_color_scheme']['cmyk_yellow_weight']
    else:
        cmyk_yellow_weight = 1.0

    cmyk_brightness = params['con_color_scheme']['cmyk_brightness'] if 'cmyk_brightness' in params['con_color_scheme'] else 'Leave this black'

    if 'cmyk_brightness_weight' in params['con_color_scheme']:
        if params['con_color_scheme']['cmyk_brightness_weight'] == "":
            cmyk_brightness_weight = 1.0
        else:
            cmyk_brightness_weight = params['con_color_scheme']['cmyk_brightness_weight']
    else:
        cmyk_brightness_weight = 1.0

    count = len(params['con_color_scheme']['rpt_image_name']) if 'rpt_image_name' in params['con_color_scheme'] else 1

    _str += FOURSPACES + "Select a color scheme:%s\n" % color_scheme

    _str += FOURSPACES + "Select the image to be colored red:%s\n" % rgb_red
    _str += FOURSPACES + "Select the image to be colored green:%s\n" % rgb_green
    _str += FOURSPACES + "Select the image to be colored blue:%s\n" % rgb_blue
    _str += FOURSPACES + "Name the output image:%s\n" % name_output_image
    _str += FOURSPACES + "Relative weight for the red image:%.1f\n" % rgb_red_weight
    _str += FOURSPACES + "Relative weight for the green image:%.1f\n" % rgb_green_weight
    _str += FOURSPACES + "Relative weight for the blue image:%.1f\n" % rgb_blue_weight

    _str += FOURSPACES + "Select the image to be colored cyan:%s\n" % cmyk_cyan
    _str += FOURSPACES + "Select the image to be colored magenta:%s\n" % cmyk_magenta
    _str += FOURSPACES + "Select the image to be colored yellow:%s\n" % cmyk_yellow
    _str += FOURSPACES + "Select the image that determines brightness:%s\n" % cmyk_brightness
    _str += FOURSPACES + "Relative weight for the cyan image:%.1f\n" % cmyk_cyan_weight
    _str += FOURSPACES + "Relative weight for the magenta image:%.1f\n" % cmyk_magenta_weight
    _str += FOURSPACES + "Relative weight for the yellow image:%.1f\n" % cmyk_yellow_weight
    _str += FOURSPACES + "Relative weight for the brightness image:%.1f\n" % cmyk_brightness_weight

    _str += FOURSPACES + "Hidden:%d\n" % count

    if 'rpt_image_name' in params['con_color_scheme']:
        for i in params['con_color_scheme']['rpt_image_name']:
            image_name = params['con_color_scheme']['rpt_image_name']['image_name']
            if 'color' in params['con_color_scheme']['rpt_image_name']:
                color = params['con_color_scheme']['rpt_image_name']['color']
            else:
                color = '#FF0000'

            if 'weight' in params['con_color_scheme']['rpt_image_name']:
                weight = params['con_color_scheme']['rpt_image_name']['weight']
            else:
                weight = 1.0
    else:
        image_name = 'None'
        color = '#FF0000'
        weight = 1.0

    _str += FOURSPACES + "Image name:%s\n" % image_name
    _str += FOURSPACES + "Color:%s\n" % color
    _str += FOURSPACES + "Weight:%s\n" % weight

    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(writegtc())

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

    <inputs>
        <expand macro="input_pipeline_param" />
        <param name="name_output_image" label="Enter the name of the resulting image" value="ColorImage" type="text">

            <expand macro="text_validator" />
        </param>
        <conditional name="con_color_scheme">
            <param name="color_scheme" label="Select a color scheme" type="select">
                <help>
                    <![CDATA[
                        This tool can use one of two color schemes to combine images:
                        <br> - RGB: Each input image determines the intensity of one of the color channels: red, green, and blue.
                        <br> - CMYK: Three of the input images are combined to determine the colors (cyan, magenta, and yellow) and a fourth is used only for brightness. The cyan image adds equally to the green and blue intensities. The magenta image adds equally to the red and blue intensities. The yellow image adds equally to the red and green intensities.
                        <br> - Stack: The channels are stacked in the order listed, from top to bottom. An arbitrary number of channels is allowed.
                        For example, you could create a 5-channel image by providing 5 grayscale images. The first grayscale image you provide will fill the first channel, the second grayscale image you provide will fill the second channel, and so on.
                        <br> - Composite: A color is assigned to each grayscale image. Each grayscale image is converted to color by multiplying the intensity by the color and the resulting color images are added together. An arbitrary number of channels can be composited into a single color image.
                        ]]>
                </help>
                <option value="RGB">RGB</option>
                <option value="CMYK">CMYK</option>
                <option value="Stack">Stack</option>
                <option value="Composite">Composite</option>
            </param>
            <when value="RGB">
                <expand macro="rgb" />
            </when>
            <when value="CMYK">
                <expand macro="cmyk" />
            </when>
            <when value="Stack">
                <expand macro="stack" />
            </when>
            <when value="Composite">
                <expand macro="composite" />
            </when>
        </conditional>
    </inputs>

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

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />
            <param name="name_output_image" value="CombinedMask" />
            <conditional name="con_color_scheme">
                <param name="color_scheme" value="RGB" />
                <param name="rgb_red" value="MaskNucleoli" />
                <param name="rgb_red_weight" value="0.8" />
                <param name="rgb_green" value="Leave this black" />
                <param name="rgb_blue" value="MaskNuclei" />
                <param name="rgb_blue_weight" value="0.5" />
            </conditional>
            <expand macro="test_out_file" file="gray_to_color.cppipe" />
        </test>
    </tests>

    <help>
        <![CDATA[
            .. class:: infomark

            **What it does**

            This tool takes grayscale images as input and assigns them to colors in a red, green, blue (RGB) image or a cyan, magenta, yellow, black (CMYK) image. Each color’s brightness can be adjusted independently by using relative weights.

            @COMMON_HELP@
            ]]>
    </help>

    <expand macro="citations" />

</tool>