-
Notifications
You must be signed in to change notification settings - Fork 13
/
param_utils.nf
342 lines (311 loc) · 11.3 KB
/
param_utils.nf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def default_mf_params() {
def multifish_container_repo = 'public.ecr.aws/janeliascicomp/multifish'
def default_airlocalize_params = '/app/airlocalize/params/air_localize_default_params.txt'
[
mfrepo: multifish_container_repo,
stitching_container: '',
airlocalize_container: '',
segmentation_container: '',
registration_container: '',
spots_assignment_container: '',
acq_names: '', // this is the default parameter for all acquisitions that must be processed
// should only be used when all steps must be performed for all acquisions
ref_acq: '', // reference image for registration and/or segmentation
shared_work_dir: '',
//shared_scratch_dir: "$workDir/scratch", // currently not used
local_scratch_dir: "\$PROCESS_DIR",
data_dir: '',
output_dir: '',
publish_dir: '',
skip: '', // do not skip anything by default
// download params
downloader_container: multifish_container_repo+'/downloader:1.1.0',
data_manifest: '',
verify_md5: 'true',
// stitching params
spark_container_repo: multifish_container_repo,
spark_container_name: 'stitching',
spark_container_version: '1.2.0',
stitching_app: '/app/app.jar',
stitching_output: 'stitching',
resolution: '0.23,0.23,0.42',
axis: '-x,y,z',
channels: 'c0,c1,c2,c3',
stitching_block_size: '128,128,64',
retile_z_size: 64,
stitching_mode: 'incremental',
stitching_padding: '0,0,0',
stitching_blur_sigma: '2',
stitching_czi_pattern: '', // A suffix pattern that is applied to acq_names when creating CZI names e.g. "_V%02d"
flatfield_correction: true,
with_fillBackground: true,
workers: 6,
worker_cores: 8,
gb_per_core: 15,
driver_memory: '2g',
wait_for_spark_timeout_seconds: 7200,
sleep_between_timeout_checks_seconds: 10,
dapi_channel: 'c2', // DAPI channel used to drive both the segmentation and the registration
bleed_channel: 'c3',
// spot extraction params
spot_extraction_output: 'spots',
spot_extraction_scale: 's0',
// Airlocalize params
airlocalize_xy_stride: 0, // use the default defined by airlocalize_xy_stride_param
airlocalize_xy_overlap: 0, // use the default defined by airlocalize_xy_overlap_param
airlocalize_z_stride: 0, // use the default defined by airlocalize_z_stride_param
airlocalize_z_overlap: 0, // use the default defined by airlocalize_z_overlap_param
default_airlocalize_params: default_airlocalize_params,
per_channel_air_localize_params: ",,,",
airlocalize_cpus: 1,
airlocalize_memory: '2 G',
// RS-Fish params
use_rsfish: false,
rsfish_container_repo: multifish_container_repo,
rsfish_container_name: 'rs_fish',
rsfish_container_version: '1.0.2',
rs_fish_app: '/app/app.jar',
rsfish_workers: 6,
rsfish_worker_cores: 8,
rsfish_gb_per_core: 15,
rsfish_driver_cores: 1,
rsfish_driver_memory: '1g',
rsfish_min: 0,
rsfish_max: 4096,
rsfish_anisotropy: 0.7,
rsfish_sigma: 1.5,
rsfish_threshold: 0.007,
rsfish_background: 0,
rsfish_intensity: 0,
rsfish_params: '',
// RS-Fish parameters adjustable per channel
per_channel: [
rsfish_min: '',
rsfish_max: '',
rsfish_anisotropy: '',
rsfish_sigma: '',
rsfish_threshold: '',
rsfish_background: '',
rsfish_intensity: '',
],
// segmentation params
segmentation_output: 'segmentation',
segmentation_model_dir: "${projectDir}/external-modules/segmentation/model/starfinity",
segmentation_scale: 's2',
segmentation_cpus: 30,
segmentation_memory: '220 G',
// registration params
registration_fixed_output: 'fixed',
registration_output: 'registration',
aff_scale: 's3', // the scale level for affine alignments
def_scale: "s2", // the scale level for deformable alignments
registration_xy_stride: 0, // use the default defined by registration_xy_stride_param - must be a power of 2
registration_xy_overlap: 0, // use the default defined by registration_xy_overlap_param
registration_z_stride: 0, // use the default defined by registration_z_stride_param - must be a power of 2
registration_z_overlap: 0, // use the default defined by registration_z_overlap_param
spots_cc_radius: 8,
spots_spot_number: 2000,
// ransac params
ransac_cc_cutoff: 0.9,
ransac_dist_threshold: 2.5,
// deformation parameters
deform_iterations: '500x200x25x1',
deform_auto_mask: '0',
// compute resources
ransac_cpus: 1,
ransac_memory: '1 G',
spots_cpus: 1,
spots_memory: '2 G',
interpolate_cpus: 1,
interpolate_memory: '1 G',
coarse_spots_cpus: 1,
coarse_spots_memory: '8 G',
aff_scale_transform_cpus: 1, // cores for affine scale transforms
aff_scale_transform_memory: '15 G',
def_scale_transform_cpus: 8, // cores for deformable scale transforms
def_scale_transform_memory: '80 G',
deform_cpus: 1,
deform_memory: '4 G',
registration_stitch_cpus: 2,
registration_stitch_memory: '20 G',
registration_transform_cpus: 12,
registration_transform_memory: '120 G',
// warp spots parameters
warp_spots_cpus: 3,
warp_spots_memory: '60 G',
// intensity measurement parameters
measure_intensities_output: 'intensities',
measure_intensities_cpus: 1,
measure_intensities_memory: '50 G',
// spot assignment parameters
assign_spots_output: 'assignments',
assign_spots_cpus: 1,
assign_spots_memory: '15 G',
]
}
def set_derived_defaults(mf_params, user_params) {
if (mf_params.shared_work_dir) {
if (!user_params.containsKey('data_dir')) {
mf_params.data_dir = "${mf_params.shared_work_dir}/inputs"
}
if (!user_params.containsKey('output_dir')) {
mf_params.output_dir = "${mf_params.shared_work_dir}/outputs"
}
if (!user_params.containsKey('segmentation_model_dir')) {
mf_params.segmentation_model_dir = "${mf_params.shared_work_dir}/inputs/model/starfinity"
}
if (!user_params.containsKey('spark_work_dir')) {
mf_params.spark_work_dir = "${mf_params.shared_work_dir}/spark"
}
if (!user_params.containsKey('singularity_cache_dir')) {
mf_params.singularity_cache_dir = "${mf_params.shared_work_dir}/singularity"
}
}
mf_params
}
def get_value_or_default(Map ps, String param, String default_value) {
if (ps[param])
ps[param]
else
default_value
}
def get_list_or_default(Map ps, String param, List default_list) {
def source_value = ps[param]
if (source_value == null) {
return default_list
} else if (source_value instanceof Boolean) {
// most likely the parameter was set as '--param'
// followed by no value
return default_list
} else if (source_value instanceof String) {
if (source_value.trim() == '') {
return default_list
} else {
return source_value.tokenize(',').collect { it.trim() }
}
} else {
// this is the case in which a parameter was set to a numeric value,
// e.g., "--param 1000" or "--param 20.3"
return [source_value]
}
}
def stitching_container_param(Map ps) {
def stitching_container = ps.stitching_container
if (!stitching_container)
"${ps.mfrepo}/stitching:1.1.0"
else
stitching_container
}
def airlocalize_container_param(Map ps) {
def spot_extraction_container = ps.spot_extraction_container
if (!spot_extraction_container)
"${ps.mfrepo}/spot_extraction:1.2.0"
else
airlocalize_container
}
def segmentation_container_param(Map ps) {
def segmentation_container = ps.segmentation_container
if (!segmentation_container)
"${ps.mfrepo}/segmentation:1.0.0"
else
segmentation_container
}
def registration_container_param(Map ps) {
def registration_container = ps.registration_container
if (!registration_container)
"${ps.mfrepo}/registration:1.2.3"
else
registration_container
}
def spots_assignment_container_param(Map ps) {
def spots_assignment_container = ps.spots_assignment_container
if (!spots_assignment_container)
"${ps.mfrepo}/spot_assignment:1.3.0"
else
spots_assignment_container
}
/**
* Get the stitching ref channel or if not specified use dapi_channel.
* Also extracts only the numeric part from the channel since that's
* how the stitching pipeline expects it.
*/
def stitching_ref_param(Map ps) {
def stitching_ref = ps.stitching_ref
? ps.stitching_ref
: ps.dapi_channel
if (stitching_ref=="all") {
return ''
}
def ch_num_lookup = (stitching_ref =~ /(\d+)/)
if (ch_num_lookup.find()) {
return ch_num_lookup[0][1]
} else {
return ''
}
}
def airlocalize_xy_stride_param(Map ps) {
def airlocalize_xy_stride = ps.airlocalize_xy_stride
if (!airlocalize_xy_stride) {
return 1024
} else {
return airlocalize_xy_stride
}
}
def airlocalize_xy_overlap_param(Map ps) {
def airlocalize_xy_overlap = ps.airlocalize_xy_overlap
if (!airlocalize_xy_overlap) {
airlocalize_xy_overlap = (int) (0.05 * airlocalize_xy_stride_param(ps))
return airlocalize_xy_overlap < 50 ? 50 : airlocalize_xy_overlap
} else {
return airlocalize_xy_overlap
}
}
def airlocalize_z_stride_param(Map ps) {
def airlocalize_z_stride = ps.airlocalize_z_stride
if (!airlocalize_z_stride) {
return 512
} else {
return airlocalize_z_stride
}
}
def airlocalize_z_overlap_param(Map ps) {
def airlocalize_z_overlap = ps.airlocalize_z_overlap
if (!airlocalize_z_overlap) {
airlocalize_z_overlap = (int) (0.05 * airlocalize_z_stride_param(ps))
return airlocalize_z_overlap < 50 ? 50 : airlocalize_z_overlap
} else {
return airlocalize_z_overlap
}
}
def registration_xy_stride_param(Map ps) {
def registration_xy_stride = ps.registration_xy_stride
if (!registration_xy_stride) {
return 256
} else {
return registration_xy_stride
}
}
def registration_xy_overlap_param(Map ps) {
def registration_xy_overlap = ps.registration_xy_overlap
if (!registration_xy_overlap) {
return (int) (registration_xy_stride_param(ps) / 8)
} else {
return registration_xy_overlap
}
}
def registration_z_stride_param(Map ps) {
def registration_z_stride = ps.registration_z_stride
if (!registration_z_stride) {
return 256
} else {
return registration_z_stride
}
}
def registration_z_overlap_param(Map ps) {
def registration_z_overlap = ps.registration_z_overlap
if (!registration_z_overlap) {
return (int) (registration_z_stride_param(ps) / 8)
} else {
return registration_z_overlap
}
}