-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
265 lines (194 loc) · 5.48 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
#!/usr/bin/env nextflow
if ( params.help ) {
help = """
|viral_comp: A workflow for the comparison of viral sequences.
|
|Required arguments:
| --sample_sheet Sample sheet file (CSV format ,) with header as below:
| `sample_name,fasta_file`
| --ref_sample Reference sample for the annotation
| --out_dir Output directory
|
""".stripMargin()
// Print the help with the stripped margin and exit
println(help)
exit(0)
}
// Validate input parameters
if (params.sample_sheet == null) {
error """No sample sheet provided. Use --sample_sheet to specify the path to the
| sample sheet file.""".stripMargin()
}
if (params.ref_sample == null) {
error """No ref_sample provided. Use --ref_sample to specify the reference
| sample for the annotation.""".stripMargin()
}
if (params.out_dir == null) {
error "No out_dir provided. Use --out_dir to specify the output directory"
}
// Process 1: Split each fasta file into separate files per sequence
process SPLIT_FASTA {
container 'python:3.10'
label 'cpu_x1'
label 'mem_2G'
input:
tuple val(sample_name), path(fasta_file)
output:
path("*.fa")
script:
template "split_fasta_per_sequence.py"
}
process CONCAT_FASTA {
container "debian:stable-slim"
label 'cpu_x1'
label 'mem_2G'
input:
tuple val(seq_name), path(fasta_files)
output:
tuple val(seq_name), path("${seq_name}.fa")
script:
"""
#!/bin/bash
cat *.fa > ${seq_name}.fa
"""
}
process ANNOT_REF {
container "staphb/prokka:latest"
label 'cpu_x8'
label 'mem_2G_per_cpu'
input:
tuple val(ref_sample), path(fasta_files)
output:
tuple val(ref_sample), path("reference_annotation/*")
publishDir "$params.out_dir", mode: 'copy'
script:
"""
#!/bin/bash
cat $fasta_files > concat.fa
prokka --kingdom Viruses --cpu $task.cpus --outdir reference_annotation \\
--locustag L --cdsrnaolap --quiet concat.fa
"""
}
process ALIGN_SEGMENT {
container "${params.biocontainers_registry}/biocontainers/mafft:7.520--h031d066_2"
label 'cpu_x16'
label 'mem_24G'
input:
tuple val(seq_name), path(fasta_file)
output:
tuple val(seq_name), path("${seq_name}.aln.fa")
script:
"""
#!/bin/bash
mafft --adjustdirection --retree 2 --thread $task.cpus --maxiterate 100 $fasta_file > ${seq_name}.aln.fa
sed -i "s/>_R_/>/g" ${seq_name}.aln.fa
"""
}
process DISTRIBUTE_SEQS {
container 'python:3.10'
label 'cpu_x1'
label 'mem_2G'
input:
tuple val(ref_name), path(annot_file), val(seq_name), path(aln_file)
output:
path "{cds,nc}/*.fa", optional: true
publishDir "$params.out_dir", pattern: "nc/*", mode: 'copy'
script:
template "parse_first_aln_with_annot.py"
}
process ALIGN_CDS {
container 'ghcr.io/nexomis/macse:v2.07.0'
label 'cpu_x1'
label 'mem_4G'
input:
tuple val(seq_name), path(fasta_file)
output:
tuple val(seq_name), path("aligned_cds/${seq_name}/NT_aln.fa"), path("aligned_cds/${seq_name}/AA_aln.fa")
publishDir "$params.out_dir", mode: 'copy'
script:
"""
#!/bin/bash
mkdir -p aligned_cds
mkdir -p aligned_cds/${seq_name}
macse -prog alignSequences -seq $fasta_file -out_NT aligned_cds/${seq_name}/NT_aln.raw.fa -out_AA aligned_cds/${seq_name}/AA_aln.raw.fa
fold -w 80 aligned_cds/${seq_name}/NT_aln.raw.fa > aligned_cds/${seq_name}/NT_aln.fa
fold -w 80 aligned_cds/${seq_name}/AA_aln.raw.fa > aligned_cds/${seq_name}/AA_aln.fa
rm aligned_cds/${seq_name}/NT_aln.raw.fa aligned_cds/${seq_name}/AA_aln.raw.fa
"""
}
process FORMAT_ALN_CDS {
container 'python:3.10'
label 'cpu_x1'
label 'mem_2G'
input:
tuple val(ref_sample), val(seq_name), path(nt_aln_file), path(aa_aln_file)
output:
path("cds_mutable/*/*"), optional: true
publishDir "$params.out_dir", mode: 'copy'
script:
template "format_aligned_cds.py"
}
process FORMAT_ALN_NC {
container 'python:3.10'
label 'cpu_x1'
label 'mem_2G'
input:
tuple val(ref_sample), val(seq_name), path(nt_aln_file)
output:
path("nc_mutable/*"), optional: true
publishDir "$params.out_dir", mode: 'copy'
script:
template "format_aligned_nc.py"
}
process GET_ORIENTED_REF {
container "python:3.10"
label 'cpu_x1'
label 'mem_2G'
input:
tuple val(ref_sample) ,val(seq_name), path(aln_file)
output:
tuple val(ref_sample), path("oriented_${ref_sample}_${seq_name}.fa")
script:
template "get_oriented_ref.py"
}
workflow{
Channel.fromPath(params.sample_sheet)
| splitCsv(header: true, sep: ',', strip: true)
| map { row -> tuple(row.sample_name, row.fasta_file) }
| set { samplesInput }
SPLIT_FASTA(samplesInput)
| flatten()
| map {tuple( it.name.split('\\.')[0], it )}
| groupTuple(by: 0)
| set {splitFastas}
CONCAT_FASTA(splitFastas)
| ALIGN_SEGMENT
| set {alignedSegment}
Channel.of(params.ref_sample)
| combine(alignedSegment)
| GET_ORIENTED_REF
| groupTuple(by: 0)
| ANNOT_REF
| flatMap { key, items ->
items.collect { item -> [key, item] }
}
| filter { it[1].getExtension() == "gff" }
| combine(alignedSegment)
| set {seqsToDistribute}
DISTRIBUTE_SEQS(seqsToDistribute)
| flatten()
| map {tuple( it.parent.name, it.name.split('\\.')[0], it )}
| branch {
cds: it[0] == "cds"
nc: it[0] == "nc"
}
| set { ditributedSeqs }
ditributedSeqs.cds
| map {tuple(it[1], it[2])}
| ALIGN_CDS
| map {tuple(params.ref_sample, it[0], it[1], it[2])}
| FORMAT_ALN_CDS
ditributedSeqs.nc
| map {tuple(params.ref_sample, it[1], it[2])}
| FORMAT_ALN_NC
}