# HG changeset patch # User bgruening # Date 1699176994 0 # Node ID 6070780813d96314ebd78c59913be38faf469cf5 # Parent 670975e9245829402c77b174edf9daa0f2a606f0 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5 diff -r 670975e92458 -r 6070780813d9 color_to_gray.py --- a/color_to_gray.py Fri Feb 26 14:09:20 2021 +0000 +++ b/color_to_gray.py Sun Nov 05 09:36:34 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 = "ColorToGray" OUTPUT_FILENAME = "output.cppipe" @@ -16,27 +15,38 @@ 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\\'Convert the color image to grayscale.\\'\\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\\'Convert the color image to grayscale.\\'\\x5D", + "batch_state:array(\\x5B\\x5D, dtype=uint8)", + "enabled:True", + "wants_pause:False]\n", + ] + ) return result def build_main_block(input_params): """Creates the main block of the CP pipeline with the parameters that don't depend on conditional choices""" - result = INDENTATION.join([f"{INDENTATION}Select the input image:{get_json_value(input_params,'name_input_image')}\n", - f"Conversion method:{get_json_value(input_params,'con_conversion_method.conversion_method')}\n", - f"Image type:{get_json_value(input_params,'con_conversion_method.con_image_type.image_type')}\n", - ]) + result = INDENTATION.join( + [ + f"{INDENTATION}Select the input image:{get_json_value(input_params,'name_input_image')}\n", + f"Conversion method:{get_json_value(input_params,'con_conversion_method.conversion_method')}\n", + f"Image type:{get_json_value(input_params,'con_conversion_method.con_image_type.image_type')}\n", + ] + ) - conversion_method = get_json_value(input_params, 'con_conversion_method.conversion_method') + conversion_method = get_json_value( + input_params, "con_conversion_method.conversion_method" + ) - image_type = get_json_value(input_params, 'con_conversion_method.con_image_type.image_type') + image_type = get_json_value( + input_params, "con_conversion_method.con_image_type.image_type" + ) rgb_comb_name_out = "OrigGray" combine_w_red = 1.0 combine_w_green = 1.0 @@ -59,88 +69,131 @@ channel_count = 1 if conversion_method == "Combine": if image_type == "RGB" or image_type == "HSV": - rgb_comb_name_out = get_json_value(input_params, 'con_conversion_method.name_output_image') - combine_w_red = get_json_value(input_params, 'con_conversion_method.con_image_type.weight_red_channel') - combine_w_green = get_json_value(input_params, 'con_conversion_method.con_image_type.weight_green_channel') - combine_w_blue = get_json_value(input_params, 'con_conversion_method.con_image_type.weight_blue_channel') + rgb_comb_name_out = get_json_value( + input_params, "con_conversion_method.name_output_image" + ) + combine_w_red = get_json_value( + input_params, "con_conversion_method.con_image_type.weight_red_channel" + ) + combine_w_green = get_json_value( + input_params, + "con_conversion_method.con_image_type.weight_green_channel", + ) + combine_w_blue = get_json_value( + input_params, "con_conversion_method.con_image_type.weight_blue_channel" + ) elif conversion_method == "Split": if image_type == "RGB": - split_red = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_red.yes_no') - red_output_name = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_red.name_output_image') - split_green = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_green.yes_no') - green_output_name = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_green.name_output_image') - split_blue = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_blue.yes_no') - blue_output_name = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_blue.name_output_image') + split_red = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_red.yes_no", + ) + red_output_name = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_red.name_output_image", + ) + split_green = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_green.yes_no", + ) + green_output_name = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_green.name_output_image", + ) + split_blue = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_blue.yes_no", + ) + blue_output_name = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_blue.name_output_image", + ) elif image_type == "HSV": - split_hue = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_hue.yes_no') - hue_output_name = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_hue.name_output_image') - split_saturation = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_saturation.yes_no') - saturation_output_name = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_saturation.name_output_image') - split_value = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_value.yes_no') - value_output_name = get_json_value(input_params, 'con_conversion_method.con_image_type.con_convert_value.name_output_image') + split_hue = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_hue.yes_no", + ) + hue_output_name = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_hue.name_output_image", + ) + split_saturation = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_saturation.yes_no", + ) + saturation_output_name = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_saturation.name_output_image", + ) + split_value = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_value.yes_no", + ) + value_output_name = get_json_value( + input_params, + "con_conversion_method.con_image_type.con_convert_value.name_output_image", + ) result += INDENTATION.join( - [f"{INDENTATION}Name the output image:{rgb_comb_name_out}\n", - f"Relative weight of the red channel:{str(combine_w_red)}\n", - f"Relative weight of the green channel:{str(combine_w_green)}\n", - f"Relative weight of the blue channel:{str(combine_w_blue)}\n", - - f"Convert red to gray?:{split_red}\n", - f"Name the output image:{red_output_name}\n", - f"Convert green to gray?:{split_green}\n", - f"Name the output image:{green_output_name}\n", - f"Convert blue to gray?:{split_blue}\n", - f"Name the output image:{blue_output_name}\n", - - f"Convert hue to gray?:{split_hue}\n", - f"Name the output image:{hue_output_name}\n", - f"Convert saturation to gray?:{split_saturation}\n", - f"Name the output image:{saturation_output_name}\n", - f"Convert value to gray?:{split_value}\n", - f"Name the output image:{value_output_name}\n" - ]) + [ + f"{INDENTATION}Name the output image:{rgb_comb_name_out}\n", + f"Relative weight of the red channel:{str(combine_w_red)}\n", + f"Relative weight of the green channel:{str(combine_w_green)}\n", + f"Relative weight of the blue channel:{str(combine_w_blue)}\n", + f"Convert red to gray?:{split_red}\n", + f"Name the output image:{red_output_name}\n", + f"Convert green to gray?:{split_green}\n", + f"Name the output image:{green_output_name}\n", + f"Convert blue to gray?:{split_blue}\n", + f"Name the output image:{blue_output_name}\n", + f"Convert hue to gray?:{split_hue}\n", + f"Name the output image:{hue_output_name}\n", + f"Convert saturation to gray?:{split_saturation}\n", + f"Name the output image:{saturation_output_name}\n", + f"Convert value to gray?:{split_value}\n", + f"Name the output image:{value_output_name}\n", + ] + ) channel_count = 1 if image_type == "Channels": - channels = input_params['con_conversion_method']['con_image_type']['rpt_channel'] + channels = input_params["con_conversion_method"]["con_image_type"][ + "rpt_channel" + ] channel_count = len(channels) - result += INDENTATION.join( - [f"{INDENTATION}Channel count:{channel_count}\n" - ]) + result += INDENTATION.join([f"{INDENTATION}Channel count:{channel_count}\n"]) for ch in channels: rel_weight_ch = 1.0 image_name = "Channel1" if conversion_method == "Combine": - rel_weight_ch = get_json_value(ch, 'weight_of_channel') + rel_weight_ch = get_json_value(ch, "weight_of_channel") else: - image_name = get_json_value(ch, 'image_name') + image_name = get_json_value(ch, "image_name") result += INDENTATION.join( - [f"{INDENTATION}Channel number:{get_json_value(ch,'channel_no')}\n", - f"Relative weight of the channel:{str(rel_weight_ch)}\n", - f"Image name:{image_name}\n" - ]) + [ + f"{INDENTATION}Channel number:{get_json_value(ch,'channel_no')}\n", + f"Relative weight of the channel:{str(rel_weight_ch)}\n", + f"Image name:{image_name}\n", + ] + ) else: result += INDENTATION.join( - [f"{INDENTATION}Channel count:{channel_count}\n", - "Channel number:Red\\x3A 1\n", - "Relative weight of the channel:1.0\n", - "Image name:Channel1\n" - ]) + [ + f"{INDENTATION}Channel count:{channel_count}\n", + "Channel number:Red\\x3A 1\n", + "Relative weight of the channel:1.0\n", + "Image name:Channel1\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) diff -r 670975e92458 -r 6070780813d9 cp_common_functions.py --- a/cp_common_functions.py Fri Feb 26 14:09:20 2021 +0000 +++ b/cp_common_functions.py Sun Nov 05 09:36:34 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 diff -r 670975e92458 -r 6070780813d9 image_math.py --- a/image_math.py Fri Feb 26 14:09:20 2021 +0000 +++ b/image_math.py Sun Nov 05 09:36:34 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) diff -r 670975e92458 -r 6070780813d9 overlay_outlines.py --- a/overlay_outlines.py Fri Feb 26 14:09:20 2021 +0000 +++ b/overlay_outlines.py Sun Nov 05 09:36:34 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) diff -r 670975e92458 -r 6070780813d9 starting_modules.py --- a/starting_modules.py Fri Feb 26 14:09:20 2021 +0000 +++ b/starting_modules.py Sun Nov 05 09:36:34 2023 +0000 @@ -9,22 +9,25 @@ def write_images(): - filter_images = params['images']['filter_images'] + filter_images = params["images"]["filter_images"] _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" _str += FOURSPACES + ":\n" _str += FOURSPACES + "Filter images?:%s\n" % filter_images - _str += FOURSPACES + "Select the rule criteria:and (extension does isimage) (directory doesnot startwith \".\")\n" + _str += ( + FOURSPACES + + 'Select the rule criteria:and (extension does isimage) (directory doesnot startwith ".")\n' + ) return _str def write_metadata(): - metadata_extraction = params['metadata']['con_metadata_extraction'] - extract = metadata_extraction['extract'] + metadata_extraction = params["metadata"]["con_metadata_extraction"] + extract = metadata_extraction["extract"] - if 'extraction_method' in metadata_extraction: - method_count = len(metadata_extraction['extraction_method']) + if "extraction_method" in metadata_extraction: + method_count = len(metadata_extraction["extraction_method"]) else: method_count = 1 @@ -35,22 +38,42 @@ _str += FOURSPACES + "Metadata data type:Text\n" _str += FOURSPACES + "Metadata types:{}\n" _str += FOURSPACES + "Extraction method count:%d\n" % method_count - _str += FOURSPACES + "Metadata extraction method:Extract from file/folder names\n" - _str += FOURSPACES + "Regular expression to extract from file name:^(?P.*)_(?P\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P\x5B0-9\x5D)_w(?P\x5B0-9\x5D)\n" - _str += FOURSPACES + "Regular expression to extract from folder name:(?P\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$\n" + _str += ( + FOURSPACES + "Metadata extraction method:Extract from file/folder names\n" + ) + _str += ( + FOURSPACES + + "Regular expression to extract from file name:^(?P.*)_(?P\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P\x5B0-9\x5D)_w(?P\x5B0-9\x5D)\n" + ) + _str += ( + FOURSPACES + + "Regular expression to extract from folder name:(?P\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$\n" + ) _str += FOURSPACES + "Extract metadata from:All images\n" - _str += FOURSPACES + "Select the filtering criteria:and (file does contain \"\")\n" + _str += ( + FOURSPACES + 'Select the filtering criteria:and (file does contain "")\n' + ) _str += FOURSPACES + "Metadata file location:\n" _str += FOURSPACES + "Match file and image metadata:\x5B\x5D\n" _str += FOURSPACES + "Use case insensitive matching?:No\n" else: - _str += FOURSPACES + "Metadata data type:Text\n" # default Text,not possible to select in Galaxy + _str += ( + FOURSPACES + "Metadata data type:Text\n" + ) # default Text,not possible to select in Galaxy _str += FOURSPACES + "Metadata types:{}\n" _str += FOURSPACES + "Extraction method count:%d\n" % method_count for methods in metadata_extraction["extraction_method"]: - _str += FOURSPACES + "Metadata extraction method:%s\n" % methods["metadata_extraction_method"] - _str += FOURSPACES + "Metadata source:%s\n" % methods["con_metadata_source"]["metadata_source"] + _str += ( + FOURSPACES + + "Metadata extraction method:%s\n" + % methods["metadata_extraction_method"] + ) + _str += ( + FOURSPACES + + "Metadata source:%s\n" + % methods["con_metadata_source"]["metadata_source"] + ) if "file_name_regex" in methods["con_metadata_source"]: file_regex = methods["con_metadata_source"]["file_name_regex"] @@ -63,24 +86,62 @@ file_regex = "(?P.*)_(?P[a-zA-Z0-9]+)" folder_regex = "(?P.*)" - _str += FOURSPACES + "Regular expression to extract from file name:%s\n" % file_regex - _str += FOURSPACES + "Regular expression to extract from folder name:%s\n" % folder_regex + _str += ( + FOURSPACES + + "Regular expression to extract from file name:%s\n" % file_regex + ) + _str += ( + FOURSPACES + + "Regular expression to extract from folder name:%s\n" % folder_regex + ) - _str += FOURSPACES + "Extract metadata from:%s\n" % methods["con_metadata_extract_from"]["extract_metadata_from"] + _str += ( + FOURSPACES + + "Extract metadata from:%s\n" + % methods["con_metadata_extract_from"]["extract_metadata_from"] + ) - if methods["con_metadata_extract_from"]["extract_metadata_from"] == "Images matching a rule": + if ( + methods["con_metadata_extract_from"]["extract_metadata_from"] + == "Images matching a rule" + ): rule_str = "" for r in methods["con_metadata_extract_from"]["r_match"]: if r["con_match"]["rule_type"] == "extension": - rule_str += " (" + r["con_match"]["rule_type"] + " " + r["con_match"]["operator"] + " " + \ - r["con_match"]["match_type"] + ")" + rule_str += ( + " (" + + r["con_match"]["rule_type"] + + " " + + r["con_match"]["operator"] + + " " + + r["con_match"]["match_type"] + + ")" + ) else: - rule_str += " (" + r["con_match"]["rule_type"] + " " + r["con_match"]["operator"] + " " +\ - r["con_match"]["contain"] + " \"" + r["con_match"]["match_value"] + "\")" + rule_str += ( + " (" + + r["con_match"]["rule_type"] + + " " + + r["con_match"]["operator"] + + " " + + r["con_match"]["contain"] + + ' "' + + r["con_match"]["match_value"] + + '")' + ) - _str += FOURSPACES + "Select the filtering criteria:" + methods["con_metadata_extract_from"]["match_all_any"] + rule_str + "\n" + _str += ( + FOURSPACES + + "Select the filtering criteria:" + + methods["con_metadata_extract_from"]["match_all_any"] + + rule_str + + "\n" + ) else: - _str += FOURSPACES + "Select the filtering criteria:and (file does contain \"\")\n" # this line is required even if it's not used + _str += ( + FOURSPACES + + 'Select the filtering criteria:and (file does contain "")\n' + ) # this line is required even if it's not used _str += FOURSPACES + "Metadata file location:\n" _str += FOURSPACES + "Match file and image metadata:\x5B\x5D\n" @@ -90,20 +151,30 @@ def write_nameandtypes(): - nameandtypes = params['nameandtypes'] - assign_a_name = nameandtypes['con_assign_a_name_to']['assign_a_name_to'] + nameandtypes = params["nameandtypes"] + assign_a_name = nameandtypes["con_assign_a_name_to"]["assign_a_name_to"] - if "con_select_image_type" in nameandtypes['con_assign_a_name_to']: - con_set_intensity = nameandtypes['con_assign_a_name_to']['con_select_image_type']['con_set_intensity'] - max_intensity = con_set_intensity['maximum_intensity'] if "maximum_intensity" in con_set_intensity else 255.0 + if "con_select_image_type" in nameandtypes["con_assign_a_name_to"]: + con_set_intensity = nameandtypes["con_assign_a_name_to"][ + "con_select_image_type" + ]["con_set_intensity"] + max_intensity = ( + con_set_intensity["maximum_intensity"] + if "maximum_intensity" in con_set_intensity + else 255.0 + ) else: max_intensity = 255.0 - pixel_space = nameandtypes['pixel_space'] + pixel_space = nameandtypes["pixel_space"] - rule_count = len(nameandtypes['con_assign_a_name_to']['r_match_rule']) if "r_match_rule" in nameandtypes['con_assign_a_name_to'] else 1 + rule_count = ( + len(nameandtypes["con_assign_a_name_to"]["r_match_rule"]) + if "r_match_rule" in nameandtypes["con_assign_a_name_to"] + else 1 + ) - process_3d = nameandtypes['pixel_space']['process_3d'] + process_3d = nameandtypes["pixel_space"]["process_3d"] x_spacing = 1.0 if "x_spacing" not in pixel_space else pixel_space["x_spacing"] y_spacing = 1.0 if "y_spacing" not in pixel_space else pixel_space["y_spacing"] z_spacing = 1.0 if "z_spacing" not in pixel_space else pixel_space["z_spacing"] @@ -113,12 +184,26 @@ _str += FOURSPACES + "Assign a name to:%s\n" % assign_a_name if assign_a_name == "All images": - _str += FOURSPACES + "Select the image type:%s\n" % nameandtypes['con_assign_a_name_to']['con_select_image_type']['select_image_type'] - _str += FOURSPACES + "Name to assign these images:%s\n" % nameandtypes['con_assign_a_name_to']['name_to_assign'] + _str += ( + FOURSPACES + + "Select the image type:%s\n" + % nameandtypes["con_assign_a_name_to"]["con_select_image_type"][ + "select_image_type" + ] + ) + _str += ( + FOURSPACES + + "Name to assign these images:%s\n" + % nameandtypes["con_assign_a_name_to"]["name_to_assign"] + ) _str += FOURSPACES + "Match metadata:[]\n" _str += FOURSPACES + "Image set matching method:Order\n" - _str += FOURSPACES + "Set intensity range from:%s\n" % con_set_intensity['set_intensity_range_from'] + _str += ( + FOURSPACES + + "Set intensity range from:%s\n" + % con_set_intensity["set_intensity_range_from"] + ) _str += FOURSPACES + "Assignments count:%s\n" % rule_count _str += FOURSPACES + "Single images count:0\n" _str += FOURSPACES + "Maximum intensity:%.1f\n" % max_intensity @@ -130,7 +215,11 @@ _str += FOURSPACES + "Name to assign these images:DNA\n" _str += FOURSPACES + "Match metadata:[]\n" - _str += FOURSPACES + "Image set matching method:%s\n" % nameandtypes['con_assign_a_name_to']['matching_method'] + _str += ( + FOURSPACES + + "Image set matching method:%s\n" + % nameandtypes["con_assign_a_name_to"]["matching_method"] + ) _str += FOURSPACES + "Set intensity range from:Image metadata\n" _str += FOURSPACES + "Assignments count:%d\n" % rule_count _str += FOURSPACES + "Single images count:0\n" @@ -147,36 +236,77 @@ rule_str = "" if len(rule["r_match"]) > 0: for r in rule["r_match"]: - if r["con_match"]["rule_type"] == "file" or r["con_match"]["rule_type"] == "directory": - rule_str += " (" + r["con_match"]["rule_type"] + " " + r["con_match"]["operator"] + " " + \ - r["con_match"]["contain"] + " \"" + r["con_match"]["match_value"] + "\")" + if ( + r["con_match"]["rule_type"] == "file" + or r["con_match"]["rule_type"] == "directory" + ): + rule_str += ( + " (" + + r["con_match"]["rule_type"] + + " " + + r["con_match"]["operator"] + + " " + + r["con_match"]["contain"] + + ' "' + + r["con_match"]["match_value"] + + '")' + ) else: - rule_str += " (" + r["con_match"]["rule_type"] + " " + r["con_match"]["operator"] + " " + \ - r["con_match"]["match_type"] + ")" + rule_str += ( + " (" + + r["con_match"]["rule_type"] + + " " + + r["con_match"]["operator"] + + " " + + r["con_match"]["match_type"] + + ")" + ) else: - rule_str = " (file does contain \"\")" # need to have a value even if it is not used + rule_str = ' (file does contain "")' # need to have a value even if it is not used - _str += FOURSPACES + "Select the rule criteria:" + rule["match_all_any"] + rule_str + "\n" + _str += ( + FOURSPACES + + "Select the rule criteria:" + + rule["match_all_any"] + + rule_str + + "\n" + ) img_or_obj = rule["con_select_image_type"]["select_image_type"] if img_or_obj == "Objects": _str += FOURSPACES + "Name to assign these images:DNA\n" - _str += FOURSPACES + "Name to assign these objects:%s\n" % rule["con_select_image_type"]["name_to_assign"] + _str += ( + FOURSPACES + + "Name to assign these objects:%s\n" + % rule["con_select_image_type"]["name_to_assign"] + ) else: - _str += FOURSPACES + "Name to assign these images:%s\n" % rule["con_select_image_type"]["name_to_assign"] + _str += ( + FOURSPACES + + "Name to assign these images:%s\n" + % rule["con_select_image_type"]["name_to_assign"] + ) _str += FOURSPACES + "Name to assign these objects:Cell\n" _str += FOURSPACES + "Select the image type:%s\n" % img_or_obj intensity_range = "Image metadata" # default value if img_or_obj == "Grayscale image" or img_or_obj == "Color image": - intensity_range = rule["con_select_image_type"]["con_set_intensity"]["set_intensity_range_from"] + intensity_range = rule["con_select_image_type"]["con_set_intensity"][ + "set_intensity_range_from" + ] _str += FOURSPACES + "Set intensity range from:%s\n" % intensity_range if intensity_range == "Manual": - _str += FOURSPACES + "Maximum intensity:%s\n" % rule["con_select_image_type"]["con_set_intensity"]["maximum_intensity"] + _str += ( + FOURSPACES + + "Maximum intensity:%s\n" + % rule["con_select_image_type"]["con_set_intensity"][ + "maximum_intensity" + ] + ) else: _str += FOURSPACES + "Maximum intensity:255.0\n" @@ -184,9 +314,9 @@ def write_groups(): - groups = params['groups'] + groups = params["groups"] - _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" + _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" group_images = groups["con_groups"]["group_images"] @@ -194,7 +324,10 @@ _str += FOURSPACES + "grouping metadata count:1\n" if group_images == "Yes": - _str += FOURSPACES + "Metadata category:%s\n" % groups["con_groups"]["group_category"] + _str += ( + FOURSPACES + + "Metadata category:%s\n" % groups["con_groups"]["group_category"] + ) else: _str += FOURSPACES + "Metadata category:None\n" @@ -202,13 +335,15 @@ with open("output.cppipe", "w") as f: - headers = ["CellProfiler Pipeline: http://www.cellprofiler.org\n", - "Version:3\n", - "DateRevision:319\n", - "GitHash:\n", - "ModuleCount:4\n", - "HasImagePlaneDetails:False", - "\n"] + headers = [ + "CellProfiler Pipeline: http://www.cellprofiler.org\n", + "Version:3\n", + "DateRevision:319\n", + "GitHash:\n", + "ModuleCount:4\n", + "HasImagePlaneDetails:False", + "\n", + ] f.writelines(headers) diff -r 670975e92458 -r 6070780813d9 starting_modules.xml --- a/starting_modules.xml Fri Feb 26 14:09:20 2021 +0000 +++ b/starting_modules.xml Sun Nov 05 09:36:34 2023 +0000 @@ -1,14 +1,22 @@ - load images and metadata into CellProfiler (Images, Metadata, NamesAndTypes, Groups) + Load images and metadata macros.xml - 1 + 2 starting_modules_images.xml starting_modules_metadata.xml starting_modules_nameandtypes.xml starting_modules_groups.xml + + operation_3443 + + + CellProfiler + cellprofiler + +