comparison overlay_outlines.py @ 6:667a513e67e4 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author bgruening
date Sun, 05 Nov 2023 09:24:38 +0000
parents 3a05117669cf
children
comparison
equal deleted inserted replaced
5:b178453ea8d1 6:667a513e67e4
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import argparse 3 import argparse
4 import json 4 import json
5 5
6 from cp_common_functions import get_json_value 6 from cp_common_functions import (get_json_value,
7 from cp_common_functions import get_pipeline_lines 7 get_pipeline_lines,
8 from cp_common_functions import get_total_number_of_modules 8 get_total_number_of_modules,
9 from cp_common_functions import INDENTATION 9 INDENTATION, update_module_count,
10 from cp_common_functions import update_module_count 10 write_pipeline)
11 from cp_common_functions import write_pipeline
12 11
13 MODULE_NAME = "OverlayOutlines" 12 MODULE_NAME = "OverlayOutlines"
14 OUTPUT_FILENAME = "output.cppipe" 13 OUTPUT_FILENAME = "output.cppipe"
15 14
16 15
17 def build_ctg_header(module_name, module_number): 16 def build_ctg_header(module_name, module_number):
18 """Creates the first line of a module given the name and module number""" 17 """Creates the first line of a module given the name and module number"""
19 result = "|".join([f"{module_name}:[module_num:{module_number}", 18 result = "|".join(
20 "svn_version:\\'Unknown\\'", 19 [
21 "variable_revision_number:4", 20 f"{module_name}:[module_num:{module_number}",
22 "show_window:True", 21 "svn_version:\\'Unknown\\'",
23 "notes:\\x5B\\'Overlay the embryo outlines on the grayscale image.\\'\\x5D", 22 "variable_revision_number:4",
24 "batch_state:array(\\x5B\\x5D, dtype=uint8)", 23 "show_window:True",
25 "enabled:True", 24 "notes:\\x5B\\'Overlay the embryo outlines on the grayscale image.\\'\\x5D",
26 "wants_pause:False]\n"]) 25 "batch_state:array(\\x5B\\x5D, dtype=uint8)",
26 "enabled:True",
27 "wants_pause:False]\n",
28 ]
29 )
27 return result 30 return result
28 31
29 32
30 def build_main_block(input_params): 33 def build_main_block(input_params):
31 result = f"{INDENTATION}Display outlines on a blank image?:{get_json_value(input_params,'con_blank_img.blank_img')}\n" 34 result = f"{INDENTATION}Display outlines on a blank image?:{get_json_value(input_params,'con_blank_img.blank_img')}\n"
32 35
33 on_blank = get_json_value(input_params, 'con_blank_img.blank_img') 36 on_blank = get_json_value(input_params, "con_blank_img.blank_img")
34 # defaults 37 # defaults
35 img_to_display = "None" 38 img_to_display = "None"
36 display_mode = get_json_value(input_params, 'con_blank_img.con_display_mode.display_mode') 39 display_mode = get_json_value(
40 input_params, "con_blank_img.con_display_mode.display_mode"
41 )
37 method_brightness = "Max of image" 42 method_brightness = "Max of image"
38 howto = get_json_value(input_params, 'howto_outline') 43 howto = get_json_value(input_params, "howto_outline")
39 outline_color = "#FF0000" 44 outline_color = "#FF0000"
40 obj_to_display = "None" 45 obj_to_display = "None"
41 46
42 name_output_img = get_json_value(input_params, 'name_output_image') 47 name_output_img = get_json_value(input_params, "name_output_image")
43 48
44 if on_blank == "No": 49 if on_blank == "No":
45 img_to_display = get_json_value(input_params, 'con_blank_img.image_to_outline') 50 img_to_display = get_json_value(input_params, "con_blank_img.image_to_outline")
46 51
47 result += INDENTATION.join( 52 result += INDENTATION.join(
48 [f"{INDENTATION}Select image on which to display outlines:{img_to_display}\n", 53 [
49 f"Name the output image:{name_output_img}\n", 54 f"{INDENTATION}Select image on which to display outlines:{img_to_display}\n",
50 f"Outline display mode:{display_mode}\n" 55 f"Name the output image:{name_output_img}\n",
51 ]) 56 f"Outline display mode:{display_mode}\n",
57 ]
58 )
52 59
53 if on_blank == "No" and display_mode == "Grayscale": 60 if on_blank == "No" and display_mode == "Grayscale":
54 method_brightness = get_json_value(input_params, 'con_blank_img.con_display_mode.method_brightness') 61 method_brightness = get_json_value(
62 input_params, "con_blank_img.con_display_mode.method_brightness"
63 )
55 64
56 result += INDENTATION.join( 65 result += INDENTATION.join(
57 [f"{INDENTATION}Select method to determine brightness of outlines:{method_brightness}\n", 66 [
58 f"How to outline:{howto}\n" 67 f"{INDENTATION}Select method to determine brightness of outlines:{method_brightness}\n",
59 ]) 68 f"How to outline:{howto}\n",
69 ]
70 )
60 71
61 obj_outline_str = "" 72 obj_outline_str = ""
62 73
63 if display_mode == "Color": 74 if display_mode == "Color":
64 for obj in input_params['con_blank_img']['con_display_mode']['rpt_obj_to_display']: 75 for obj in input_params["con_blank_img"]["con_display_mode"][
65 outline_color = get_json_value(obj, 'outline_color') 76 "rpt_obj_to_display"
66 obj_to_display = get_json_value(obj, 'obj_to_display') 77 ]:
78 outline_color = get_json_value(obj, "outline_color")
79 obj_to_display = get_json_value(obj, "obj_to_display")
67 obj_outline_str += INDENTATION.join( 80 obj_outline_str += INDENTATION.join(
68 [f"{INDENTATION}Select outline color:{outline_color}\n", 81 [
69 f"Select objects to display:{obj_to_display}\n" 82 f"{INDENTATION}Select outline color:{outline_color}\n",
70 ]) 83 f"Select objects to display:{obj_to_display}\n",
84 ]
85 )
71 else: # grayscale 86 else: # grayscale
72 for obj in input_params['con_blank_img']['con_display_mode']['rpt_obj_to_display']: 87 for obj in input_params["con_blank_img"]["con_display_mode"][
73 obj_to_display = get_json_value(obj, 'obj_to_display') 88 "rpt_obj_to_display"
89 ]:
90 obj_to_display = get_json_value(obj, "obj_to_display")
74 obj_outline_str += INDENTATION.join( 91 obj_outline_str += INDENTATION.join(
75 [f"{INDENTATION}Select outline color:{outline_color}\n", 92 [
76 f"Select objects to display:{obj_to_display}\n" 93 f"{INDENTATION}Select outline color:{outline_color}\n",
77 ]) 94 f"Select objects to display:{obj_to_display}\n",
95 ]
96 )
78 obj_outline_str = obj_outline_str.rstrip("\n") 97 obj_outline_str = obj_outline_str.rstrip("\n")
79 result += f"{obj_outline_str}" 98 result += f"{obj_outline_str}"
80 99
81 return result 100 return result
82 101
83 102
84 if __name__ == "__main__": 103 if __name__ == "__main__":
85 parser = argparse.ArgumentParser() 104 parser = argparse.ArgumentParser()
86 parser.add_argument( 105 parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline")
87 '-p', '--pipeline', 106 parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy")
88 help='CellProfiler pipeline'
89 )
90 parser.add_argument(
91 '-i', '--inputs',
92 help='JSON inputs from Galaxy'
93 )
94 args = parser.parse_args() 107 args = parser.parse_args()
95 108
96 pipeline_lines = get_pipeline_lines(args.pipeline) 109 pipeline_lines = get_pipeline_lines(args.pipeline)
97 inputs_galaxy = json.load(open(args.inputs, "r")) 110 inputs_galaxy = json.load(open(args.inputs, "r"))
98 111