Previous changeset 5:b178453ea8d1 (2021-02-26) |
Commit message:
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5 |
modified:
color_to_gray.py cp_common_functions.py image_math.py mask_image.xml overlay_outlines.py starting_modules.py tile.py track_objects.py |
b |
diff -r b178453ea8d1 -r 667a513e67e4 color_to_gray.py --- a/color_to_gray.py Fri Feb 26 14:19:11 2021 +0000 +++ b/color_to_gray.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
b'@@ -3,12 +3,11 @@\n import argparse\r\n import json\r\n \r\n-from cp_common_functions import get_json_value\r\n-from cp_common_functions import get_pipeline_lines\r\n-from cp_common_functions import get_total_number_of_modules\r\n-from cp_common_functions import INDENTATION\r\n-from cp_common_functions import update_module_count\r\n-from cp_common_functions import write_pipeline\r\n+from cp_common_functions import (get_json_value,\r\n+ get_pipeline_lines,\r\n+ get_total_number_of_modules,\r\n+ INDENTATION, update_module_count,\r\n+ write_pipeline)\r\n \r\n MODULE_NAME = "ColorToGray"\r\n OUTPUT_FILENAME = "output.cppipe"\r\n@@ -16,27 +15,38 @@\n \r\n def build_ctg_header(module_name, module_number):\r\n """Creates the first line of a module given the name and module number"""\r\n- result = "|".join([f"{module_name}:[module_num:{module_number}",\r\n- "svn_version:\\\\\'Unknown\\\\\'",\r\n- "variable_revision_number:4",\r\n- "show_window:True",\r\n- "notes:\\\\x5B\\\\\'Convert the color image to grayscale.\\\\\'\\\\x5D",\r\n- "batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)",\r\n- "enabled:True",\r\n- "wants_pause:False]\\n"])\r\n+ result = "|".join(\r\n+ [\r\n+ f"{module_name}:[module_num:{module_number}",\r\n+ "svn_version:\\\\\'Unknown\\\\\'",\r\n+ "variable_revision_number:4",\r\n+ "show_window:True",\r\n+ "notes:\\\\x5B\\\\\'Convert the color image to grayscale.\\\\\'\\\\x5D",\r\n+ "batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)",\r\n+ "enabled:True",\r\n+ "wants_pause:False]\\n",\r\n+ ]\r\n+ )\r\n return result\r\n \r\n \r\n def build_main_block(input_params):\r\n """Creates the main block of the CP pipeline with the parameters that don\'t depend on conditional choices"""\r\n- result = INDENTATION.join([f"{INDENTATION}Select the input image:{get_json_value(input_params,\'name_input_image\')}\\n",\r\n- f"Conversion method:{get_json_value(input_params,\'con_conversion_method.conversion_method\')}\\n",\r\n- f"Image type:{get_json_value(input_params,\'con_conversion_method.con_image_type.image_type\')}\\n",\r\n- ])\r\n+ result = INDENTATION.join(\r\n+ [\r\n+ f"{INDENTATION}Select the input image:{get_json_value(input_params,\'name_input_image\')}\\n",\r\n+ f"Conversion method:{get_json_value(input_params,\'con_conversion_method.conversion_method\')}\\n",\r\n+ f"Image type:{get_json_value(input_params,\'con_conversion_method.con_image_type.image_type\')}\\n",\r\n+ ]\r\n+ )\r\n \r\n- conversion_method = get_json_value(input_params, \'con_conversion_method.conversion_method\')\r\n+ conversion_method = get_json_value(\r\n+ input_params, "con_conversion_method.conversion_method"\r\n+ )\r\n \r\n- image_type = get_json_value(input_params, \'con_conversion_method.con_image_type.image_type\')\r\n+ image_type = get_json_value(\r\n+ input_params, "con_conversion_method.con_image_type.image_type"\r\n+ )\r\n rgb_comb_name_out = "OrigGray"\r\n combine_w_red = 1.0\r\n combine_w_green = 1.0\r\n@@ -59,88 +69,131 @@\n channel_count = 1\r\n if conversion_method == "Combine":\r\n if image_type == "RGB" or image_type == "HSV":\r\n- rgb_comb_name_out = get_json_value(input_params, \'con_conversion_method.name_output_image\')\r\n- combine_w_red = get_json_value(input_params, \'con_conversion_method.con_image_type.weight_red_channel\')\r\n- combine_w_green = get_json_value(input_params, \'con_conversion_method.con_image_type.weight_green_channel\')\r\n- combine_w_blue = get_json_value(input_params, \'con_conversion_method.con_image_type.weight_blue_channel\')\r\n+ rgb_comb_name_out = get_json_value(\r\n+ inp'..b' f"Name the output image:{hue_output_name}\\n",\r\n- f"Convert saturation to gray?:{split_saturation}\\n",\r\n- f"Name the output image:{saturation_output_name}\\n",\r\n- f"Convert value to gray?:{split_value}\\n",\r\n- f"Name the output image:{value_output_name}\\n"\r\n- ])\r\n+ [\r\n+ f"{INDENTATION}Name the output image:{rgb_comb_name_out}\\n",\r\n+ f"Relative weight of the red channel:{str(combine_w_red)}\\n",\r\n+ f"Relative weight of the green channel:{str(combine_w_green)}\\n",\r\n+ f"Relative weight of the blue channel:{str(combine_w_blue)}\\n",\r\n+ f"Convert red to gray?:{split_red}\\n",\r\n+ f"Name the output image:{red_output_name}\\n",\r\n+ f"Convert green to gray?:{split_green}\\n",\r\n+ f"Name the output image:{green_output_name}\\n",\r\n+ f"Convert blue to gray?:{split_blue}\\n",\r\n+ f"Name the output image:{blue_output_name}\\n",\r\n+ f"Convert hue to gray?:{split_hue}\\n",\r\n+ f"Name the output image:{hue_output_name}\\n",\r\n+ f"Convert saturation to gray?:{split_saturation}\\n",\r\n+ f"Name the output image:{saturation_output_name}\\n",\r\n+ f"Convert value to gray?:{split_value}\\n",\r\n+ f"Name the output image:{value_output_name}\\n",\r\n+ ]\r\n+ )\r\n \r\n channel_count = 1\r\n if image_type == "Channels":\r\n- channels = input_params[\'con_conversion_method\'][\'con_image_type\'][\'rpt_channel\']\r\n+ channels = input_params["con_conversion_method"]["con_image_type"][\r\n+ "rpt_channel"\r\n+ ]\r\n channel_count = len(channels)\r\n- result += INDENTATION.join(\r\n- [f"{INDENTATION}Channel count:{channel_count}\\n"\r\n- ])\r\n+ result += INDENTATION.join([f"{INDENTATION}Channel count:{channel_count}\\n"])\r\n \r\n for ch in channels:\r\n rel_weight_ch = 1.0\r\n image_name = "Channel1"\r\n if conversion_method == "Combine":\r\n- rel_weight_ch = get_json_value(ch, \'weight_of_channel\')\r\n+ rel_weight_ch = get_json_value(ch, "weight_of_channel")\r\n else:\r\n- image_name = get_json_value(ch, \'image_name\')\r\n+ image_name = get_json_value(ch, "image_name")\r\n result += INDENTATION.join(\r\n- [f"{INDENTATION}Channel number:{get_json_value(ch,\'channel_no\')}\\n",\r\n- f"Relative weight of the channel:{str(rel_weight_ch)}\\n",\r\n- f"Image name:{image_name}\\n"\r\n- ])\r\n+ [\r\n+ f"{INDENTATION}Channel number:{get_json_value(ch,\'channel_no\')}\\n",\r\n+ f"Relative weight of the channel:{str(rel_weight_ch)}\\n",\r\n+ f"Image name:{image_name}\\n",\r\n+ ]\r\n+ )\r\n else:\r\n result += INDENTATION.join(\r\n- [f"{INDENTATION}Channel count:{channel_count}\\n",\r\n- "Channel number:Red\\\\x3A 1\\n",\r\n- "Relative weight of the channel:1.0\\n",\r\n- "Image name:Channel1\\n"\r\n- ])\r\n+ [\r\n+ f"{INDENTATION}Channel count:{channel_count}\\n",\r\n+ "Channel number:Red\\\\x3A 1\\n",\r\n+ "Relative weight of the channel:1.0\\n",\r\n+ "Image name:Channel1\\n",\r\n+ ]\r\n+ )\r\n result = result.rstrip("\\n")\r\n return result\r\n \r\n \r\n if __name__ == "__main__":\r\n parser = argparse.ArgumentParser()\r\n- parser.add_argument(\r\n- \'-p\', \'--pipeline\',\r\n- help=\'CellProfiler pipeline\'\r\n- )\r\n- parser.add_argument(\r\n- \'-i\', \'--inputs\',\r\n- help=\'JSON inputs from Galaxy\'\r\n- )\r\n+ parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline")\r\n+ parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy")\r\n args = parser.parse_args()\r\n \r\n pipeline_lines = get_pipeline_lines(args.pipeline)\r\n' |
b |
diff -r b178453ea8d1 -r 667a513e67e4 cp_common_functions.py --- a/cp_common_functions.py Fri Feb 26 14:19:11 2021 +0000 +++ b/cp_common_functions.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
@@ -25,7 +25,7 @@ def get_total_number_of_modules(pipeline_lines): """Gets the number of modules from the header of the previous pipeline""" - number_of_modules = pipeline_lines[LINE_NUM_MODULES].strip().split(':')[1] + number_of_modules = pipeline_lines[LINE_NUM_MODULES].strip().split(":")[1] return int(number_of_modules) @@ -38,7 +38,7 @@ def update_module_count(pipeline_lines, count): """Updates the number of modules in the .cppipe header""" - module_count_entry = pipeline_lines[LINE_NUM_MODULES].strip().split(':')[0] + module_count_entry = pipeline_lines[LINE_NUM_MODULES].strip().split(":")[0] pipeline_lines[4] = f"{module_count_entry}:{count}\n" return pipeline_lines @@ -51,12 +51,16 @@ def build_header(module_name, module_number): """Creates the first line of a module given the name and module number""" - result = "|".join([f"{module_name}:[module_num:{module_number}", - "svn_version:\\'Unknown\\'", - "variable_revision_number:4", - "show_window:False", - "notes:\\x5B\\x5D", - "batch_state:array(\\x5B\\x5D, dtype=uint8)", - "enabled:True", - "wants_pause:False]\n"]) + result = "|".join( + [ + f"{module_name}:[module_num:{module_number}", + "svn_version:\\'Unknown\\'", + "variable_revision_number:4", + "show_window:False", + "notes:\\x5B\\x5D", + "batch_state:array(\\x5B\\x5D, dtype=uint8)", + "enabled:True", + "wants_pause:False]\n", + ] + ) return result |
b |
diff -r b178453ea8d1 -r 667a513e67e4 image_math.py --- a/image_math.py Fri Feb 26 14:19:11 2021 +0000 +++ b/image_math.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
@@ -3,14 +3,11 @@ import argparse import json -from cp_common_functions import build_header -from cp_common_functions import concat_conditional -from cp_common_functions import get_json_value -from cp_common_functions import get_pipeline_lines -from cp_common_functions import get_total_number_of_modules -from cp_common_functions import INDENTATION -from cp_common_functions import update_module_count -from cp_common_functions import write_pipeline +from cp_common_functions import (build_header, concat_conditional, + get_json_value, get_pipeline_lines, + get_total_number_of_modules, + INDENTATION, update_module_count, + write_pipeline) MODULE_NAME = "ImageMath" OUTPUT_FILENAME = "output.cppipe" @@ -29,33 +26,37 @@ "and": "And", "or": "Or", "not": "Not", - "equals": "Equals" + "equals": "Equals", } def build_main_block(input_params): """Creates the main block of the CP pipeline with the parameters that don't depend on conditional choices""" - operation = operator_map[get_json_value( - input_params, 'operation.operation')] - result = INDENTATION.join([f"{INDENTATION}Operation:{operation}\n", - f"Raise the power of the result by:{get_json_value(input_params,'operation.op_results.raise_the_power_of_the_result_by')}\n", - f"Multiply the result by:{get_json_value(input_params,'operation.op_results.multiply_the_result_by')}\n", - f"Add to result:{get_json_value(input_params,'operation.op_results.add_to_result')}\n", - f"Set values less than 0 equal to 0?:{get_json_value(input_params,'operation.op_results.set_values_less_than_0_equal_to_0')}\n", - f"Set values greater than 1 equal to 1?:{get_json_value(input_params,'operation.op_results.set_values_greater_than_1_equal_to_1')}\n", - f"Ignore the image masks?:{get_json_value(input_params,'ignore_the_image_masks')}\n", - f"Name the output image:{get_json_value(input_params,'name_output_image')}" - ]) + operation = operator_map[get_json_value(input_params, "operation.operation")] + result = INDENTATION.join( + [ + f"{INDENTATION}Operation:{operation}\n", + f"Raise the power of the result by:{get_json_value(input_params,'operation.op_results.raise_the_power_of_the_result_by')}\n", + f"Multiply the result by:{get_json_value(input_params,'operation.op_results.multiply_the_result_by')}\n", + f"Add to result:{get_json_value(input_params,'operation.op_results.add_to_result')}\n", + f"Set values less than 0 equal to 0?:{get_json_value(input_params,'operation.op_results.set_values_less_than_0_equal_to_0')}\n", + f"Set values greater than 1 equal to 1?:{get_json_value(input_params,'operation.op_results.set_values_greater_than_1_equal_to_1')}\n", + f"Ignore the image masks?:{get_json_value(input_params,'ignore_the_image_masks')}\n", + f"Name the output image:{get_json_value(input_params,'name_output_image')}", + ] + ) return result def build_variable_block(inputs_galaxy): result = "" first_image_block = build_first_image_block( - get_json_value(inputs_galaxy, 'operation.first_image')) + get_json_value(inputs_galaxy, "operation.first_image") + ) result += f"\n{first_image_block}" second_image_block = build_second_image_block( - get_json_value(inputs_galaxy, 'operation.second_image')) + get_json_value(inputs_galaxy, "operation.second_image") + ) result += f"\n{second_image_block}" return result @@ -64,22 +65,27 @@ """Creates the block of parameters for the first operator in operations""" value_select = get_json_value( - input_params, 'image_or_measurement_first.image_or_measurement_first') + input_params, "image_or_measurement_first.image_or_measurement_first" + ) image_name = get_json_value( - input_params, 'image_or_measurement_first.select_the_first_image') - value_multiply = get_json_value( - input_params, 'multiply_the_first_image_by') + input_params, "image_or_measurement_first.select_the_first_image" + ) + value_multiply = get_json_value(input_params, "multiply_the_first_image_by") category = get_json_value( - input_params, 'image_or_measurement_first.category_first.category_first') + input_params, "image_or_measurement_first.category_first.category_first" + ) measurement = get_json_value( - input_params, 'image_or_measurement_first.category_first.measurement_first') + input_params, "image_or_measurement_first.category_first.measurement_first" + ) result = INDENTATION.join( - [f"{INDENTATION}Image or measurement?:{value_select}\n", - f"Select the first image:{image_name}\n", - f"Multiply the first image by:{value_multiply}\n", - f"Measurement:{concat_conditional(category, measurement)}" - ]) + [ + f"{INDENTATION}Image or measurement?:{value_select}\n", + f"Select the first image:{image_name}\n", + f"Multiply the first image by:{value_multiply}\n", + f"Measurement:{concat_conditional(category, measurement)}", + ] + ) return result @@ -87,35 +93,34 @@ """Creates the block of parameters for the second operator in binary operations""" value_select = get_json_value( - input_params, 'image_or_measurement_second.image_or_measurement_second') + input_params, "image_or_measurement_second.image_or_measurement_second" + ) image_name = get_json_value( - input_params, 'image_or_measurement_second.select_the_second_image') - value_multiply = get_json_value( - input_params, 'multiply_the_second_image_by') + input_params, "image_or_measurement_second.select_the_second_image" + ) + value_multiply = get_json_value(input_params, "multiply_the_second_image_by") category = get_json_value( - input_params, 'image_or_measurement_second.category_second.category_second') + input_params, "image_or_measurement_second.category_second.category_second" + ) measurement = get_json_value( - input_params, 'image_or_measurement_second.category_second.measurement_second') + input_params, "image_or_measurement_second.category_second.measurement_second" + ) result = INDENTATION.join( - [f"{INDENTATION}Image or measurement?:{value_select}\n", - f"Select the second image:{image_name}\n", - f"Multiply the second image by:{value_multiply}\n", - f"Measurement:{concat_conditional(category, measurement)}" - ]) + [ + f"{INDENTATION}Image or measurement?:{value_select}\n", + f"Select the second image:{image_name}\n", + f"Multiply the second image by:{value_multiply}\n", + f"Measurement:{concat_conditional(category, measurement)}", + ] + ) return result if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument( - '-p', '--pipeline', - help='CellProfiler pipeline' - ) - parser.add_argument( - '-i', '--inputs', - help='JSON inputs from Galaxy' - ) + parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline") + parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy") args = parser.parse_args() pipeline_lines = get_pipeline_lines(args.pipeline) |
b |
diff -r b178453ea8d1 -r 667a513e67e4 mask_image.xml --- a/mask_image.xml Fri Feb 26 14:19:11 2021 +0000 +++ b/mask_image.xml Sun Nov 05 09:24:38 2023 +0000 |
b |
@@ -1,11 +1,19 @@ <tool id="cp_mask_image" name="MaskImage" version="@CP_VERSION@+galaxy@VERSION_SUFFIX@"> - <description>hide portions of an image based on previously identified objects</description> + <description>with CellProfiler</description> <macros> <import>macros.xml</import> - <token name="@VERSION_SUFFIX@">0</token> + <token name="@VERSION_SUFFIX@">1</token> </macros> + <edam_operations> + <edam_operation>operation_3443</edam_operation> + </edam_operations> + <xrefs> + <xref type="bio.tools">CellProfiler</xref> + <xref type="biii">cellprofiler</xref> + </xrefs> + <expand macro="py_requirements"/> <expand macro="cmd_modules" /> |
b |
diff -r b178453ea8d1 -r 667a513e67e4 overlay_outlines.py --- a/overlay_outlines.py Fri Feb 26 14:19:11 2021 +0000 +++ b/overlay_outlines.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
@@ -3,12 +3,11 @@ import argparse import json -from cp_common_functions import get_json_value -from cp_common_functions import get_pipeline_lines -from cp_common_functions import get_total_number_of_modules -from cp_common_functions import INDENTATION -from cp_common_functions import update_module_count -from cp_common_functions import write_pipeline +from cp_common_functions import (get_json_value, + get_pipeline_lines, + get_total_number_of_modules, + INDENTATION, update_module_count, + write_pipeline) MODULE_NAME = "OverlayOutlines" OUTPUT_FILENAME = "output.cppipe" @@ -16,65 +15,85 @@ def build_ctg_header(module_name, module_number): """Creates the first line of a module given the name and module number""" - result = "|".join([f"{module_name}:[module_num:{module_number}", - "svn_version:\\'Unknown\\'", - "variable_revision_number:4", - "show_window:True", - "notes:\\x5B\\'Overlay the embryo outlines on the grayscale image.\\'\\x5D", - "batch_state:array(\\x5B\\x5D, dtype=uint8)", - "enabled:True", - "wants_pause:False]\n"]) + result = "|".join( + [ + f"{module_name}:[module_num:{module_number}", + "svn_version:\\'Unknown\\'", + "variable_revision_number:4", + "show_window:True", + "notes:\\x5B\\'Overlay the embryo outlines on the grayscale image.\\'\\x5D", + "batch_state:array(\\x5B\\x5D, dtype=uint8)", + "enabled:True", + "wants_pause:False]\n", + ] + ) return result def build_main_block(input_params): result = f"{INDENTATION}Display outlines on a blank image?:{get_json_value(input_params,'con_blank_img.blank_img')}\n" - on_blank = get_json_value(input_params, 'con_blank_img.blank_img') + on_blank = get_json_value(input_params, "con_blank_img.blank_img") # defaults img_to_display = "None" - display_mode = get_json_value(input_params, 'con_blank_img.con_display_mode.display_mode') + display_mode = get_json_value( + input_params, "con_blank_img.con_display_mode.display_mode" + ) method_brightness = "Max of image" - howto = get_json_value(input_params, 'howto_outline') + howto = get_json_value(input_params, "howto_outline") outline_color = "#FF0000" obj_to_display = "None" - name_output_img = get_json_value(input_params, 'name_output_image') + name_output_img = get_json_value(input_params, "name_output_image") if on_blank == "No": - img_to_display = get_json_value(input_params, 'con_blank_img.image_to_outline') + img_to_display = get_json_value(input_params, "con_blank_img.image_to_outline") result += INDENTATION.join( - [f"{INDENTATION}Select image on which to display outlines:{img_to_display}\n", - f"Name the output image:{name_output_img}\n", - f"Outline display mode:{display_mode}\n" - ]) + [ + f"{INDENTATION}Select image on which to display outlines:{img_to_display}\n", + f"Name the output image:{name_output_img}\n", + f"Outline display mode:{display_mode}\n", + ] + ) if on_blank == "No" and display_mode == "Grayscale": - method_brightness = get_json_value(input_params, 'con_blank_img.con_display_mode.method_brightness') + method_brightness = get_json_value( + input_params, "con_blank_img.con_display_mode.method_brightness" + ) result += INDENTATION.join( - [f"{INDENTATION}Select method to determine brightness of outlines:{method_brightness}\n", - f"How to outline:{howto}\n" - ]) + [ + f"{INDENTATION}Select method to determine brightness of outlines:{method_brightness}\n", + f"How to outline:{howto}\n", + ] + ) obj_outline_str = "" if display_mode == "Color": - for obj in input_params['con_blank_img']['con_display_mode']['rpt_obj_to_display']: - outline_color = get_json_value(obj, 'outline_color') - obj_to_display = get_json_value(obj, 'obj_to_display') + for obj in input_params["con_blank_img"]["con_display_mode"][ + "rpt_obj_to_display" + ]: + outline_color = get_json_value(obj, "outline_color") + obj_to_display = get_json_value(obj, "obj_to_display") obj_outline_str += INDENTATION.join( - [f"{INDENTATION}Select outline color:{outline_color}\n", - f"Select objects to display:{obj_to_display}\n" - ]) + [ + f"{INDENTATION}Select outline color:{outline_color}\n", + f"Select objects to display:{obj_to_display}\n", + ] + ) else: # grayscale - for obj in input_params['con_blank_img']['con_display_mode']['rpt_obj_to_display']: - obj_to_display = get_json_value(obj, 'obj_to_display') + for obj in input_params["con_blank_img"]["con_display_mode"][ + "rpt_obj_to_display" + ]: + obj_to_display = get_json_value(obj, "obj_to_display") obj_outline_str += INDENTATION.join( - [f"{INDENTATION}Select outline color:{outline_color}\n", - f"Select objects to display:{obj_to_display}\n" - ]) + [ + f"{INDENTATION}Select outline color:{outline_color}\n", + f"Select objects to display:{obj_to_display}\n", + ] + ) obj_outline_str = obj_outline_str.rstrip("\n") result += f"{obj_outline_str}" @@ -83,14 +102,8 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument( - '-p', '--pipeline', - help='CellProfiler pipeline' - ) - parser.add_argument( - '-i', '--inputs', - help='JSON inputs from Galaxy' - ) + parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline") + parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy") args = parser.parse_args() pipeline_lines = get_pipeline_lines(args.pipeline) |
b |
diff -r b178453ea8d1 -r 667a513e67e4 starting_modules.py --- a/starting_modules.py Fri Feb 26 14:19:11 2021 +0000 +++ b/starting_modules.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
b'@@ -9,22 +9,25 @@\n \r\n \r\n def write_images():\r\n- filter_images = params[\'images\'][\'filter_images\']\r\n+ filter_images = params["images"]["filter_images"]\r\n \r\n _str = "\\nImages:[module_num:1|svn_version:\\\\\'Unknown\\\\\'|variable_revision_number:2|show_window:False|notes:\\\\x5B\\\\\'To begin creating your project, use the Images module to compile a list of files and/or folders that you want to analyze. You can also specify a set of rules to include only the desired files in your selected folders.\\\\\'\\\\x5D|batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\\n"\r\n _str += FOURSPACES + ":\\n"\r\n _str += FOURSPACES + "Filter images?:%s\\n" % filter_images\r\n- _str += FOURSPACES + "Select the rule criteria:and (extension does isimage) (directory doesnot startwith \\".\\")\\n"\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + \'Select the rule criteria:and (extension does isimage) (directory doesnot startwith ".")\\n\'\r\n+ )\r\n \r\n return _str\r\n \r\n \r\n def write_metadata():\r\n- metadata_extraction = params[\'metadata\'][\'con_metadata_extraction\']\r\n- extract = metadata_extraction[\'extract\']\r\n+ metadata_extraction = params["metadata"]["con_metadata_extraction"]\r\n+ extract = metadata_extraction["extract"]\r\n \r\n- if \'extraction_method\' in metadata_extraction:\r\n- method_count = len(metadata_extraction[\'extraction_method\'])\r\n+ if "extraction_method" in metadata_extraction:\r\n+ method_count = len(metadata_extraction["extraction_method"])\r\n else:\r\n method_count = 1\r\n \r\n@@ -35,22 +38,42 @@\n _str += FOURSPACES + "Metadata data type:Text\\n"\r\n _str += FOURSPACES + "Metadata types:{}\\n"\r\n _str += FOURSPACES + "Extraction method count:%d\\n" % method_count\r\n- _str += FOURSPACES + "Metadata extraction method:Extract from file/folder names\\n"\r\n- _str += FOURSPACES + "Regular expression to extract from file name:^(?P<Plate>.*)_(?P<Well>\\x5BA-P\\x5D\\x5B0-9\\x5D{2})_s(?P<Site>\\x5B0-9\\x5D)_w(?P<ChannelNumber>\\x5B0-9\\x5D)\\n"\r\n- _str += FOURSPACES + "Regular expression to extract from folder name:(?P<Date>\\x5B0-9\\x5D{4}_\\x5B0-9\\x5D{2}_\\x5B0-9\\x5D{2})$\\n"\r\n+ _str += (\r\n+ FOURSPACES + "Metadata extraction method:Extract from file/folder names\\n"\r\n+ )\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Regular expression to extract from file name:^(?P<Plate>.*)_(?P<Well>\\x5BA-P\\x5D\\x5B0-9\\x5D{2})_s(?P<Site>\\x5B0-9\\x5D)_w(?P<ChannelNumber>\\x5B0-9\\x5D)\\n"\r\n+ )\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Regular expression to extract from folder name:(?P<Date>\\x5B0-9\\x5D{4}_\\x5B0-9\\x5D{2}_\\x5B0-9\\x5D{2})$\\n"\r\n+ )\r\n _str += FOURSPACES + "Extract metadata from:All images\\n"\r\n- _str += FOURSPACES + "Select the filtering criteria:and (file does contain \\"\\")\\n"\r\n+ _str += (\r\n+ FOURSPACES + \'Select the filtering criteria:and (file does contain "")\\n\'\r\n+ )\r\n _str += FOURSPACES + "Metadata file location:\\n"\r\n _str += FOURSPACES + "Match file and image metadata:\\x5B\\x5D\\n"\r\n _str += FOURSPACES + "Use case insensitive matching?:No\\n"\r\n else:\r\n- _str += FOURSPACES + "Metadata data type:Text\\n" # default Text,not possible to select in Galaxy\r\n+ _str += (\r\n+ FOURSPACES + "Metadata data type:Text\\n"\r\n+ ) # default Text,not possible to select in Galaxy\r\n _str += FOURSPACES + "Metadata types:{}\\n"\r\n _str += FOURSPACES + "Extraction method count:%d\\n" % method_count\r\n \r\n for methods in metadata_extraction["extraction_method"]:\r\n- _str += FOURSPACES + "Metadata extraction method:%s\\n" % methods["metadata_extraction_method"]\r\n- _str += FOURSPACES + "Metadata source:%s\\n" % methods["con_metadata_source"]["metadata_source"]\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Metadata extraction method:%s\\n"\r\n+ % methods["metadata_'..b'e objects:%s\\n" % rule["con_select_image_type"]["name_to_assign"]\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Name to assign these objects:%s\\n"\r\n+ % rule["con_select_image_type"]["name_to_assign"]\r\n+ )\r\n else:\r\n- _str += FOURSPACES + "Name to assign these images:%s\\n" % rule["con_select_image_type"]["name_to_assign"]\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Name to assign these images:%s\\n"\r\n+ % rule["con_select_image_type"]["name_to_assign"]\r\n+ )\r\n _str += FOURSPACES + "Name to assign these objects:Cell\\n"\r\n \r\n _str += FOURSPACES + "Select the image type:%s\\n" % img_or_obj\r\n \r\n intensity_range = "Image metadata" # default value\r\n if img_or_obj == "Grayscale image" or img_or_obj == "Color image":\r\n- intensity_range = rule["con_select_image_type"]["con_set_intensity"]["set_intensity_range_from"]\r\n+ intensity_range = rule["con_select_image_type"]["con_set_intensity"][\r\n+ "set_intensity_range_from"\r\n+ ]\r\n \r\n _str += FOURSPACES + "Set intensity range from:%s\\n" % intensity_range\r\n \r\n if intensity_range == "Manual":\r\n- _str += FOURSPACES + "Maximum intensity:%s\\n" % rule["con_select_image_type"]["con_set_intensity"]["maximum_intensity"]\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Maximum intensity:%s\\n"\r\n+ % rule["con_select_image_type"]["con_set_intensity"][\r\n+ "maximum_intensity"\r\n+ ]\r\n+ )\r\n else:\r\n _str += FOURSPACES + "Maximum intensity:255.0\\n"\r\n \r\n@@ -184,9 +314,9 @@\n \r\n \r\n def write_groups():\r\n- groups = params[\'groups\']\r\n+ groups = params["groups"]\r\n \r\n- _str = "\\nGroups:[module_num:4|svn_version:\\\\\'Unknown\\\\\'|variable_revision_number:2|show_window:False|notes:\\\\x5B\\\\\\\'The Groups module optionally allows you to split your list of images into image subsets (groups) which will be processed independently of each other. Examples of groupings include screening batches, microtiter plates, time-lapse movies, etc.\\\\\'\\\\x5D|batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\\n"\r\n+ _str = "\\nGroups:[module_num:4|svn_version:\\\\\'Unknown\\\\\'|variable_revision_number:2|show_window:False|notes:\\\\x5B\\\\\'The Groups module optionally allows you to split your list of images into image subsets (groups) which will be processed independently of each other. Examples of groupings include screening batches, microtiter plates, time-lapse movies, etc.\\\\\'\\\\x5D|batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\\n"\r\n \r\n group_images = groups["con_groups"]["group_images"]\r\n \r\n@@ -194,7 +324,10 @@\n _str += FOURSPACES + "grouping metadata count:1\\n"\r\n \r\n if group_images == "Yes":\r\n- _str += FOURSPACES + "Metadata category:%s\\n" % groups["con_groups"]["group_category"]\r\n+ _str += (\r\n+ FOURSPACES\r\n+ + "Metadata category:%s\\n" % groups["con_groups"]["group_category"]\r\n+ )\r\n else:\r\n _str += FOURSPACES + "Metadata category:None\\n"\r\n \r\n@@ -202,13 +335,15 @@\n \r\n \r\n with open("output.cppipe", "w") as f:\r\n- headers = ["CellProfiler Pipeline: http://www.cellprofiler.org\\n",\r\n- "Version:3\\n",\r\n- "DateRevision:319\\n",\r\n- "GitHash:\\n",\r\n- "ModuleCount:4\\n",\r\n- "HasImagePlaneDetails:False",\r\n- "\\n"]\r\n+ headers = [\r\n+ "CellProfiler Pipeline: http://www.cellprofiler.org\\n",\r\n+ "Version:3\\n",\r\n+ "DateRevision:319\\n",\r\n+ "GitHash:\\n",\r\n+ "ModuleCount:4\\n",\r\n+ "HasImagePlaneDetails:False",\r\n+ "\\n",\r\n+ ]\r\n \r\n f.writelines(headers)\r\n \r\n' |
b |
diff -r b178453ea8d1 -r 667a513e67e4 tile.py --- a/tile.py Fri Feb 26 14:19:11 2021 +0000 +++ b/tile.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
@@ -3,85 +3,100 @@ import argparse import json -from cp_common_functions import get_json_value -from cp_common_functions import get_pipeline_lines -from cp_common_functions import get_total_number_of_modules -from cp_common_functions import INDENTATION -from cp_common_functions import update_module_count -from cp_common_functions import write_pipeline - +from cp_common_functions import (get_json_value, + get_pipeline_lines, + get_total_number_of_modules, + INDENTATION, update_module_count, + write_pipeline) MODULE_NAME = "Tile" OUTPUT_FILENAME = "output.cppipe" def build_header(module_name, module_number): - result = "|".join([f"{module_name}:[module_num:{module_number}", - "svn_version:\\'Unknown\\'", - "variable_revision_number:1", - "show_window:True", - "notes:\\x5B\\'Tile the original color image, the outlined image and the image of tracked labels together.\\'\\x5D", - "batch_state:array(\\x5B\\x5D, dtype=uint8)", - "enabled:True", - "wants_pause:False]\n"]) + result = "|".join( + [ + f"{module_name}:[module_num:{module_number}", + "svn_version:\\'Unknown\\'", + "variable_revision_number:1", + "show_window:True", + "notes:\\x5B\\'Tile the original color image, the outlined image and the image of tracked labels together.\\'\\x5D", + "batch_state:array(\\x5B\\x5D, dtype=uint8)", + "enabled:True", + "wants_pause:False]\n", + ] + ) return result def build_main_block(input_params): - result = INDENTATION.join([f"{INDENTATION}Select an input image:{get_json_value(input_params,'input_image')}\n", - f"Name the output image:{get_json_value(input_params,'output_image_name')}\n", - f"Tile assembly method:{get_json_value(input_params,'con_assembly_method.assembly_method')}\n" - ]) + result = INDENTATION.join( + [ + f"{INDENTATION}Select an input image:{get_json_value(input_params,'input_image')}\n", + f"Name the output image:{get_json_value(input_params,'output_image_name')}\n", + f"Tile assembly method:{get_json_value(input_params,'con_assembly_method.assembly_method')}\n", + ] + ) - calc_rows = get_json_value(input_params, 'con_assembly_method.con_calc_no_row.calc_no_row') + calc_rows = get_json_value( + input_params, "con_assembly_method.con_calc_no_row.calc_no_row" + ) no_of_rows = 8 - calc_cols = get_json_value(input_params, 'con_assembly_method.con_calc_no_cols.calc_no_cols') + calc_cols = get_json_value( + input_params, "con_assembly_method.con_calc_no_cols.calc_no_cols" + ) no_of_cols = 12 if calc_rows == "No": - no_of_rows = get_json_value(input_params, 'con_assembly_method.con_calc_no_row.no_of_row') + no_of_rows = get_json_value( + input_params, "con_assembly_method.con_calc_no_row.no_of_row" + ) if calc_cols == "No": - no_of_cols = get_json_value(input_params, 'con_assembly_method.con_calc_no_cols.no_of_cols') + no_of_cols = get_json_value( + input_params, "con_assembly_method.con_calc_no_cols.no_of_cols" + ) - corner_to_begin = get_json_value(input_params, 'con_assembly_method.corner_to_begin') - direction_tiling = get_json_value(input_params, 'con_assembly_method.direction') - meander = get_json_value(input_params, 'con_assembly_method.meander_mode') + corner_to_begin = get_json_value( + input_params, "con_assembly_method.corner_to_begin" + ) + direction_tiling = get_json_value(input_params, "con_assembly_method.direction") + meander = get_json_value(input_params, "con_assembly_method.meander_mode") - assembly_method = get_json_value(input_params, 'con_assembly_method.assembly_method') + assembly_method = get_json_value( + input_params, "con_assembly_method.assembly_method" + ) result += INDENTATION.join( - [f"{INDENTATION}Final number of rows:{str(no_of_rows)}\n", - f"Final number of columns:{str(no_of_cols)}\n", - f"Image corner to begin tiling:{corner_to_begin}\n", - f"Direction to begin tiling:{direction_tiling}\n", - f"Use meander mode?:{meander}\n", - f"Automatically calculate number of rows?:{calc_rows}\n", - f"Automatically calculate number of columns?:{calc_cols}\n" - ]) + [ + f"{INDENTATION}Final number of rows:{str(no_of_rows)}\n", + f"Final number of columns:{str(no_of_cols)}\n", + f"Image corner to begin tiling:{corner_to_begin}\n", + f"Direction to begin tiling:{direction_tiling}\n", + f"Use meander mode?:{meander}\n", + f"Automatically calculate number of rows?:{calc_rows}\n", + f"Automatically calculate number of columns?:{calc_cols}\n", + ] + ) if assembly_method == "Within cycles": - additionals = input_params['con_assembly_method']['rpt_additional_image'] + additionals = input_params["con_assembly_method"]["rpt_additional_image"] for img in additionals: result += INDENTATION.join( - [f"{INDENTATION}Select an additional image to tile:{get_json_value(img, 'additional_img')}\n" - ]) + [ + f"{INDENTATION}Select an additional image to tile:{get_json_value(img, 'additional_img')}\n" + ] + ) result = result.rstrip("\n") return result if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument( - '-p', '--pipeline', - help='CellProfiler pipeline' - ) - parser.add_argument( - '-i', '--inputs', - help='JSON inputs from Galaxy' - ) + parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline") + parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy") args = parser.parse_args() pipeline_lines = get_pipeline_lines(args.pipeline) |
b |
diff -r b178453ea8d1 -r 667a513e67e4 track_objects.py --- a/track_objects.py Fri Feb 26 14:19:11 2021 +0000 +++ b/track_objects.py Sun Nov 05 09:24:38 2023 +0000 |
[ |
b'@@ -3,68 +3,95 @@\n import argparse\r\n import json\r\n \r\n-from cp_common_functions import get_json_value\r\n-from cp_common_functions import get_pipeline_lines\r\n-from cp_common_functions import get_total_number_of_modules\r\n-from cp_common_functions import INDENTATION\r\n-from cp_common_functions import update_module_count\r\n-from cp_common_functions import write_pipeline\r\n+from cp_common_functions import (get_json_value,\r\n+ get_pipeline_lines,\r\n+ get_total_number_of_modules,\r\n+ INDENTATION, update_module_count,\r\n+ write_pipeline)\r\n \r\n MODULE_NAME = "TrackObjects"\r\n OUTPUT_FILENAME = "output.cppipe"\r\n \r\n \r\n def build_header(module_name, module_number):\r\n- result = "|".join([f"{module_name}:[module_num:{module_number}",\r\n- "svn_version:\\\\\'Unknown\\\\\'",\r\n- "variable_revision_number:7",\r\n- "show_window:True",\r\n- "notes:\\\\x5B\\\\\'Track the embryos across images using the Overlap method\\\\x3A tracked objects are identified by the amount of frame-to-frame overlap. Save an image of embryos labeled with a unique number across time.\\\\\'\\\\x5D",\r\n- "batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)",\r\n- "enabled:True",\r\n- "wants_pause:False]\\n"])\r\n+ result = "|".join(\r\n+ [\r\n+ f"{module_name}:[module_num:{module_number}",\r\n+ "svn_version:\\\\\'Unknown\\\\\'",\r\n+ "variable_revision_number:7",\r\n+ "show_window:True",\r\n+ "notes:\\\\x5B\\\\\'Track the embryos across images using the Overlap method\\\\x3A tracked objects are identified by the amount of frame-to-frame overlap. Save an image of embryos labeled with a unique number across time.\\\\\'\\\\x5D",\r\n+ "batch_state:array(\\\\x5B\\\\x5D, dtype=uint8)",\r\n+ "enabled:True",\r\n+ "wants_pause:False]\\n",\r\n+ ]\r\n+ )\r\n return result\r\n \r\n \r\n def build_main_block(input_params):\r\n- result = INDENTATION.join([f"{INDENTATION}Choose a tracking method:{get_json_value(input_params,\'con_tracking_method.tracking_method\')}\\n",\r\n- f"Select the objects to track:{get_json_value(input_params,\'object_to_track\')}\\n"\r\n- ])\r\n+ result = INDENTATION.join(\r\n+ [\r\n+ f"{INDENTATION}Choose a tracking method:{get_json_value(input_params,\'con_tracking_method.tracking_method\')}\\n",\r\n+ f"Select the objects to track:{get_json_value(input_params,\'object_to_track\')}\\n",\r\n+ ]\r\n+ )\r\n \r\n- tracking_method = get_json_value(input_params, \'con_tracking_method.tracking_method\')\r\n+ tracking_method = get_json_value(\r\n+ input_params, "con_tracking_method.tracking_method"\r\n+ )\r\n \r\n obj_measurement = "None" # default value\r\n if tracking_method == "Measurements":\r\n- measurement_category = get_json_value(input_params, \'con_tracking_method.con_measurement_category.measurement_category\')\r\n- measurement = get_json_value(input_params, \'con_tracking_method.con_measurement_category.measurement\')\r\n+ measurement_category = get_json_value(\r\n+ input_params,\r\n+ "con_tracking_method.con_measurement_category.measurement_category",\r\n+ )\r\n+ measurement = get_json_value(\r\n+ input_params, "con_tracking_method.con_measurement_category.measurement"\r\n+ )\r\n \r\n if measurement_category == "Intensity" or measurement_category == "Location":\r\n- img_measure = get_json_value(input_params, \'con_tracking_method.con_measurement_category.img_measure\')\r\n+ img_measure = get_json_value(\r\n+ input_params, "con_tracking_method.con_measurement_category.img_measure"\r\n+ )\r\n obj_measurement = f"{measurement_category}_{measurement}_{img_measure}"\r\n else:\r\n '..b'ax\')\r\n+ use_max = get_json_value(\r\n+ input_params,\r\n+ "con_tracking_method.con_filter_by_lifetime.con_use_max.use_max",\r\n+ )\r\n if use_max == "Yes":\r\n- max_life = get_json_value(input_params, \'con_tracking_method.con_filter_by_lifetime.con_use_max.max_lifetime\')\r\n+ max_life = get_json_value(\r\n+ input_params,\r\n+ "con_tracking_method.con_filter_by_lifetime.con_use_max.max_lifetime",\r\n+ )\r\n \r\n result += INDENTATION.join(\r\n- [f"{INDENTATION}Filter objects by lifetime?:{filter_by_lifetime}\\n",\r\n- f"Filter using a minimum lifetime?:{use_min}\\n",\r\n- f"Minimum lifetime:{min_life}\\n",\r\n- f"Filter using a maximum lifetime?:{use_max}\\n",\r\n- f"Maximum lifetime:{max_life}\\n"\r\n- ])\r\n+ [\r\n+ f"{INDENTATION}Filter objects by lifetime?:{filter_by_lifetime}\\n",\r\n+ f"Filter using a minimum lifetime?:{use_min}\\n",\r\n+ f"Minimum lifetime:{min_life}\\n",\r\n+ f"Filter using a maximum lifetime?:{use_max}\\n",\r\n+ f"Maximum lifetime:{max_life}\\n",\r\n+ ]\r\n+ )\r\n \r\n # print 2 leftover from LAP\r\n result += INDENTATION.join(\r\n- [f"{INDENTATION}Mitosis alternative cost:{mitosis_alt}\\n",\r\n- f"Maximum mitosis distance, in pixel units:{max_mitosis_dist}\\n"\r\n- ])\r\n+ [\r\n+ f"{INDENTATION}Mitosis alternative cost:{mitosis_alt}\\n",\r\n+ f"Maximum mitosis distance, in pixel units:{max_mitosis_dist}\\n",\r\n+ ]\r\n+ )\r\n \r\n # Follow Neighbors\r\n # defaults\r\n@@ -155,32 +228,36 @@\n weight_of_area_diff = 25.0\r\n \r\n if tracking_method == "Follow Neighbors":\r\n- avg_cell_diameter = get_json_value(input_params, \'con_tracking_method.avg_diameter\')\r\n- use_adv = get_json_value(input_params, \'con_tracking_method.con_adv_parameter.adv_parameter\')\r\n+ avg_cell_diameter = get_json_value(\r\n+ input_params, "con_tracking_method.avg_diameter"\r\n+ )\r\n+ use_adv = get_json_value(\r\n+ input_params, "con_tracking_method.con_adv_parameter.adv_parameter"\r\n+ )\r\n if use_adv == "Yes":\r\n- cost_of_cell = get_json_value(input_params, \'con_tracking_method.con_adv_parameter.cost\')\r\n- weight_of_area_diff = get_json_value(input_params, \'con_tracking_method.con_adv_parameter.weight\')\r\n+ cost_of_cell = get_json_value(\r\n+ input_params, "con_tracking_method.con_adv_parameter.cost"\r\n+ )\r\n+ weight_of_area_diff = get_json_value(\r\n+ input_params, "con_tracking_method.con_adv_parameter.weight"\r\n+ )\r\n \r\n result += INDENTATION.join(\r\n- [f"{INDENTATION}Average cell diameter in pixels:{avg_cell_diameter}\\n",\r\n- f"Use advanced configuration parameters:{use_adv}\\n",\r\n- f"Cost of cell to empty matching:{cost_of_cell}\\n",\r\n- f"Weight of area difference in function matching cost:{weight_of_area_diff}\\n"\r\n- ])\r\n+ [\r\n+ f"{INDENTATION}Average cell diameter in pixels:{avg_cell_diameter}\\n",\r\n+ f"Use advanced configuration parameters:{use_adv}\\n",\r\n+ f"Cost of cell to empty matching:{cost_of_cell}\\n",\r\n+ f"Weight of area difference in function matching cost:{weight_of_area_diff}\\n",\r\n+ ]\r\n+ )\r\n result = result.rstrip("\\n")\r\n return result\r\n \r\n \r\n if __name__ == "__main__":\r\n parser = argparse.ArgumentParser()\r\n- parser.add_argument(\r\n- \'-p\', \'--pipeline\',\r\n- help=\'CellProfiler pipeline\'\r\n- )\r\n- parser.add_argument(\r\n- \'-i\', \'--inputs\',\r\n- help=\'JSON inputs from Galaxy\'\r\n- )\r\n+ parser.add_argument("-p", "--pipeline", help="CellProfiler pipeline")\r\n+ parser.add_argument("-i", "--inputs", help="JSON inputs from Galaxy")\r\n args = parser.parse_args()\r\n \r\n pipeline_lines = get_pipeline_lines(args.pipeline)\r\n' |