comparison tile.py @ 2:972d2c365739 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:31:44 +0000
parents 1fd453cd757b
children
comparison
equal deleted inserted replaced
1:1fd453cd757b 2:972d2c365739
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
13 11
14 MODULE_NAME = "Tile" 12 MODULE_NAME = "Tile"
15 OUTPUT_FILENAME = "output.cppipe" 13 OUTPUT_FILENAME = "output.cppipe"
16 14
17 15
18 def build_header(module_name, module_number): 16 def build_header(module_name, module_number):
19 result = "|".join([f"{module_name}:[module_num:{module_number}", 17 result = "|".join(
20 "svn_version:\\'Unknown\\'", 18 [
21 "variable_revision_number:1", 19 f"{module_name}:[module_num:{module_number}",
22 "show_window:True", 20 "svn_version:\\'Unknown\\'",
23 "notes:\\x5B\\'Tile the original color image, the outlined image and the image of tracked labels together.\\'\\x5D", 21 "variable_revision_number:1",
24 "batch_state:array(\\x5B\\x5D, dtype=uint8)", 22 "show_window:True",
25 "enabled:True", 23 "notes:\\x5B\\'Tile the original color image, the outlined image and the image of tracked labels together.\\'\\x5D",
26 "wants_pause:False]\n"]) 24 "batch_state:array(\\x5B\\x5D, dtype=uint8)",
25 "enabled:True",
26 "wants_pause:False]\n",
27 ]
28 )
27 return result 29 return result
28 30
29 31
30 def build_main_block(input_params): 32 def build_main_block(input_params):
31 result = INDENTATION.join([f"{INDENTATION}Select an input image:{get_json_value(input_params,'input_image')}\n", 33 result = INDENTATION.join(
32 f"Name the output image:{get_json_value(input_params,'output_image_name')}\n", 34 [
33 f"Tile assembly method:{get_json_value(input_params,'con_assembly_method.assembly_method')}\n" 35 f"{INDENTATION}Select an input image:{get_json_value(input_params,'input_image')}\n",
34 ]) 36 f"Name the output image:{get_json_value(input_params,'output_image_name')}\n",
37 f"Tile assembly method:{get_json_value(input_params,'con_assembly_method.assembly_method')}\n",
38 ]
39 )
35 40
36 calc_rows = get_json_value(input_params, 'con_assembly_method.con_calc_no_row.calc_no_row') 41 calc_rows = get_json_value(
42 input_params, "con_assembly_method.con_calc_no_row.calc_no_row"
43 )
37 no_of_rows = 8 44 no_of_rows = 8
38 45
39 calc_cols = get_json_value(input_params, 'con_assembly_method.con_calc_no_cols.calc_no_cols') 46 calc_cols = get_json_value(
47 input_params, "con_assembly_method.con_calc_no_cols.calc_no_cols"
48 )
40 no_of_cols = 12 49 no_of_cols = 12
41 50
42 if calc_rows == "No": 51 if calc_rows == "No":
43 no_of_rows = get_json_value(input_params, 'con_assembly_method.con_calc_no_row.no_of_row') 52 no_of_rows = get_json_value(
53 input_params, "con_assembly_method.con_calc_no_row.no_of_row"
54 )
44 55
45 if calc_cols == "No": 56 if calc_cols == "No":
46 no_of_cols = get_json_value(input_params, 'con_assembly_method.con_calc_no_cols.no_of_cols') 57 no_of_cols = get_json_value(
58 input_params, "con_assembly_method.con_calc_no_cols.no_of_cols"
59 )
47 60
48 corner_to_begin = get_json_value(input_params, 'con_assembly_method.corner_to_begin') 61 corner_to_begin = get_json_value(
49 direction_tiling = get_json_value(input_params, 'con_assembly_method.direction') 62 input_params, "con_assembly_method.corner_to_begin"
50 meander = get_json_value(input_params, 'con_assembly_method.meander_mode') 63 )
64 direction_tiling = get_json_value(input_params, "con_assembly_method.direction")
65 meander = get_json_value(input_params, "con_assembly_method.meander_mode")
51 66
52 assembly_method = get_json_value(input_params, 'con_assembly_method.assembly_method') 67 assembly_method = get_json_value(
68 input_params, "con_assembly_method.assembly_method"
69 )
53 70
54 result += INDENTATION.join( 71 result += INDENTATION.join(
55 [f"{INDENTATION}Final number of rows:{str(no_of_rows)}\n", 72 [
56 f"Final number of columns:{str(no_of_cols)}\n", 73 f"{INDENTATION}Final number of rows:{str(no_of_rows)}\n",
57 f"Image corner to begin tiling:{corner_to_begin}\n", 74 f"Final number of columns:{str(no_of_cols)}\n",
58 f"Direction to begin tiling:{direction_tiling}\n", 75 f"Image corner to begin tiling:{corner_to_begin}\n",
59 f"Use meander mode?:{meander}\n", 76 f"Direction to begin tiling:{direction_tiling}\n",
60 f"Automatically calculate number of rows?:{calc_rows}\n", 77 f"Use meander mode?:{meander}\n",
61 f"Automatically calculate number of columns?:{calc_cols}\n" 78 f"Automatically calculate number of rows?:{calc_rows}\n",
62 ]) 79 f"Automatically calculate number of columns?:{calc_cols}\n",
80 ]
81 )
63 82
64 if assembly_method == "Within cycles": 83 if assembly_method == "Within cycles":
65 additionals = input_params['con_assembly_method']['rpt_additional_image'] 84 additionals = input_params["con_assembly_method"]["rpt_additional_image"]
66 85
67 for img in additionals: 86 for img in additionals:
68 result += INDENTATION.join( 87 result += INDENTATION.join(
69 [f"{INDENTATION}Select an additional image to tile:{get_json_value(img, 'additional_img')}\n" 88 [
70 ]) 89 f"{INDENTATION}Select an additional image to tile:{get_json_value(img, 'additional_img')}\n"
90 ]
91 )
71 result = result.rstrip("\n") 92 result = result.rstrip("\n")
72 return result 93 return result
73 94
74 95
75 if __name__ == "__main__": 96 if __name__ == "__main__":
76 parser = argparse.ArgumentParser() 97 parser = argparse.ArgumentParser()
77 parser.add_argument( 98 parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline")
78 '-p', '--pipeline', 99 parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy")
79 help='CellProfiler pipeline'
80 )
81 parser.add_argument(
82 '-i', '--inputs',
83 help='JSON inputs from Galaxy'
84 )
85 args = parser.parse_args() 100 args = parser.parse_args()
86 101
87 pipeline_lines = get_pipeline_lines(args.pipeline) 102 pipeline_lines = get_pipeline_lines(args.pipeline)
88 inputs_galaxy = json.load(open(args.inputs, "r")) 103 inputs_galaxy = json.load(open(args.inputs, "r"))
89 104