-
Notifications
You must be signed in to change notification settings - Fork 1
/
stitch_pipeline.nf
executable file
·171 lines (154 loc) · 5.88 KB
/
stitch_pipeline.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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
include {
stitching_spark_params;
} from './params/stitching_params'
include {
default_em_params;
get_value_or_default;
get_list_or_default;
deconvolution_container_param;
stitching_container_param;
} from './param_utils'
// app parameters
def default_params = default_em_params(params)
def final_params = default_params +
stitching_spark_params(default_params) +
[
stitching_container: stitching_container_param(default_params),
deconvolution_container: deconvolution_container_param(default_params),
]
include {
prepare_stitching_data;
} from './processes/stitching' addParams(final_params)
include {
prepare_tiles_for_stitching as prestitching;
} from './workflows/prestitching' addParams(final_params)
include {
stitching;
} from './workflows/stitching' addParams(final_params)
include {
deconvolution
} from './workflows/deconvolution' addParams(final_params)
workflow {
def images_dir = get_value_or_default(final_params, 'images_dir', final_params.input_dir)
def pipeline_output_dir = get_value_or_default(final_params, 'output_dir', images_dir)
def stitching_dir = final_params.stitching_output
? "${pipeline_output_dir}/${final_params.stitching_output}"
: pipeline_output_dir
def channels = get_list_or_default(final_params, 'channels', [])
def skip = get_list_or_default(final_params, 'skip', [])
// deconvolution params
def iterations_per_channel = get_list_or_default(final_params, 'iterations_per_channel', [])
.collect {
it as int
}
def channels_psfs = channels.collect {
def ch = it.replace('nm', '')
return "${final_params.psf_dir}/${ch}_PSF.tif"
}
log.info """
channels: ${channels}
skipped_steps: ${skip}
spark_workers: ${final_params.workers}
""".stripIndent()
def stitching_data = prepare_stitching_data(
Channel.of(images_dir),
Channel.of(stitching_dir),
Channel.of(final_params.spark_work_dir)
) // [ input_images_dir, stitching_dir, stitching_working_dir ]
stitching_data.subscribe { log.debug "Stitching: $it" }
def pre_stitching_res
if (skip.contains('prestitching')) {
// skip prestitching
pre_stitching_res = stitching_data
| map {
def (input_images_dir, stitching_dirname) = it
[ input_images_dir, stitching_dirname ]
}
} else {
pre_stitching_res = prestitching(
stitching_data.map { it[0] }, // images dir
stitching_data.map { it[1] }, // stitching dir
channels,
final_params.resolution,
final_params.axis,
final_params.block_size,
final_params.app, // app.jar location
final_params.spark_conf,
stitching_data.map { "${it[2]}/prestitch" }, // spark_working_dir
final_params.workers,
final_params.worker_cores,
final_params.gb_per_core,
final_params.driver_cores,
final_params.driver_memory,
final_params.driver_stack_size,
final_params.driver_logconfig
) // [ input_images_dir, stitching_dir ]
pre_stitching_res.subscribe { log.debug "Pre stitch results: $it" }
}
def stitching_input
if (skip.contains('deconvolution')) {
// skip deconvolution
stitching_input = stitching_data
| join(pre_stitching_res, by:[0,1])
| map {
def (input_images_dir, stitching_dirname, stitching_working_dir) = it
def stitching_dir_file = file(stitching_dirname)
def stitching_working_dir_file = file(stitching_working_dir)
def r = [ "${stitching_dir_file}", "${stitching_working_dir_file}" ]
log.info "Prepare stitching input: $r"
r
}
} else {
def deconv_res = deconvolution(
pre_stitching_res.map { it[1] }, // stitching_dir
channels,
channels_psfs,
iterations_per_channel
)
| groupTuple(by: 1) // groupBy input_dir
| map {
[
it[1], // stitching_dir
it[0], // channels
it[2] // deconv_res
]
}
deconv_res | view
stitching_input = stitching_data
| map {
def (stitching_dirname, stitching_working_dir) = it[1..2] // [ stitching_dir, stitching_work_dir ]
def stitching_dir_file = file(stitching_dirname)
def stitching_working_dir_file = file(stitching_working_dir)
def r = [ "${stitching_dir_file}", "${stitching_working_dir_file}" ]
log.info "Prepare stitching input: $r"
r
}
| join(deconv_res, by: 0) // [ stitching_dir, stitching_work_dir, channels, deconv_json_res ]
stitching_input | view
}
if (!skip.contains('stitch') || !skip.contains('fuse') || !skip.contains('tiff-export')) {
def stitching_res = stitching(
stitching_input.map { it[0] }, // stitching_dir
channels,
final_params.stitching_mode,
final_params.stitching_padding,
final_params.stitching_blur_sigma,
final_params.export_level,
final_params.allow_fusestage,
skip,
final_params.app, // app.jar location
final_params.spark_conf,
stitching_input.map { "${it[1]}/stitch" }, // spark working dir
final_params.workers,
final_params.worker_cores,
final_params.gb_per_core,
final_params.driver_cores,
final_params.driver_memory,
final_params.driver_stack_size,
final_params.driver_logconfig
)
stitching_res | view
}
}