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