-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nf
More file actions
311 lines (250 loc) · 7.29 KB
/
main.nf
File metadata and controls
311 lines (250 loc) · 7.29 KB
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
nextflow.enable.dsl=2
import groovyx.gpars.dataflow.DataflowVariable
params.input_fasta = "$baseDir/data/sequences.fasta"
params.outdir = "nf_results"
params.group_by = "country year month"
params.sequences_per_group = 20
params.min_date = 2012
params.dropped_strains = "config/dropped_strains.txt"
params.input_metadata = "data/metadata.tsv"
params.reference = "config/zika_outgroup.gb"
params.colors = file("config/colors.tsv")
params.lat_longs = file("config/lat_longs.tsv")
params.auspice_config = file("config/auspice_config.json")
params.coalescent = "opt"
params.date_inference = "marginal"
params.clock_filter_iqd = 4
params.inference_method = "joint"
params.columns = "region country"
process index_sequences {
tag "index_sequences"
publishDir "${params.outdir}/sequence_index", mode: 'copy'
input:
path sequences
output:
path "sequence_index.tsv"
script:
"""
augur index \
--sequences $sequences \
--output sequence_index.tsv
"""
}
process filter_sequences {
tag "filter_sequences"
publishDir "${params.outdir}/filtered_sequences", mode: 'copy'
input:
path sequences
path sequence_index
path metadata
path exclude
output:
path "filtered.fasta"
script:
"""
augur filter \
--sequences $sequences \
--sequence-index $sequence_index \
--metadata $metadata \
--exclude $exclude \
--output filtered.fasta \
--group-by ${params.group_by} \
--sequences-per-group ${params.sequences_per_group} \
--min-date ${params.min_date}
"""
}
process align_sequences {
tag "align_sequences"
publishDir "${params.outdir}/aligned", mode: 'copy'
input:
path sequences
path reference
output:
path "aligned.fasta"
script:
"""
augur align \
--sequences $sequences \
--reference-sequence $reference \
--output aligned.fasta \
--fill-gaps
"""
}
process build_tree {
tag "build_tree"
publishDir "${params.outdir}/tree", mode: 'copy'
input:
path alignment
output:
path "tree_raw.nwk"
script:
"""
augur tree \
--alignment $alignment \
--output tree_raw.nwk
"""
}
process refine_tree {
tag "refine_tree"
publishDir "${params.outdir}/refined_tree", mode: 'copy'
input:
path tree
path alignment
path metadata
val coalescent
val date_inference
val clock_filter_iqd
output:
tuple path("tree_refined.nwk"), path("branch_lengths.json")
script:
"""
augur refine \
--tree $tree \
--alignment $alignment \
--metadata $metadata \
--output-tree tree_refined.nwk \
--output-node-data branch_lengths.json \
--timetree \
--coalescent $coalescent \
--date-confidence \
--date-inference $date_inference \
--clock-filter-iqd $clock_filter_iqd
"""
}
process ancestral_sequences {
tag "ancestral_sequences"
publishDir "${params.outdir}/ancestral_sequences", mode: 'copy'
input:
tuple val(method), path(tree), path(alignment)
output:
path "nt_muts.json"
script:
"""
augur ancestral \
--tree $tree \
--alignment $alignment \
--output-node-data nt_muts.json \
--inference $method
"""
}
process translate {
tag "translate"
publishDir "${params.outdir}/translated_sequences", mode: 'copy'
input:
tuple path(tree), path(node_data), path(reference)
output:
path "aa_muts.json"
script:
"""
augur translate \
--tree $tree \
--ancestral-sequences $node_data \
--reference-sequence $reference \
--output-node-data aa_muts.json
"""
}
process traits {
tag "traits"
publishDir "${params.outdir}/traits", mode: 'copy'
input:
tuple val(columns), path(tree), path(metadata)
output:
tuple path("traits.json"), path("traitsregion.mugration_model.txt"), path("traitscountry.mugration_model.txt")
script:
"""
augur traits \
--tree ${tree} \
--metadata ${metadata} \
--output-node-data traits.json \
--columns ${columns} \
--confidence
"""
}
process export {
tag "export"
publishDir "${params.outdir}/export", mode: 'copy'
input:
tuple path(tree), path(metadata), path(branch_lengths), path(traits), path(nt_muts), path(aa_muts), path(colors), \
path(lat_longs), path(auspice_config)
output:
path("auspice_json.json")
log.info "Exporting data files for auspice..."
script:
"""
augur export v2 \
--tree ${tree} \
--metadata ${metadata} \
--node-data ${branch_lengths} ${traits} ${nt_muts} ${aa_muts} \
--colors ${colors} \
--lat-longs ${lat_longs} \
--auspice-config ${auspice_config} \
--include-root-sequence \
--output auspice_json.json
"""
}
Channel.fromPath(params.input_fasta, checkIfExists:true)
.set{ input_fasta_ch }
Channel.fromPath(params.input_metadata, checkIfExists:true)
.set { input_metadata_ch }
Channel.fromPath(params.dropped_strains, checkIfExists:true)
.set { dropped_strains_ch }
Channel.fromPath(params.reference, checkIfExists:true)
.set { reference_ch }
// sixth process
Channel
.value(params.inference_method)
.set{ inference_method_ch }
Channel
.value(params.columns)
.set{ columns_ch }
Channel
.value(params.colors)
.set{ colors_ch }
Channel
.value(params.lat_longs)
.set { lat_longs_ch }
Channel
.value(params.auspice_config)
.set { auspice_config_ch }
workflow {
index_sequences(input_fasta_ch)
.set{ sequence_index_ch }
filter_sequences(input_fasta_ch, sequence_index_ch, input_metadata_ch, dropped_strains_ch)
.set{ filtered_sequences_ch }
align_sequences(filtered_sequences_ch, reference_ch)
.set{ alignment_ch }
// alignment_ch |view
build_tree(alignment_ch)
.set{ tree_ch }
refine_tree(tree_ch, alignment_ch, input_metadata_ch, params.coalescent, params.date_inference, params.clock_filter_iqd)
.set{ refined_tree_ch }
ancestral_sequences_ch = refined_tree_ch
|combine(alignment_ch)
|view()
|map { arr -> tuple(params.inference_method, arr[0], arr[2]) }
|ancestral_sequences
// ancestral_sequences_ch |view
// ancestral_sequences(ancestral_sequences_ch)
tree_ch_from_refined_tree = refined_tree_ch.map { it[0] }
branch_ch_from_refined_tree = refined_tree_ch.map { it[1] }
translate_ch = tree_ch_from_refined_tree
|combine(ancestral_sequences.out)
|combine(reference_ch)
|translate
traits_ch = tree_ch_from_refined_tree
| combine(input_metadata_ch)
| map { arr -> tuple(params.columns, arr[0], arr[1]) }
| traits
traits_ch.view()
traits_from_traits_ch = traits_ch.map { it[0] }
export_ch = tree_ch_from_refined_tree
| combine(input_metadata_ch)
| combine(branch_ch_from_refined_tree)
| combine(traits_from_traits_ch)
| combine(ancestral_sequences.out)
| combine(translate.out)
| combine(colors_ch)
| combine(lat_longs_ch)
| combine(auspice_config_ch)
|export
}