Mercurial > repos > bgruening > cp_track_objects
comparison tile.py @ 0:644e5e32a83c draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
author | bgruening |
---|---|
date | Sat, 06 Feb 2021 10:03:00 +0000 |
parents | |
children | 1fd453cd757b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:644e5e32a83c |
---|---|
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 | |
14 MODULE_NAME = "Tile" | |
15 OUTPUT_FILENAME = "output.cppipe" | |
16 | |
17 | |
18 def build_header(module_name, module_number): | |
19 result = "|".join([f"{module_name}:[module_num:{module_number}", | |
20 "svn_version:\\'Unknown\\'", | |
21 "variable_revision_number:1", | |
22 "show_window:True", | |
23 "notes:\\x5B\\'Tile the original color image, the outlined image and the image of tracked labels together.\\'\\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 = INDENTATION.join([f"{INDENTATION}Select an input image:{get_json_value(input_params,'input_image')}\n", | |
32 f"Name the output image:{get_json_value(input_params,'output_image_name')}\n", | |
33 f"Tile assembly method:{get_json_value(input_params,'con_assembly_method.assembly_method')}\n" | |
34 ]) | |
35 | |
36 calc_rows = get_json_value(input_params, 'con_assembly_method.con_calc_no_row.calc_no_row') | |
37 no_of_rows = 8 | |
38 | |
39 calc_cols = get_json_value(input_params, 'con_assembly_method.con_calc_no_cols.calc_no_cols') | |
40 no_of_cols = 12 | |
41 | |
42 if calc_rows == "No": | |
43 no_of_rows = get_json_value(input_params, 'con_assembly_method.con_calc_no_row.no_of_row') | |
44 | |
45 if calc_cols == "No": | |
46 no_of_cols = get_json_value(input_params, 'con_assembly_method.con_calc_no_cols.no_of_cols') | |
47 | |
48 corner_to_begin = get_json_value(input_params, 'con_assembly_method.corner_to_begin') | |
49 direction_tiling = get_json_value(input_params, 'con_assembly_method.direction') | |
50 meander = get_json_value(input_params, 'con_assembly_method.meander_mode') | |
51 | |
52 assembly_method = get_json_value(input_params, 'con_assembly_method.assembly_method') | |
53 | |
54 result += INDENTATION.join( | |
55 [f"{INDENTATION}Final number of rows:{str(no_of_rows)}\n", | |
56 f"Final number of columns:{str(no_of_cols)}\n", | |
57 f"Image corner to begin tiling:{corner_to_begin}\n", | |
58 f"Direction to begin tiling:{direction_tiling}\n", | |
59 f"Use meander mode?:{meander}\n", | |
60 f"Automatically calculate number of rows?:{calc_rows}\n", | |
61 f"Automatically calculate number of columns?:{calc_cols}\n" | |
62 ]) | |
63 | |
64 if assembly_method == "Within cycles": | |
65 additionals = input_params['con_assembly_method']['rpt_additional_image'] | |
66 | |
67 for img in additionals: | |
68 result += INDENTATION.join( | |
69 [f"{INDENTATION}Select an additional image to tile:{get_json_value(img, 'additional_img')}\n" | |
70 ]) | |
71 | |
72 return result | |
73 | |
74 | |
75 if __name__ == "__main__": | |
76 parser = argparse.ArgumentParser() | |
77 parser.add_argument( | |
78 '-p', '--pipeline', | |
79 help='CellProfiler pipeline' | |
80 ) | |
81 parser.add_argument( | |
82 '-i', '--inputs', | |
83 help='JSON inputs from Galaxy' | |
84 ) | |
85 args = parser.parse_args() | |
86 | |
87 pipeline_lines = get_pipeline_lines(args.pipeline) | |
88 inputs_galaxy = json.load(open(args.inputs, "r")) | |
89 | |
90 current_module_num = get_total_number_of_modules(pipeline_lines) | |
91 current_module_num += 1 | |
92 pipeline_lines = update_module_count(pipeline_lines, current_module_num) | |
93 | |
94 header_block = build_header(MODULE_NAME, current_module_num) | |
95 main_block = build_main_block(inputs_galaxy) | |
96 | |
97 module_pipeline = f"\n{header_block}{main_block}\n" | |
98 pipeline_lines.append(module_pipeline) | |
99 | |
100 write_pipeline(OUTPUT_FILENAME, pipeline_lines) |