-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.nf
216 lines (188 loc) · 7 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
// Define input and output directory parameters
params.input_dir = 'raw_data'
// Define a list of different trimming combinations for sequence processing
def trimmingCombinations = [
"QualityTrim_Q25",
"AdapterTrim_Q25",
"LengthFilter_75",
"ComplexityFilter",
"SlidingWindow_4nt_q25",
"QualitySlidingHybrid_Q25_4nt_q25", // QualityTrim_Q25 + SlidingWindow_4nt_q25
"QualityAdapterHybrid_Q25", // QualityTrim_Q25 + AdapterTrim_Q25
"LengthComplexityHybrid_75", // LengthFilter_75 + ComplexityFilter
"SlidingComplexityHybrid_4nt_q25", // SlidingWindow_4nt_q25 + ComplexityFilter
"AdapterSlidingHybrid_Q25_4nt_q25", // AdapterTrim_Q25 + SlidingWindow_4nt_q25
"QualityLengthHybrid_Q25_75", // QualityTrim_Q25 + LengthFilter_75
"QualityComplexityHybrid_Q25", // QualityTrim_Q25 + ComplexityFilter
"AdapterLengthHybrid_Q25_75", // AdapterTrim_Q25 + LengthFilter_75
"AdapterComplexityHybrid_Q25", // AdapterTrim_Q25 + ComplexityFilter
"LengthSlidingHybrid_75_4nt_Q25", // LengthFilter_75 + SlidingWindow_4nt_q25
"NoTrimming"
]
/* Create a channel with trimming combinations
and pair them with file pairs from the input directory
*/
Channel
.from(trimmingCombinations)
.combine(Channel.fromFilePairs("${params.input_dir}/*_{1,2}.fastq"))
.map { trimParams, sampleId, files ->
println("Trim Params: ${trimParams}, Files: ${files}")
tuple(trimParams, files)
}
.set { trimmingChannel }
process fastp_process {
label 'fastp'
tag "${trimParams}_${reads[0].getName()}"
input:
tuple val(trimParams), file(reads)
output:
tuple val(trimParams), \
path("${reads[0].simpleName}_${trimParams}.fastq"), \
path("${reads[1].simpleName}_${trimParams}.fastq")
script:
String trimParamsStr = trimParams.toString().trim()
def fastpCmd = "fastp --in1 ${reads[0]} --in2 ${reads[1]}"
String outputFileName1 = "${reads[0].simpleName}_${trimParams}.fastq"
String outputFileName2 = "${reads[1].simpleName}_${trimParams}.fastq"
fastpCmd += " --out1 ${outputFileName1} --out2 ${outputFileName2}"
String htmlReport = "${reads[0].simpleName}_${trimParams}.html"
String jsonReport = "${reads[0].simpleName}_${trimParams}.json"
fastpCmd += " --html ${htmlReport} --json ${jsonReport}"
def parts = trimParamsStr.tokenize('_')
def trimActionMap = [
QualityTrim: { String q ->
"--qualified_quality_phred ${q.replace('Q', '')}"
},
AdapterTrim: { String q ->
"--detect_adapter_for_pe --qualified_quality_phred " +
"${q.replace('Q', '')}"
},
LengthFilter: { String length ->
"--length_required ${length}"
},
ComplexityFilter: { _ ->
"--low_complexity_filter"
},
SlidingWindow: { String windowSize, String meanQuality ->
"--cut_right --cut_window_size ${windowSize.replace('nt', '')} " +
"--cut_mean_quality ${meanQuality.replace('q', '')}"
},
QualitySlidingHybrid: { String q, String windowSize, String meanQuality ->
"--cut_right --qualified_quality_phred ${q.replace('Q', '')} " +
"--cut_window_size ${windowSize.replace('nt', '')} " +
"--cut_mean_quality ${meanQuality.replace('q', '')}"
},
QualityAdapterHybrid: { String q ->
"--detect_adapter_for_pe --qualified_quality_phred " +
"${q.replace('Q', '')}"
},
LengthComplexityHybrid: { String length ->
"--length_required ${length} --low_complexity_filter"
},
SlidingComplexityHybrid: { String windowSize, String meanQuality ->
"--cut_right --cut_window_size ${windowSize.replace('nt', '')} " +
"--cut_mean_quality ${meanQuality.replace('q', '')} " +
"--low_complexity_filter"
},
AdapterSlidingHybrid: { String q, String windowSize, String meanQuality ->
"--detect_adapter_for_pe --cut_right --cut_window_size " +
"${windowSize.replace('nt', '')} --cut_mean_quality " +
"${meanQuality.replace('q', '')} --qualified_quality_phred " +
"${q.replace('Q', '')}"
},
QualityLengthHybrid: { String q, String length ->
"--qualified_quality_phred ${q.replace('Q', '')} " +
"--length_required ${length}"
},
QualityComplexityHybrid: { String q ->
"--qualified_quality_phred ${q.replace('Q', '')} --low_complexity_filter"
},
AdapterLengthHybrid: { String q, String length ->
"--detect_adapter_for_pe --qualified_quality_phred " +
"${q.replace('Q', '')} --length_required ${length}"
},
AdapterComplexityHybrid: { String q ->
"--detect_adapter_for_pe --qualified_quality_phred " +
"${q.replace('Q', '')} --low_complexity_filter"
},
LengthSlidingHybrid: {
String length, String windowSize, String meanQuality ->
"--length_required ${length} --cut_right --cut_window_size " +
"${windowSize.replace('nt', '')} --cut_mean_quality " +
"${meanQuality.replace('Q', '')}"
},
NoTrimming: { _ ->
"--disable_adapter_trimming --disable_quality_filtering " +
"--disable_length_filtering"
}
]
trimActionMap.each { key, action ->
if (trimParamsStr.startsWith(key)) {
fastpCmd += " " + action(parts.drop(1))
return
}
}
"""
set -euo pipefail
echo "Trimming parameters: ${trimParams}"
if [ ${reads.size()} -ne 2 ]; then
echo "Error: Expected two reads files, but got ${reads.size()}"
exit 1
fi
${fastpCmd}
echo "fastp process for ${trimParams}_"\
"${reads[0].getName()} completed successfully."
"""
}
process spades_process {
label 'spades'
tag "${trimParams}"
input:
tuple val(trimParams), path(read1), path(read2)
output:
path "scaffolds_${trimParams}.fasta"
cpus 4
memory '8 GB'
script:
"""
set -euo pipefail
echo "Read1: ${read1}"
echo "Read2: ${read2}"
echo "Starting SPAdes genome assembly for ${trimParams}..."
spades.py --isolate -1 ${read1} -2 ${read2} -o output_${trimParams}
mv output_${trimParams}/scaffolds.fasta scaffolds_${trimParams}.fasta
echo "SPAdes genome assembly for ${trimParams} completed successfully."
"""
}
process quast_process {
label 'quast'
input:
path genomes
output:
path "reports"
cpus 4
memory '8 GB'
script:
"""
mkdir -p reports
set -euo pipefail
for genome in ${genomes}
do
genome_name=\$(basename \$genome .fasta)
echo "Starting QUAST quality assessment for \$genome_name..."
quast.py -o reports/output_\${genome_name} \${genome}
mv reports/output_\${genome_name}/report.html \
reports/report_\${genome_name}.html
echo "QUAST quality assessment for \$genome_name completed."
done
"""
}
workflow {
fastp_process(trimmingChannel)
.groupTuple()
.set { fastpCollectChannel }
spades_process(fastpCollectChannel)
.collect()
.set { quastInputChannel }
quast_process(quastInputChannel)
}