-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
222 lines (171 loc) · 6.21 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
#!/usr/bin/env nextflow
/*
========================================================================================
nextflow-base
========================================================================================
Writtrn by - Sangram keshari Sahu
Basic Nextflow structure template
----------------------------------------------------------------------------------------
*/
def workflow_description() {
return """
----------------------------------------------------------------------
Workflow Name: ${workflow.manifest.name}-v${workflow.manifest.version}
Short Description: ${workflow.manifest.description}
----------------------------------------------------------------------
""".stripIndent()
}
def helpMessage() {
log.info workflow_description()
log.info"""
Usage:
nextflow run ${workflow.manifest.name}-v${workflow.manifest.version} [arguments]
Workflow arguments:
--reads Path to fastq files directory
--cdna
--outdir
Tool arguments:
--fastp.length_required (default: '${params.fastp.length_required}')
--fastp.length_limit (default: '${params.fastp.length_limit}')
--fastp.qualified_quality_phred (default: '${params.fastp.qualified_quality_phred}')
System arguments:
--max_cpus Maximum CPU threads to be used (default: '${params.max_cpus}')
--max_memory Maximum memroy to be used (default: '${params.max_memory}')
--email Email ID for notofications (default: '${params.email}')
--help This help menu
Nextflow arguments:
-profile Run execution settings [docker,conda,test]
-resume Resume from where you left
Note: Please take care of single (-) and double (--) before an argument
Check documentation for more details on each argument.
----------------------------------------------------------------------
"""
}
// Help
if (params.help){
helpMessage()
exit 0
} else {
log.info workflow_description()
}
// ######################### params summary ######################
def summary = [:]
summary['User'] = workflow.userName
summary['Launch dir'] = workflow.launchDir
summary['Working dir'] = workflow.workDir
summary['Script dir'] = workflow.projectDir
summary['Input FASTA dir'] = params.reads
summary['Output dir'] = params.outdir
summary['Config Profile'] = workflow.profile
summary['Docker Container'] = workflow.container
summary['Maximum CPU'] = params.max_memory
summary['Maximum Memory'] = params.max_cpus
log.info summary.collect { k,v -> "${k.padRight(18)}: $v" }.join("\n")
def line() {
return """
----------------------------------------------------------------------
""".stripIndent()
}
log.info line()
// ######################### Parameters check ######################
// Input
if(!params.reads){
exit 1, "Please give a directory path containing pair-end fastq files."
} else {
reads = "${params.reads}/*_{1,2}.f*.gz"
Channel
.fromFilePairs( reads, checkExists:true )
.ifEmpty { error "Cannot find any reads matching: ${reads}" }
.into { read_pairs_ch; read_pairs2_ch }
}
// Output directory
if(params.outdir) results_dir = params.outdir
// reference
if(params.cdna) cdna_file = file(params.cdna)
// ######################### Workflow Starting here ######################
process fastp {
tag "filtering on $sample_id"
publishDir "${results_dir}/${sample_id}", mode: 'copy'
memory params.max_memory
container 'quay.io/biocontainers/fastp:0.20.1--h8b12597_0'
input:
set sample_id, file(reads) from read_pairs_ch
output:
set sample_id, file("fastp_filtred_reads/${reads[0]}"), file("fastp_filtred_reads/${reads[1]}") into fastp_ch, fastp_ch2
set sample_id, file("fastp_filtred_reads/${sample_id}_fastp.json"), file("fastp_filtred_reads/${sample_id}_fastp.html") into fastp_reports
script:
"""
mkdir fastp_filtred_reads
fastp -i ${reads[0]} -I ${reads[1]} \
-o fastp_filtred_reads/${reads[0]} \
-O fastp_filtred_reads/${reads[1]} \
--json fastp_filtred_reads/${sample_id}_fastp.json \
--html fastp_filtred_reads/${sample_id}_fastp.html \
--detect_adapter_for_pe \
--disable_length_filtering \
--correction \
--thread ${task.cpus}
"""
}
process fastqc {
tag "FASTQC on $sample_id"
publishDir "${results_dir}/${sample_id}", mode: 'copy'
cpus params.max_cpus
container 'quay.io/biocontainers/fastqc:0.11.9--0'
input:
set sample_id, file(fq1), file(fq2) from fastp_ch
output:
file("fastqc_report_${sample_id}") into fastqc_report
script:
"""
mkdir fastqc_report_${sample_id}
fastqc -f fastq -q ${fq1} ${fq2} \
-o fastqc_report_${sample_id} \
-f fastq -q ${fq1} ${fq2} \
--threads ${task.cpus}
"""
}
process index {
tag "$cdna.simpleName"
container 'quay.io/biocontainers/kallisto:0.46.2--h4f7b962_1'
input:
file cdna from cdna_file
output:
file 'index' into index_ch
script:
"""
kallisto index -i index $cdna
"""
}
process quant {
tag "Kallisto quant on $sample_id"
publishDir "${results_dir}/${sample_id}", mode: 'copy'
container 'quay.io/biocontainers/kallisto:0.46.2--h4f7b962_1'
input:
file index from index_ch
set sample_id, file(fq1), file(fq2) from fastp_ch2
output:
file("kallisto_quant_${sample_id}") into quant_ch
script:
"""
mkdir kallisto_quant_${sample_id}
kallisto quant -i $index ${fq1} ${fq2} -o kallisto_quant_${sample_id} \
&> kallisto_quant_${sample_id}/stdout.log
"""
}
process multiqc {
container 'quay.io/biocontainers/multiqc:1.8--py_2'
publishDir "${results_dir}", mode: 'copy'
input:
file('*') from quant_ch.mix(fastqc_report).collect()
output:
file('multiqc_report.html') optional true
when: params.multiqc_report
script:
"""
multiqc .
"""
}
workflow.onComplete {
log.info ( workflow.success ? "\nDone! Open the following report in your browser --> $results_dir/multiqc_report.html\n" : "Oops .. something went wrong" )
}