-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.nf
293 lines (265 loc) · 7.34 KB
/
main.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
#!/usr/bin/env nextflow
params.outdir = '.'
params.all = false
params.minerva = false
params.miniature = false
params.metadata = false
params.he = false
params.input_csv = false
params.input_synid = false
params.input_path = false
params.watch_path = false
params.watch_csv = false
params.echo = false
params.keepBg = false
params.level = -1
params.bioformats2ometiff = true
params.watch_file = false
params.thumbnail_width = 256
params.thumbnail_sharpen = 20
params.thumbnail_quality = 75
heStory = 'https://gist.githubusercontent.com/adamjtaylor/3494d806563d71c34c3ab45d75794dde/raw/d72e922bc8be3298ebe8717ad2b95eef26e0837b/unscaled.story.json'
heScript = 'https://gist.githubusercontent.com/adamjtaylor/bbadf5aa4beef9aa1d1a50d76e2c5bec/raw/1f6e79ab94419e27988777343fa2c345a18c5b1b/fix_he_exhibit.py'
minerva_description_script = 'https://gist.githubusercontent.com/adamjtaylor/e51873a801fee39f1f1efa978e2b5e44/raw/c03d0e09ec58e4c391f5ce4ca4183abca790f2a2/inject_description.py'
if(params.keepBg == false) {
remove_bg = true
} else {
remove_bg = false
}
// Make a channel for inputing a csv which splits into rows - this could by synids, or paths
if (params.input_csv != false) {
Channel
.from(file(params.input_csv, checkIfExists: true))
.splitCsv(header:false, sep:'', strip:true)
.map { it[0] }
.unique()
.set { input_csv }
} else {
Channel.empty().set{input_csv}
}
// A channel to take a single imput synid
if (params.input_synid != false) {
Channel
.of(params.input_synid)
.set {input_synid}
} else {
Channel.empty().set{input_synid}
}
// Channel taking a single input_path (works with wildcards)
if (params.input_path != false) {
Channel
.fromPath(params.input_path)
.set {input_path}
} else {
Channel.empty().set{input_path}
}
if (params.watch_csv != false) {
Channel
.watchPath(params.watch_csv, 'create,modify')
.splitCsv(header:false, sep:'', strip:true)
.map { it[0] }
.unique()
.set {watch_csv}
} else {
Channel.empty().set{watch_csv}
}
if (params.watch_path != false) {
Channel
.watchPath(params.watch_path)
.set {watch_path}
} else {
Channel.empty().set{watch_path}
}
// Mix the csv inputs and split into those that are synids and those that are ne not
input_csv
.mix( watch_csv)
.branch {
syn: it =~ /^syn\d{8}/
other: true
}
.set { input_csv_branch }
// Mix the synids
input_synid
.mix(input_csv_branch.syn)
.into {synids_toget; synids_togetannotations}
// Mix the files
input_csv_branch.other
.map { it -> file(it) }
.mix( input_path, watch_path )
.map { it -> tuple(it.simpleName, it)}
.set {files}
process synapse_get {
label "process_low"
debug params.echo
secret 'SYNAPSE_AUTH_TOKEN'
input:
val synid from synids_toget
output:
set synid, file('*') into syn_out
stub:
"""
touch "test.tif"
"""
script:
"""
echo "synapse get $synid"
synapse get $synid
"""
}
process get_annotations {
label "process_low"
debug params.echo
secret 'SYNAPSE_AUTH_TOKEN'
when:
params.metadata == true || params.all == true
publishDir "$params.outdir/$workflow.runName", saveAs: {filename -> "${synid}/$workflow.runName/annotations.json"}
input:
val synid from synids_togetannotations
output:
file 'annotations.json'
stub:
"""
touch "annotations.json"
"""
script:
"""
echo "synapse get-annotations --id $synid"
synapse get-annotations --id $synid > annotations.json
"""
}
files
.mix(syn_out)
.branch {
ome: it[1] =~ /.+\.ome\.tif{1,2}$/ || params.bioformats2ometiff == false
other: true
}
.set { input_groups }
input_groups.ome
// .map { file -> tuple(file.parent, file.simpleName, file) }
.into {ome_ch; ome_view_ch}
if (params.echo) { ome_view_ch.view { "$it is an ometiff" } }
input_groups.other
.into {bf_convert_ch; bf_view_ch}
if (params.echo) { bf_view_ch.view { "$it is NOT an ometiff" } }
process make_ometiff{
label "process_medium"
debug params.echo
input:
set synid, file(input) from bf_convert_ch
output:
set synid, file("${input.simpleName}.ome.tiff") into converted_ch
stub:
"""
touch raw_dir
touch "test.ome.tiff"
"""
script:
"""
export JAVA_OPTS="-Xms10g -Xmx25g"
bioformats2raw $input 'raw_dir'
raw2ometiff 'raw_dir' "${input.simpleName}.ome.tiff"
"""
}
ome_ch
.mix(converted_ch)
.into { ome_story_ch; ome_miniature_ch; ome_metadata_ch }
process make_story{
label "process_medium"
publishDir "$params.outdir/$workflow.runName", saveAs: {filename -> "${synid}/$workflow.runName/minerva/story.json"}, pattern: "story.json"
debug params.echo
when:
params.minerva == true || params.all == true
input:
set synid, file(ome) from ome_story_ch
output:
set synid, file('story.json'), file(ome) into ome_pyramid_ch
stub:
"""
touch story.json
"""
script:
if(params.he == true)
"""
wget -O story.json $heStory
"""
else
"""
python3 /auto-minerva/story.py $ome > 'story.json'
"""
}
process render_pyramid{
label "process_medium"
publishDir "$params.outdir/$workflow.runName", saveAs: {filename -> "${synid}/$workflow.runName/minerva/"}
debug params.echo
secret 'SYNAPSE_AUTH_TOKEN'
when:
params.minerva == true || params.all == true
input:
set synid, file(story), file(ome) from ome_pyramid_ch
output:
file 'minerva'
stub:
"""
mkdir minerva
touch minerva/index.html
touch minerva/exhibit.json
"""
script:
if(params.he == true)
"""
python3 /minerva-author/src/save_exhibit_pyramid.py $ome $story 'minerva'
cp /index.html minerva
wget -O fix_he_exhibit.py $heScript
python3 fix_he_exhibit.py minerva/exhibit.json
wget -O inject_description.py $minerva_description_script
python3 inject_description.py minerva/exhibit.json --synid $synid
"""
else
"""
python3 /minerva-author/src/save_exhibit_pyramid.py $ome $story 'minerva'
cp /index.html minerva
wget -O inject_description.py $minerva_description_script
python3 inject_description.py minerva/exhibit.json --synid $synid --output minerva/exhibit.json
"""
}
process render_miniature{
label "process_high"
publishDir "$params.outdir/$workflow.runName", saveAs: {filename -> "${synid}/$workflow.runName/thumbnail.jpg"}
debug params.echo
when:
params.miniature == true || params.all == true
input:
set synid, file(ome) from ome_miniature_ch
output:
file 'data/miniature.jpg'
stub:
"""
mkdir data
touch data/miniature.jpg
"""
script:
"""
mkdir data
python3 /miniature/docker/paint_miniature.py $ome 'miniature.png' --remove_bg $remove_bg --level $params.level
convert data/miniature.png -colorspace RGB -sharpen 20 -resize '$params.thumbnail_width>' -sharpen $params.thumbnail_sharpen -colorspace sRGB -quality $params.thumbnail_quality data/miniature.jpg
"""
}
process get_metadata{
label "process_low"
publishDir "$params.outdir/$workflow.runName", saveAs: {filename -> "${synid}/$workflow.runName/headers.json"}
debug params.echo
when:
params.metadata == true || params.all == true
input:
set synid, file(ome) from ome_metadata_ch
output:
file "tifftags.json"
stub:
"""
touch tifftags.json
"""
script:
"""
python /image-header-validation/image-tags2json.py $ome > "tifftags.json"
"""
}