-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
212 lines (183 loc) · 7.18 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
#!/usr/bin/env nextflow
import groovy.json.JsonOutput // used for parameter output
nextflow.enable.dsl=2
//import processes for
include{
quality_control
quality_control_2
adapter_removal
quality_filter
} from './modules/read_processing.nf'
if (params.aligner == "bowtie2"){
include{
build_index_bowtie
mapping_bowtie
} from './modules/alignment.nf'
} else if (params.aligner == "star"){
include{
build_index_STAR
mapping_STAR
} from './modules/alignment.nf'
}
include{
collect_metadata
get_md5sum
multiqc
collect_versions
} from './modules/default_processes.nf'
/*
* Prints help and exits workflow afterwards when parameter --help is set to true
*/
if ( params.help ) {
help = """main.nf: Collects processing data from preprocessing steps (adapter trimming and quality filtering) as well as from alignment steps and returns them. Provides an overview of the general quality of the data.
|Required arguments:
| --reads Location of the input file file (FASTQ).
|
|Optional arguments:
| --aligner States which alignment tool is used. Currently available are:
| 'bowtie2' and 'star'
| [default: ${params.aligner}]
| --min_length Minimum length for reads after adapter trimming.
| [default: ${params.min_length}]
| --min_qual Minimum base quality.
| [default: ${params.min_qual}]
| --min_percent_qual_filter Minimum percentage of bases within a read that need to
| be above the quality threshold
| [default: ${params.min_percent_qual_filter}]
| --report_all_alignments If stated all possible alignments are calculated
| [default: ${params.report_all_alignments}]
| --max_alignments States the maximum number of alignments per read.
| Is overwritten by --report_all_alignments.
| [default: Default number used by the aligner]
| -w The NextFlow work directory. Delete the directory once the process
| is finished [default: ${workDir}]""".stripMargin()
// Print the help with the stripped margin and exit
println(help)
exit(0)
}
//essential input files
input_reads = Channel.fromPath( params.reads ) //FASTQ file(s) containing reads
reference = Channel.fromPath( params.reference )
//non essential input files
if(params.annotation != 'NO_FILE'){
annotation_file = Channel.fromPath( params.annotation )
}
annotation = file(params.annotation)
/*
* preparation for workflow
*/
// Collect all input files
input_files = input_reads.concat(Channel.of(annotation))
.concat(reference)
.flatten().toList()
/*
* Welcome log to be displayed before workflow
*/
log.info """\
${params.manifest.name} v${params.manifest.version}
==========================
input reads : ${params.reads}
input reference : ${params.reference}
input annotation : ${params.annotation}
output to : ${params.output_dir}
--
Aligner : ${params.aligner}
--
run as : ${workflow.commandLine}
started at : ${workflow.start}
config files : ${workflow.configFiles}
"""
.stripIndent()
/*
* Starting subworkflow descriptions
*/
workflow alignment {
take:
reference
annotation
reads
main:
if(params.aligner == "bowtie2"){
build_index_bowtie(reference)
mapping_bowtie(build_index_bowtie.out.index.first(),
reads)
alignments_tmp = mapping_bowtie.out.bam_alignments
version_index_tmp = build_index_bowtie.out.version
version_align_tmp = mapping_bowtie.out.version
report_tmp = mapping_bowtie.out.report
} else if (params.aligner == "star"){
build_index_STAR(reference,
annotation)
mapping_STAR(reads
.combine(build_index_STAR.out.index))
alignments_tmp = mapping_STAR.out.bam_alignments
version_index_tmp = build_index_STAR.out.version
version_align_tmp = mapping_STAR.out.version
report_tmp = mapping_STAR.out.report
}
emit:
version_index = version_index_tmp
version_align = version_align_tmp
reports = report_tmp
alignments = alignments_tmp
}
/*
* Actual workflow connecting subworkflows
*/
workflow {
// Preprocessing
quality_control(input_reads)
adapter_removal(input_reads)
quality_filter(adapter_removal.out.fastq_trimmed)
quality_control_2(quality_filter.out.fastq_quality_filtered)
alignment(reference,
annotation,
quality_filter.out.fastq_quality_filtered
)
multiqc(adapter_removal.out.report,
quality_filter.out.report,
quality_control.out.output,
quality_control_2.out.output,
alignment.out.reports)
// Collect metadata
collect_metadata()
get_md5sum(input_files)
collect_versions(collect_metadata.out.version
.concat(get_md5sum.out.version)
.concat(quality_control.out.version.first())
.concat(quality_control_2.out.version.first())
.concat(adapter_removal.out.version.first())
.concat(quality_filter.out.version.first())
.concat(alignment.out.version_index.first())
.concat(alignment.out.version_align.first())
.concat(multiqc.out.version)
.flatten().toList()
)
}
/*
* Check for parameter correctness
*/
def validAligners = ["bowtie2","star"]
if(params.aligner !in validAligners){
log.info """\
Stated aligner (${params.aligner}) is not a valid option.
Available aligners are: "bowtie2" and "star".
Please use one of them via the parameter --aligner and restart the pipeline.
"""
.stripIndent()
exit(1)
}
/*
* Prints complection status to command line
*/
workflow.onComplete{
// Create JSON file with all parameters -> will be saved in metadata output
jsonStr = JsonOutput.toJson(params)
file("${params.output_dir}/metadata/params.json").text = JsonOutput.prettyPrint(jsonStr)
println "Pipeline completed at: $workflow.complete"
println "Execution status: ${ workflow.success ? 'OK' : 'failed' }"
}
workflow.onError {
println "Something went wrong :("
println "Pipeline execution stopped with following error message: ${workflow.errorMessage}"
}