comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:99e493b2e951
1 <tool id="cp_identify_primary_objects" name="IdentifyPrimaryObjects" version="@CP_VERSION@">
2 <description>module of CellProfiler</description>
3
4 <macros>
5 <import>macros.xml</import>
6 <xml name="ipo_common">
7 <param name="input_from_nat" type="text" label="Select the input image (from NamesAndTypes)">
8 <expand macro="text_validator" />
9 </param>
10 <param name="name_to_be_identified" type="text" label="Name the primary objects to be identified">
11 <expand macro="text_validator" />
12 </param>
13 <param name="min_diameter" type="integer" label="Typical minimum diameter of objects, in pixel units (Min)" value="15" min="0" />
14 <param name="max_diameter" type="integer" label="Typical maximum diameter of objects, in pixel units (Max)" value="200" min="0" />
15 <param name="discard_outside_border" type="select" display="radio" label="Discard objects outside the diameter range?">
16 <option value="Yes">Yes</option>
17 <option value="No">No</option>
18 </param>
19 <param name="discard_touching_border" type="select" display="radio" label="Discard objects touching the border of the image?">
20 <option value="Yes">Yes</option>
21 <option value="No">No</option>
22 </param>
23 </xml>
24
25 <xml name="clumped_objects_params">
26 <conditional name="con_smoothing_filter">
27 <param name="smoothing_filter" type="select" label="Automatically calculate size of smoothing filter for decluping?">
28 <option value="Yes">Yes</option>
29 <option value="No">No</option>
30 </param>
31 <when value="No">
32 <param name="size_smoothing_filter" type="integer" label="Size of smoothing filter" value="1"/>
33 </when>
34 <when value="Yes" />
35 </conditional>
36 <conditional name="con_min_distance">
37 <param name="min_distance" type="select" label="Automatically calculate minimum allowed distance between local maxima?">
38 <option value="Yes">Yes</option>
39 <option value="No">No</option>
40 </param>
41 <when value="No">
42 <param name="min_allowed_distance" type="integer" label="Supress local maxima that are closer than this minimum allowed distance" value="1" />
43 </when>
44 <when value="Yes" />
45 </conditional>
46 <param name="speed_up" type="select" display="radio" label="Speed up by using lower-resolution image to find local maxima?">
47 <option value="Yes">Yes</option>
48 <option value="No">No</option>
49 </param>
50 </xml>
51
52 <xml name="clumped_objects">
53 <conditional name="con_dividing_lines">
54 <param name="dividing_lines" type="select" label="Method to draw dividing lines between clumped objects">
55 <option value="Intensity">Intensity</option>
56 <option value="Shape">Shape</option>
57 <option value="Propagate">Propagate</option>
58 <option value="None">None</option>
59 </param>
60 <when value="Shape">
61 <expand macro="clumped_objects_params"/>
62 </when>
63 <when value="Intensity">
64 <expand macro="clumped_objects_params"/>
65 </when>
66 <when value="Propagate"/>
67 <when value="None"/>
68 </conditional>
69 </xml>
70 </macros>
71
72 <expand macro="py_requirements"/>
73 <expand macro="cmd_modules" />
74
75 <configfiles>
76 <inputs name="inputs" />
77
78 <configfile name="script_file">
79 import json
80 import sys
81 import os
82
83 FOURSPACES=@SPACES@
84
85 input_json_path = sys.argv[1]
86 input_pipeline= sys.argv[2]
87
88 params = json.load(open(input_json_path, "r"))
89
90 ipo = params['con_advanced']
91
92 adv = params['con_advanced']['advanced']
93
94
95 def write_ipo():
96 _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
97
98 if adv == "Yes":
99 _str += FOURSPACES + "Select the input image:%s\n" % ipo['input_from_nat']
100 _str += FOURSPACES + "Name the primary objects to be identified:%s\n" % ipo['name_to_be_identified']
101 _str += FOURSPACES + "Typical diameter of objects, in pixel units (Min,Max):%d,%d\n" % (ipo['min_diameter'], ipo['max_diameter'])
102 _str += FOURSPACES + "Discard objects outside the diameter range?:%s\n" % ipo['discard_outside_border']
103 _str += FOURSPACES + "Discard objects touching the border of the image?:%s\n" % ipo['discard_touching_border']
104
105 _str += FOURSPACES + "Method to distinguish clumped objects:%s\n" % ipo['con_distinguish_clumped_objects']['distinguish_clumped_objects']
106
107 if "con_dividing_lines" in ipo['con_distinguish_clumped_objects']:
108 smoothing = ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_smoothing_filter'][
109 'smoothing_filter']
110 supress = ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_min_distance']['min_distance']
111
112 _str += FOURSPACES + "Method to draw dividing lines between clumped objects:%s\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['dividing_lines']
113
114 if smoothing == "Yes":
115 _str += FOURSPACES + "Size of smoothing filter:0\n"
116 else:
117 _str += FOURSPACES + "Size of smoothing filter:%d\n" % ipo['con_distinguish_clumped_objects']['con_dividing_lines']['con_smoothing_filter']['size_smoothing_filter']
118
119 if supress == "Yes":
120 _str += FOURSPACES + "Suppress local maxima that are closer than this minimum allowed distance:7\n"
121 else:
122 _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']
123
124 _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']
125
126 _str += FOURSPACES + "Fill holes in identified objects?:%s\n" % ipo['fill_hole']
127
128 if "con_dividing_lines" in ipo['con_distinguish_clumped_objects']:
129 _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']
130 _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']
131
132 if "con_handling_excessive" in ipo:
133 excessive = ipo['con_handling_excessive']['excessive_handling']
134
135 _str += FOURSPACES + "Handling of objects if excessive number of objects identified:%s\n" % ipo['con_handling_excessive']['excessive_handling']
136 if excessive == "Continue":
137 _str += FOURSPACES + "Maximum number of objects:500\n"
138 else:
139 _str += FOURSPACES + "Maximum number of objects:%d\n" + ipo['con_handling_excessive']['max_obj']
140
141 _str += FOURSPACES + "Use advanced settings?:%s\n" % ipo['advanced']
142 _str += FOURSPACES + "Threshold settings version:10\n"
143 _str += FOURSPACES + "Threshold strategy:%s\n" % ipo['con_threshold_strategy']['threshold_strategy']
144
145 threshold_method = ipo['con_threshold_method']['threshold_method']
146 _str += FOURSPACES + "Thresholding method:%s\n" % threshold_method
147
148 _str += FOURSPACES + "Threshold smoothing scale:%.4f\n" % ipo['threshold_smoothing_scale']
149 _str += FOURSPACES + "Threshold correction factor:%.1f\n" % ipo['threshold_correction_factor']
150 _str += FOURSPACES + "Lower and upper bounds on threshold:%.1f,%.1f\n" % (ipo['threshold_lower'], ipo['threshold_upper'])
151
152 if threshold_method == "Manual":
153 _str += FOURSPACES + "Manual threshold:%d\n" % ipo['con_threshold_method']['manual_threshold']
154 else:
155 _str += FOURSPACES + "Manual threshold:0\n"
156
157 if threshold_method == "Measurement":
158 _str += FOURSPACES + "Select the measurement to threshold with:%s\n" % ipo['con_threshold_method']['threshold_measurement']
159 else:
160 _str += FOURSPACES + "Select the measurement to threshold with:None\n"
161
162 threshold_class = ipo['con_threshold_method']['con_threshold_class']['threshold_class']
163 _str += FOURSPACES + "Two-class or three-class thresholding?:%s\n" % threshold_class
164
165 if threshold_class == "Three classes":
166 _str += FOURSPACES + "Assign pixels in the middle intensity class to the foreground or the background?:%s\n" % threshold_class['assign_pixel']
167 else:
168 _str += FOURSPACES + "Assign pixels in the middle intensity class to the foreground or the background?:Foreground\n"
169
170 if ipo['con_threshold_strategy']['threshold_strategy'] == "Adaptive":
171 _str += FOURSPACES + "Size of adaptive window:%d\n" + ipo['con_threshold_strategy']['adaptive_window']
172 else:
173 _str += FOURSPACES + "Size of adaptive window:500\n"
174
175 if threshold_method == "RobustBackground":
176 _str += FOURSPACES + "Lower outlier fraction:%.2f\n" % ipo['con_threshold_method']['lower_outlier_fraction']
177 _str += FOURSPACES + "Upper outlier fraction:%.2f\n" % ipo['con_threshold_method']['upper_outlier_fraction']
178 _str += FOURSPACES + "Averaging method:%s\n" % ipo['con_threshold_method']['avg_method']
179 _str += FOURSPACES + "Variance method:%s\n" % ['variance_method']
180 _str += FOURSPACES + "# of deviations:%.2f\n" % ipo['con_threshold_method']['no_of_deviations']
181 else:
182 _str += FOURSPACES + "Lower outlier fraction:0.05\n"
183 _str += FOURSPACES + "Upper outlier fraction:0.05\n"
184 _str += FOURSPACES + "Averaging method:Mean\n"
185 _str += FOURSPACES + "Variance method:Standard deviation\n"
186 _str += FOURSPACES + "# of deviations:2.0\n"
187
188 _str += FOURSPACES + "Thresholding method:%s\n" % threshold_method # This is a repeated entry, but needed for pipeline file
189
190 return _str
191
192
193 with open(input_pipeline) as fin:
194 lines = fin.readlines()
195
196 k, v = lines[4].strip().split(':')
197
198 module_count = int(v)
199 new_count = module_count + 1
200 lines[4] = k + ":%d\n" % new_count
201 with open("output", "w") as f:
202 f.writelines(lines)
203 f.write(write_ipo())
204
205 f.close()
206 </configfile>
207 </configfiles>
208
209 <inputs>
210 <expand macro="input_pipeline_macro" />
211 <conditional name="con_advanced">
212 <param name="advanced" type="select" display="radio" label="Use advanced settings?">
213 <option value="No">No</option>
214 <option value="Yes">Yes</option>
215 </param>
216 <when value="No">
217 <expand macro="ipo_common" />
218 </when>
219 <when value="Yes">
220 <expand macro="ipo_common" />
221 <conditional name="con_threshold_strategy">
222 <param name="threshold_strategy" type="select" label="Threshold strategy">
223 <option value="Global">Global</option>
224 <option value="Adaptive">Adaptive</option>
225 </param>
226 <when value="Adaptive">
227 <param name="adaptive_window" type="integer" label="Size of adaptive window" value="500"/>
228 </when>
229 <when value="Global" />
230 </conditional>
231 <conditional name="con_threshold_method">
232 <param name="threshold_method" type="select" label="Thresholding method">
233 <option value="Manual">Manual</option>
234 <option value="Measurement">Measurement</option>
235 <option value="Minimum cross entropy">Minimum cross entropy</option>
236 <option value="Otsu">Otsu</option>
237 <option value="RobustBackground">RobustBackground</option>
238 </param>
239 <when value="Otsu">
240 <conditional name="con_threshold_class">
241 <param name="threshold_class" type="select" label="Two-class or three-class thresholding?">
242 <option value="Two classes">Two classes</option>
243 <option value="Three classes">Three classes</option>
244 </param>
245 <when value="Three classes">
246 <param name="assign_pixel" type="select" label="Assign pixels in the middle intensity class to the foreground or the background?">
247 <option value="Foreground">Foreground</option>
248 <option value="Background">Background</option>
249 </param>
250 </when>
251 <when value="Two classes" />
252 </conditional>
253 </when>
254 <when value="Manual">
255 <param name="manual_threshold" type="integer" label="Manual threshold" value="0" />
256 </when>
257 <when value="RobustBackground">
258 <param name="lower_outlier_fraction" type="float" value="0.05" label="Lower outlier fraction" />
259 <param name="upper_outlier_fraction" type="float" value="0.05" label="Upper outlier fraction" />
260 <param name="avg_method" type="select" label="Averaging method">
261 <option value="Mean">Mean</option>
262 <option value="Median">Median</option>
263 <option value="Mode">Mode</option>
264 </param>
265 <param name="variance_method" type="select" label="Variance">
266 <option value="Standard deviation">Standard deviation</option>
267 <option value="Median absolute deviation">Median absolute deviation</option>
268 </param>
269 <param name="no_of_deviations" type="float" value="2.0" label="# of deviations" />
270 </when>
271 <when value="Measurement"/>
272 <when value="Minimum cross entropy"/>
273 </conditional>
274 <param name="threshold_smoothing_scale" type="float" value="0.0" label="Threshold smoothing scale"/>
275 <param name="threshold_correction_factor" type="float" value="0.0" label="Threshold correction factor"/>
276 <param name="threshold_lower" type="float" value="0.0" label="Lower bounds on threshold"/>
277 <param name="threshold_upper" type="float" value="1.0" label="Upper bounds on threshold"/>
278 <conditional name="con_distinguish_clumped_objects">
279 <param name="distinguish_clumped_objects" type="select" label="Method to distinguish clumped objects">
280 <option value="Shape">Shape</option>
281 <option value="Intensity">Intensity</option>
282 <option value="None">None</option>
283 </param>
284 <when value="Shape">
285 <expand macro="clumped_objects"/>
286 </when>
287 <when value="Intensity">
288 <expand macro="clumped_objects"/>
289 </when>
290 <when value="None"/>
291 </conditional>
292 <param name="fill_hole" type="select" label="Fill holes in identified objects">
293 <option value="Never">Never</option>
294 <option value="After both thresholding and declumping">After both thresholding and declumping</option>
295 <option value="After declumping only">After declumping only</option>
296 </param>
297
298 <conditional name="con_handling_excessive">
299 <param name="excessive_handling" type="select" label="Handling of objects if excessive number of objects identified">
300 <option value="Continue">Continue</option>
301 <option value="Erase">Erase</option>
302 </param>
303 <when value="Erase">
304 <param name="max_obj" type="integer" value="500" label="Maximum number of objects" />
305 </when>
306 <when value="Continue" />
307 </conditional>
308 </when>
309 </conditional>
310 </inputs>
311
312 <outputs>
313 <expand macro="output_pipeline_macro" />
314 </outputs>
315
316 <tests>
317 <test>
318 <expand macro="test_input_pipeline_param" />
319 <conditional name="con_advanced">
320 <param name="advanced" value="Yes" />
321 <param name="input_from_nat" value="DNA" />
322 <param name="name_to_be_identified" value="Nuclei" />
323 <param name="min_diameter" value="15" />
324 <param name="max_diameter" value="200" />
325 <param name="discard_outside_border" value="Yes" />
326 <param name="discard_touching_border" value="Yes" />
327 <conditional name="con_threshold_strategy">
328 <param name="threshold_strategy" value="Global" />
329 </conditional>
330 <conditional name="con_threshold_method">
331 <param name="threshold_method" value="Otsu" />
332 <conditional name="con_threshold_class" >
333 <param name="threshold_class" value="Two classes" />
334 </conditional>
335 </conditional>
336 <param name="threshold_smoothing_scale" value="1.3488" />
337 <param name="threshold_correction_factor" value="0.9" />
338 <param name="threshold_lower" value="0.0" />
339 <param name="threshold_upper" value="1.0" />
340 <conditional name="con_distinguish_clumped_objects">
341 <param name="distinguish_clumped_objects" value="Shape" />
342 <conditional name="con_dividing_lines">
343 <param name="dividing_lines" value="Shape" />
344 <conditional name="con_smoothing_filter">
345 <param name="smoothing_filter" value="Yes" />
346 </conditional>
347 <conditional name="con_min_distance">
348 <param name="min_distance" value="Yes" />
349 </conditional>
350 <param name="speed_up" value="Yes" />
351 </conditional>
352 </conditional>
353 <conditional name="con_handling_excessive">
354 <param name="excessive_handling" value="Continue" />
355 </conditional>
356 <param name="fill_hole" value="After both thresholding and declumping" />
357 </conditional>
358 <expand macro="test_out_file" file="identify_primary_objects.txt" />
359 </test>
360 </tests>
361
362 <expand macro="help" module="IdentifyPrimaryObjects"/>
363
364 <expand macro="citations" />
365
366 </tool>
367