-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_workflow.nf
executable file
·299 lines (251 loc) · 8.81 KB
/
default_workflow.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
nextflow.enable.dsl=2
// The values are assigned inside the batch script
// Based on internal values and options provided in the request
params.input_file_group = "null"
params.mets = "null"
params.workspace_dir = "null"
// amount of pages of the workspace
params.pages = "null"
params.singularity_wrapper = "null"
params.cpus = "null"
params.ram = "null"
params.forks = params.cpus
// Do not pass these parameters from the caller unless you know what you are doing
params.cpus_per_fork = (params.cpus.toInteger() / params.forks.toInteger()).intValue()
params.ram_per_fork = sprintf("%dGB", (params.ram.toInteger() / params.forks.toInteger()).intValue())
log.info """\
OPERANDI - HPC - Default Workflow
===========================================
input_file_group : ${params.input_file_group}
mets : ${params.mets}
workspace_dir : ${params.workspace_dir}
pages : ${params.pages}
singularity_wrapper : ${params.singularity_wrapper}
cpus : ${params.cpus}
ram : ${params.ram}
forks : ${params.forks}
cpus_per_fork : ${params.cpus_per_fork}
ram_per_fork : ${params.ram_per_fork}
"""
.stripIndent()
process split_page_ranges {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val range_multiplier
output:
env mets_file_chunk
env current_range_pages
script:
"""
current_range_pages=\$(${params.singularity_wrapper} ocrd workspace -d ${params.workspace_dir} list-page -f comma-separated -D ${params.forks} -C ${range_multiplier})
echo "Current range is: \$current_range_pages"
mets_file_chunk=\$(echo ${params.workspace_dir}/mets_${range_multiplier}.xml)
echo "Mets file chunk path: \$mets_file_chunk"
\$(${params.singularity_wrapper} cp -p ${params.mets} \$mets_file_chunk)
"""
}
process ocrd_cis_ocropy_binarize {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-cis-ocropy-binarize -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group}
"""
}
process ocrd_anybaseocr_crop {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-anybaseocr-crop -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group}
"""
}
process ocrd_skimage_binarize {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-skimage-binarize -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group} -p '{"method": "li"}'
"""
}
process ocrd_skimage_denoise {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-skimage-denoise -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group} -p '{"level-of-operation": "page"}'
"""
}
process ocrd_tesserocr_deskew {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-tesserocr-deskew -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group} -p '{"operation_level": "page"}'
"""
}
process ocrd_cis_ocropy_segment {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-cis-ocropy-segment -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group} -p '{"level-of-operation": "page"}'
"""
}
process ocrd_cis_ocropy_dewarp {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-cis-ocropy-dewarp -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group}
"""
}
process ocrd_calamari_recognize {
maxForks params.forks
cpus params.cpus_per_fork
memory params.ram_per_fork
debug true
input:
val mets_file_chunk
val page_range
val input_group
val output_group
output:
val mets_file_chunk
val page_range
script:
"""
${params.singularity_wrapper} ocrd-calamari-recognize -w ${params.workspace_dir} -m ${mets_file_chunk} --page-id ${page_range} -I ${input_group} -O ${output_group} -p '{"checkpoint_dir": "/ocrd-models/qurator-gt4histocr-1"}'
"""
}
process ocrd_page_transform {
maxForks 1
input:
val mets_file
val in_put
val input_group
val output_group
output:
val mets_file
script:
"""
${params.singularity_wrapper} ocrd-page-transform -w ${params.workspace_dir} -m ${mets_file} -I ${input_group} -O ${output_group} -P xsl page-remove-regions.xsl -P xslt-params "-s type=ImageRegion"
"""
}
process ocrd_fileformat_transform {
maxForks 1
input:
val mets_file
val input_group
val output_group
output:
val mets_file
script:
"""
${params.singularity_wrapper} ocrd-fileformat-transform -w ${params.workspace_dir} -m ${mets_file} -I ${input_group} -O ${output_group} -p '{"from-to":"page alto"}'
"""
}
process merging_mets {
// Must be a single instance - modifying the main mets file
maxForks 1
input:
val mets_file_chunk
val page_range
output:
val mets_file_chunk
script:
"""
${params.singularity_wrapper} ocrd workspace -d ${params.workspace_dir} merge --force --no-copy-files ${mets_file_chunk} --page-id ${page_range}
${params.singularity_wrapper} rm ${mets_file_chunk}
"""
}
workflow {
main:
ch_range_multipliers = Channel.of(0..params.forks.intValue()-1)
split_page_ranges(ch_range_multipliers)
ocrd_cis_ocropy_binarize(split_page_ranges.out[0], split_page_ranges.out[1], params.input_file_group, "OCR-D-BIN")
ocrd_anybaseocr_crop(ocrd_cis_ocropy_binarize.out[0], ocrd_cis_ocropy_binarize.out[1], "OCR-D-BIN", "OCR-D-CROP")
ocrd_skimage_binarize(ocrd_anybaseocr_crop.out[0], ocrd_anybaseocr_crop.out[1], "OCR-D-CROP", "OCR-D-BIN2")
ocrd_skimage_denoise(ocrd_skimage_binarize.out[0], ocrd_skimage_binarize.out[1], "OCR-D-BIN2", "OCR-D-BIN-DENOISE")
ocrd_tesserocr_deskew(ocrd_skimage_denoise.out[0], ocrd_skimage_denoise.out[1], "OCR-D-BIN-DENOISE", "OCR-D-BIN-DENOISE-DESKEW")
ocrd_cis_ocropy_segment(ocrd_tesserocr_deskew.out[0], ocrd_tesserocr_deskew.out[1], "OCR-D-BIN-DENOISE-DESKEW", "OCR-D-SEG")
ocrd_cis_ocropy_dewarp(ocrd_cis_ocropy_segment.out[0], ocrd_cis_ocropy_segment.out[1], "OCR-D-SEG", "OCR-D-SEG-LINE-RESEG-DEWARP")
ocrd_calamari_recognize(ocrd_cis_ocropy_dewarp.out[0], ocrd_cis_ocropy_dewarp.out[1], "OCR-D-SEG-LINE-RESEG-DEWARP", "OCR-D-OCR")
merging_mets(ocrd_calamari_recognize.out[0], ocrd_calamari_recognize.out[1])
run_once_channel = merging_mets.out.collect()
ocrd_page_transform(params.mets, run_once_channel, "OCR-D-OCR", "OCR-D-OCR-TRANSFORMED")
ocrd_fileformat_transform(ocrd_page_transform.out, "OCR-D-OCR-TRANSFORMED", "OCR-D-ALTO")
}