Mercurial > repos > bgruening > cp_gray_to_color
diff gray_to_color.xml @ 0:d37580e3f4d0 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 6d73056a625002d0275b5a9a90a9fae329ce47f1"
author | bgruening |
---|---|
date | Thu, 26 Mar 2020 17:46:36 -0400 |
parents | |
children | e5870c434f28 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gray_to_color.xml Thu Mar 26 17:46:36 2020 -0400 @@ -0,0 +1,252 @@ +<tool id="cp_gray_to_color" name="GrayToColor" version="@CP_VERSION@"> + <description>takes grayscale images and produces a color image from them</description> + <macros> + <import>macros.xml</import> + <xml name="rgb"> + <param name="rgb_red" label="Select 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" value="0.8"/> + + <param name="rgb_green" label="Select 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" value="1.0" /> + + <param name="rgb_blue" label="Select 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" value="0.5"/> + + <param name="name_output_image" label="Name the output image" value="ColorImage" type="text"/> + </xml> + <xml name="cmyk"> + <param name="cmyk_cyan" label="Select 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" value="0.5"/> + + <param name="cmyk_magenta" label="Select 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" value="0.0"/> + + <param name="cmyk_yellow" label="Select 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" value="0.0"/> + + <param name="cmyk_brightness" label="Select 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" value="0.5"/> + + <param name="name_output_image" label="Name the output image" value="ColorImage" type="text"> + <expand macro="text_validator" /> + </param> + + </xml> + <xml name="stack"> + <param name="name_output_image" label="Name the output image" value="ColorImage" type="text"> + <expand macro="text_validator" /> + </param> + <repeat name="rpt_image_name" title="Add another channel"> + <param name="image_name" type="text" label="Image name" > + <expand macro="text_validator" /> + </param> + </repeat> + </xml> + <xml name="composite"> + <param name="name_output_image" label="Name the output image" value="ColorImage" type="text"> + <expand macro="text_validator" /> + </param> + <repeat name="rpt_image_name" title="Add another channel"> + <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="0.8" 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['con_color_scheme']['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", "w") as f: + f.writelines(lines) + f.write(writegtc()) + +f.close() + </configfile> + </configfiles> + + <inputs> + <expand macro="input_pipeline_macro" /> + <conditional name="con_color_scheme"> + <param name="color_scheme" label="Select a color scheme" type="select"> + <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_macro" /> + </outputs> + + <tests> + <test> + <expand macro="test_input_pipeline_param" /> + <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" /> + <param name="name_output_image" value="CombinedMask" /> + </conditional> + <expand macro="test_out_file" file="gray_to_color.txt" /> + </test> + </tests> + + <expand macro="help" module="GrayToColor" /> + <expand macro="citations" /> + +</tool>