Mercurial > repos > bgruening > cp_identify_primary_objects
diff identify_primary_objects.xml @ 0:99e493b2e951 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 6d73056a625002d0275b5a9a90a9fae329ce47f1"
author | bgruening |
---|---|
date | Thu, 26 Mar 2020 16:57:05 -0400 |
parents | |
children | d9bf32d13dfd |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/identify_primary_objects.xml Thu Mar 26 16:57:05 2020 -0400 @@ -0,0 +1,367 @@ +<tool id="cp_identify_primary_objects" name="IdentifyPrimaryObjects" version="@CP_VERSION@"> + <description>module of CellProfiler</description> + + <macros> + <import>macros.xml</import> + <xml name="ipo_common"> + <param name="input_from_nat" type="text" label="Select the input image (from NamesAndTypes)"> + <expand macro="text_validator" /> + </param> + <param name="name_to_be_identified" type="text" label="Name the primary objects to be identified"> + <expand macro="text_validator" /> + </param> + <param name="min_diameter" type="integer" label="Typical minimum diameter of objects, in pixel units (Min)" value="15" min="0" /> + <param name="max_diameter" type="integer" label="Typical maximum diameter of objects, in pixel units (Max)" value="200" min="0" /> + <param name="discard_outside_border" type="select" display="radio" label="Discard objects outside the diameter range?"> + <option value="Yes">Yes</option> + <option value="No">No</option> + </param> + <param name="discard_touching_border" type="select" display="radio" label="Discard objects touching the border of the image?"> + <option value="Yes">Yes</option> + <option value="No">No</option> + </param> + </xml> + + <xml name="clumped_objects_params"> + <conditional name="con_smoothing_filter"> + <param name="smoothing_filter" type="select" label="Automatically calculate size of smoothing filter for decluping?"> + <option value="Yes">Yes</option> + <option value="No">No</option> + </param> + <when value="No"> + <param name="size_smoothing_filter" type="integer" label="Size of smoothing filter" value="1"/> + </when> + <when value="Yes" /> + </conditional> + <conditional name="con_min_distance"> + <param name="min_distance" type="select" label="Automatically calculate minimum allowed distance between local maxima?"> + <option value="Yes">Yes</option> + <option value="No">No</option> + </param> + <when value="No"> + <param name="min_allowed_distance" type="integer" label="Supress local maxima that are closer than this minimum allowed distance" value="1" /> + </when> + <when value="Yes" /> + </conditional> + <param name="speed_up" type="select" display="radio" label="Speed up by using lower-resolution image to find local maxima?"> + <option value="Yes">Yes</option> + <option value="No">No</option> + </param> + </xml> + + <xml name="clumped_objects"> + <conditional name="con_dividing_lines"> + <param name="dividing_lines" type="select" label="Method to draw dividing lines between clumped objects"> + <option value="Intensity">Intensity</option> + <option value="Shape">Shape</option> + <option value="Propagate">Propagate</option> + <option value="None">None</option> + </param> + <when value="Shape"> + <expand macro="clumped_objects_params"/> + </when> + <when value="Intensity"> + <expand macro="clumped_objects_params"/> + </when> + <when value="Propagate"/> + <when value="None"/> + </conditional> + </xml> + </macros> + + <expand macro="py_requirements"/> + <expand macro="cmd_modules" /> + + <configfiles> + <inputs name="inputs" /> + + <configfile name="script_file"> +import json +import sys +import os + +FOURSPACES=@SPACES@ + +input_json_path = sys.argv[1] +input_pipeline= sys.argv[2] + +params = json.load(open(input_json_path, "r")) + +ipo = params['con_advanced'] + +adv = params['con_advanced']['advanced'] + + +def write_ipo(): + _str = "\nIdentifyPrimaryObjects:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:13|show_window:True|notes:\\x5B\\'Identify the nuclei from the DNA channel.\\', \\'PARAMS\\x3A\\', \\'- Typical diameter of objects (Min,Max)\\', \\'- Method to distinguish clumped objects\\x3A Shape/None. With Shape, the distance between the 2 centers can be changed.\\'\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count + + if adv == "Yes": + _str += FOURSPACES + "Select the input image:%s\n" % ipo['input_from_nat'] + _str += FOURSPACES + "Name the primary objects to be identified:%s\n" % ipo['name_to_be_identified'] + _str += FOURSPACES + "Typical diameter of objects, in pixel units (Min,Max):%d,%d\n" % (ipo['min_diameter'], ipo['max_diameter']) + _str += FOURSPACES + "Discard objects outside the diameter range?:%s\n" % ipo['discard_outside_border'] + _str += FOURSPACES + "Discard objects touching the border of the image?:%s\n" % ipo['discard_touching_border'] + + _str += FOURSPACES + "Method to distinguish clumped objects:%s\n" % ipo['con_distinguish_clumped_objects']['distinguish_clumped_objects'] + + if "con_dividing_lines" in ipo['con_distinguish_clumped_objects']: + smoothing = ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_smoothing_filter'][ + 'smoothing_filter'] + supress = ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_min_distance']['min_distance'] + + _str += FOURSPACES + "Method to draw dividing lines between clumped objects:%s\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['dividing_lines'] + + if smoothing == "Yes": + _str += FOURSPACES + "Size of smoothing filter:0\n" + else: + _str += FOURSPACES + "Size of smoothing filter:%d\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_smoothing_filter']['size_smoothing_filter'] + + if supress == "Yes": + _str += FOURSPACES + "Suppress local maxima that are closer than this minimum allowed distance:7\n" + else: + _str += FOURSPACES + "Suppress local maxima that are closer than this minimum allowed distance:%d\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_min_distance']['min_allowed_distance'] + + _str += FOURSPACES + "Speed up by using lower-resolution image to find local maxima?:%s\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['speed_up'] + + _str += FOURSPACES + "Fill holes in identified objects?:%s\n" % ipo['fill_hole'] + + if "con_dividing_lines" in ipo['con_distinguish_clumped_objects']: + _str += FOURSPACES + "Automatically calculate size of smoothing filter for declumping?:%s\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_smoothing_filter']['smoothing_filter'] + _str += FOURSPACES + "Automatically calculate minimum allowed distance between local maxima?:%s\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_min_distance']['min_distance'] + + if "con_handling_excessive" in ipo: + excessive = ipo['con_handling_excessive']['excessive_handling'] + + _str += FOURSPACES + "Handling of objects if excessive number of objects identified:%s\n" % ipo['con_handling_excessive']['excessive_handling'] + if excessive == "Continue": + _str += FOURSPACES + "Maximum number of objects:500\n" + else: + _str += FOURSPACES + "Maximum number of objects:%d\n" + ipo['con_handling_excessive']['max_obj'] + + _str += FOURSPACES + "Use advanced settings?:%s\n" % ipo['advanced'] + _str += FOURSPACES + "Threshold settings version:10\n" + _str += FOURSPACES + "Threshold strategy:%s\n" % ipo['con_threshold_strategy']['threshold_strategy'] + + threshold_method = ipo['con_threshold_method']['threshold_method'] + _str += FOURSPACES + "Thresholding method:%s\n" % threshold_method + + _str += FOURSPACES + "Threshold smoothing scale:%.4f\n" % ipo['threshold_smoothing_scale'] + _str += FOURSPACES + "Threshold correction factor:%.1f\n" % ipo['threshold_correction_factor'] + _str += FOURSPACES + "Lower and upper bounds on threshold:%.1f,%.1f\n" % (ipo['threshold_lower'], ipo['threshold_upper']) + + if threshold_method == "Manual": + _str += FOURSPACES + "Manual threshold:%d\n" % ipo['con_threshold_method']['manual_threshold'] + else: + _str += FOURSPACES + "Manual threshold:0\n" + + if threshold_method == "Measurement": + _str += FOURSPACES + "Select the measurement to threshold with:%s\n" % ipo['con_threshold_method']['threshold_measurement'] + else: + _str += FOURSPACES + "Select the measurement to threshold with:None\n" + + threshold_class = ipo['con_threshold_method']['con_threshold_class']['threshold_class'] + _str += FOURSPACES + "Two-class or three-class thresholding?:%s\n" % threshold_class + + if threshold_class == "Three classes": + _str += FOURSPACES + "Assign pixels in the middle intensity class to the foreground or the background?:%s\n" % threshold_class['assign_pixel'] + else: + _str += FOURSPACES + "Assign pixels in the middle intensity class to the foreground or the background?:Foreground\n" + + if ipo['con_threshold_strategy']['threshold_strategy'] == "Adaptive": + _str += FOURSPACES + "Size of adaptive window:%d\n" + ipo['con_threshold_strategy']['adaptive_window'] + else: + _str += FOURSPACES + "Size of adaptive window:500\n" + + if threshold_method == "RobustBackground": + _str += FOURSPACES + "Lower outlier fraction:%.2f\n" % ipo['con_threshold_method']['lower_outlier_fraction'] + _str += FOURSPACES + "Upper outlier fraction:%.2f\n" % ipo['con_threshold_method']['upper_outlier_fraction'] + _str += FOURSPACES + "Averaging method:%s\n" % ipo['con_threshold_method']['avg_method'] + _str += FOURSPACES + "Variance method:%s\n" % ['variance_method'] + _str += FOURSPACES + "# of deviations:%.2f\n" % ipo['con_threshold_method']['no_of_deviations'] + else: + _str += FOURSPACES + "Lower outlier fraction:0.05\n" + _str += FOURSPACES + "Upper outlier fraction:0.05\n" + _str += FOURSPACES + "Averaging method:Mean\n" + _str += FOURSPACES + "Variance method:Standard deviation\n" + _str += FOURSPACES + "# of deviations:2.0\n" + + _str += FOURSPACES + "Thresholding method:%s\n" % threshold_method # This is a repeated entry, but needed for pipeline file + + return _str + + +with open(input_pipeline) as fin: + lines = fin.readlines() + + k, v = lines[4].strip().split(':') + + module_count = int(v) + new_count = module_count + 1 + lines[4] = k + ":%d\n" % new_count + with open("output", "w") as f: + f.writelines(lines) + f.write(write_ipo()) + +f.close() + </configfile> + </configfiles> + + <inputs> + <expand macro="input_pipeline_macro" /> + <conditional name="con_advanced"> + <param name="advanced" type="select" display="radio" label="Use advanced settings?"> + <option value="No">No</option> + <option value="Yes">Yes</option> + </param> + <when value="No"> + <expand macro="ipo_common" /> + </when> + <when value="Yes"> + <expand macro="ipo_common" /> + <conditional name="con_threshold_strategy"> + <param name="threshold_strategy" type="select" label="Threshold strategy"> + <option value="Global">Global</option> + <option value="Adaptive">Adaptive</option> + </param> + <when value="Adaptive"> + <param name="adaptive_window" type="integer" label="Size of adaptive window" value="500"/> + </when> + <when value="Global" /> + </conditional> + <conditional name="con_threshold_method"> + <param name="threshold_method" type="select" label="Thresholding method"> + <option value="Manual">Manual</option> + <option value="Measurement">Measurement</option> + <option value="Minimum cross entropy">Minimum cross entropy</option> + <option value="Otsu">Otsu</option> + <option value="RobustBackground">RobustBackground</option> + </param> + <when value="Otsu"> + <conditional name="con_threshold_class"> + <param name="threshold_class" type="select" label="Two-class or three-class thresholding?"> + <option value="Two classes">Two classes</option> + <option value="Three classes">Three classes</option> + </param> + <when value="Three classes"> + <param name="assign_pixel" type="select" label="Assign pixels in the middle intensity class to the foreground or the background?"> + <option value="Foreground">Foreground</option> + <option value="Background">Background</option> + </param> + </when> + <when value="Two classes" /> + </conditional> + </when> + <when value="Manual"> + <param name="manual_threshold" type="integer" label="Manual threshold" value="0" /> + </when> + <when value="RobustBackground"> + <param name="lower_outlier_fraction" type="float" value="0.05" label="Lower outlier fraction" /> + <param name="upper_outlier_fraction" type="float" value="0.05" label="Upper outlier fraction" /> + <param name="avg_method" type="select" label="Averaging method"> + <option value="Mean">Mean</option> + <option value="Median">Median</option> + <option value="Mode">Mode</option> + </param> + <param name="variance_method" type="select" label="Variance"> + <option value="Standard deviation">Standard deviation</option> + <option value="Median absolute deviation">Median absolute deviation</option> + </param> + <param name="no_of_deviations" type="float" value="2.0" label="# of deviations" /> + </when> + <when value="Measurement"/> + <when value="Minimum cross entropy"/> + </conditional> + <param name="threshold_smoothing_scale" type="float" value="0.0" label="Threshold smoothing scale"/> + <param name="threshold_correction_factor" type="float" value="0.0" label="Threshold correction factor"/> + <param name="threshold_lower" type="float" value="0.0" label="Lower bounds on threshold"/> + <param name="threshold_upper" type="float" value="1.0" label="Upper bounds on threshold"/> + <conditional name="con_distinguish_clumped_objects"> + <param name="distinguish_clumped_objects" type="select" label="Method to distinguish clumped objects"> + <option value="Shape">Shape</option> + <option value="Intensity">Intensity</option> + <option value="None">None</option> + </param> + <when value="Shape"> + <expand macro="clumped_objects"/> + </when> + <when value="Intensity"> + <expand macro="clumped_objects"/> + </when> + <when value="None"/> + </conditional> + <param name="fill_hole" type="select" label="Fill holes in identified objects"> + <option value="Never">Never</option> + <option value="After both thresholding and declumping">After both thresholding and declumping</option> + <option value="After declumping only">After declumping only</option> + </param> + + <conditional name="con_handling_excessive"> + <param name="excessive_handling" type="select" label="Handling of objects if excessive number of objects identified"> + <option value="Continue">Continue</option> + <option value="Erase">Erase</option> + </param> + <when value="Erase"> + <param name="max_obj" type="integer" value="500" label="Maximum number of objects" /> + </when> + <when value="Continue" /> + </conditional> + </when> + </conditional> + </inputs> + + <outputs> + <expand macro="output_pipeline_macro" /> + </outputs> + + <tests> + <test> + <expand macro="test_input_pipeline_param" /> + <conditional name="con_advanced"> + <param name="advanced" value="Yes" /> + <param name="input_from_nat" value="DNA" /> + <param name="name_to_be_identified" value="Nuclei" /> + <param name="min_diameter" value="15" /> + <param name="max_diameter" value="200" /> + <param name="discard_outside_border" value="Yes" /> + <param name="discard_touching_border" value="Yes" /> + <conditional name="con_threshold_strategy"> + <param name="threshold_strategy" value="Global" /> + </conditional> + <conditional name="con_threshold_method"> + <param name="threshold_method" value="Otsu" /> + <conditional name="con_threshold_class" > + <param name="threshold_class" value="Two classes" /> + </conditional> + </conditional> + <param name="threshold_smoothing_scale" value="1.3488" /> + <param name="threshold_correction_factor" value="0.9" /> + <param name="threshold_lower" value="0.0" /> + <param name="threshold_upper" value="1.0" /> + <conditional name="con_distinguish_clumped_objects"> + <param name="distinguish_clumped_objects" value="Shape" /> + <conditional name="con_dividing_lines"> + <param name="dividing_lines" value="Shape" /> + <conditional name="con_smoothing_filter"> + <param name="smoothing_filter" value="Yes" /> + </conditional> + <conditional name="con_min_distance"> + <param name="min_distance" value="Yes" /> + </conditional> + <param name="speed_up" value="Yes" /> + </conditional> + </conditional> + <conditional name="con_handling_excessive"> + <param name="excessive_handling" value="Continue" /> + </conditional> + <param name="fill_hole" value="After both thresholding and declumping" /> + </conditional> + <expand macro="test_out_file" file="identify_primary_objects.txt" /> + </test> + </tests> + + <expand macro="help" module="IdentifyPrimaryObjects"/> + + <expand macro="citations" /> + +</tool> +