-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
187 lines (157 loc) · 6.39 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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
def helpMessage() {
log.info"""
Description:
Trimming and quality control on single- or paired-ended reads.
Pipeline summary:
1. Quality control using FastQC
2. Adapter and quality trimming using Trim Galore!
Usage:
(1) Single-end reads:
nextflow run main.nf --single-end --reads '*\\.fastq\\.gz'
(2) Paired-end reads:
nextflow run main.nf --reads '*_R{1,2}\\.fastq\\.gz'
Mandatory arguments:
--reads path to one or more sets of paired-ended reads (valid
file types: .fastq.gz', '.fq.gz', '.fastq', or '.fq')
Input/output options:
--single_end when specified, input reads are single-end reads
(default: $params.single_end)
--output path to a directory which the results are written to
(default: $params.output)
Quality control:
--qc_adapters path to adapters files, if any (default: $params.qc_adapters)
Trimming (Trim Galore!):
--trim_min_length discards reads shorter than this (default: $params.trim_min_length)
--trim_quality Phred score threshold for quality trimming (default: $params.trim_quality)
--trim_adapter adapter sequence to be trimmed (default: auto-detect)
--trim_phred64 use Phred+64 (i.e., Illumina 1.5) encoding for quality scores
(default: Phred+33; Sanger/Illumina 1.8)
--trim_forward_leading
cut off bases at the start of the forward reads or all
reads if single-end reads (default: $params.trim_forward_leading)
--trim_forward_trailing
cut off bases at the end of the forward reads or all
reads if single-end reads (default: $params.trim_forward_trailing)
--trim_reverse_leading
cut off bases at the start of the forward reads or all
reads if single-end reads (default: $params.trim_reverse_leading)
--trim_reverse_trailing
cut off bases at the end of the forward reads or all
reads if single-end reads (default: $params.trim_reverse_trailing)
--trim_forward_cutoff POSITION
remove all bases past this position
cut off bases at the end of the forward reads or all
reads if single-end reads (default: $params.trim_forward_trailing)
--trim_leading_cutoff
INSTEAD of trimming, remove all bases past this position
(default: '$params.trim_leading_cutoff')
--trim_trailing_cutoff
INSTEAD of trimming, remove all bases such that there
are this many bases from the 3' end (default: '$params.trim_trailing_cutoff')
Flow control:
--skip_qc skip raw read quality assessment (default: $params.skip_qc)
--skip_trimming skip trimming step (default: $params.skip_trimming)
Miscellaneous:
--help display this help message and exit
--version display this pipeline's version number and exit
""".stripIndent()
}
def versionNumber() {
log.info"Genome assembly pipeline ~ version $workflow.manifest.version"
}
// Display the version number upon request
if ( params.version ) exit 0, versionNumber()
// Display a help message upon request
if ( params.help ) exit 0, helpMessage()
// Input validation
if ( params.reads == null ) {
exit 1, "Missing mandatory argument '--reads'\n" +
"Launch this workflow with '--help' for more info"
}
rawReads = Channel
.fromFilePairs( params.reads, size: params.single_end ? 1 : 2, type: 'file' )
.filter { it =~/.*\.fastq\.gz|.*\.fq\.gz|.*\.fastq|.*\.fq/ }
.ifEmpty { exit 1,
"No FASTQ files found with pattern '${params.reads}'\n" +
"Escape dots ('.') with a backslash character ('\\')\n" +
"Try enclosing the path in single-quotes (')\n" +
"Valid file types: '.fastq.gz', '.fq.gz', '.fastq', or '.fq'\n" +
"For single-end reads, specify '--single-end'" }
/*
* Read quality control using FastQC
*/
process rawReadsQuality {
conda "$baseDir/environment.yml"
publishDir "${params.output}/quality_control_pre-trimming", mode: 'copy'
input:
tuple val(name), path(reads)
output:
path "*_fastqc.{zip,html}"
path "fastqc_command.txt"
when:
! params.skip_qc
script:
"""
fastqc_command="fastqc --threads ${task.cpus} --quiet $reads"
\$fastqc_command
echo "\$fastqc_command" > 'fastqc_command.txt'
rename 's/_fastqc\\.zip\$/_pre-trimming_fastqc.zip/' *_fastqc.zip
rename 's/_fastqc\\.html\$/_pre-trimming_fastqc.html/' *_fastqc.html
"""
}
if ( params.skip_trimming ) {
trimmedReads = rawReads
}
/*
* Adapter removal and read trimming using Trim Galore!
*/
process trimming {
conda "$baseDir/environment.yml"
publishDir "${params.output}/trimmed_reads", mode: 'copy'
input:
tuple val(name), path(reads)
output:
tuple val(name), path("*.fq.gz")
path "*.txt"
path "*.{zip,html}"
when:
! params.skip_trimming
script:
flagsTrimming = "--fastqc --gzip --quality $params.trim_quality \
--length $params.trim_min_length --cores $task.cpus"
if ( params.trim_phred64 )
flagsTrimming += " --phred64"
if ( params.trim_forward_leading )
flagsTrimming += " --clip_R1 $params.trim_forward_leading"
if ( params.trim_forward_trailing )
flagsTrimming += " --three_prime_clip_R1 $params.trim_forward_trailing"
if ( params.trim_reverse_leading )
flagsTrimming += " --clip_R2 $params.trim_reverse_leading"
if ( params.trim_reverse_trailing )
flagsTrimming += " --three_prime_clip_R2 $params.trim_reverse_trailing"
if ( ! params.single_end )
flagsTrimming += " --paired --retain_unpaired"
commandTrimming = "trim_galore $flagsTrimming $reads"
"""
$commandTrimming
echo "$commandTrimming" > 'trim_galore_command.txt'
"""
}
workflow {
rawReadsQuality(rawReads)
trimming(rawReads)
}
workflow.onComplete {
// Display complete message
log.info "Completed at: " + workflow.complete
log.info "Duration : " + workflow.duration
log.info "Success : " + workflow.success
log.info "Exit status : " + workflow.exitStatus
}
workflow.onError {
// Display error message
log.info "Workflow execution stopped with the following message:"
log.info " " + workflow.errorMessage
}