-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
327 lines (262 loc) · 7.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#! /usr/bin/env nextflow
/* Name: RNASeq pipeline
* Auth: Jennifer Chang
* Date: 2021/03/14
* Desc: Given a reference genome and paired reads, create RNAseq counts files
*/
nextflow.enable.dsl=2
def helpMsg() {
log.info """
Usage:
The typical command for running the RNAseq pipeline is as follows:
nextflow run main.nf --reads "*_{R1,R2}.fastq.gz" --genome GENOME.fasta --genome_gff GENOME.gff --genome_cdna CDNA.fasta -profile singularity
Mandatory arguments:
--reads Paired-end reads in fastq.gz format, will need to specify glob (e.g. "*_{R1,R2}.fastq.gz")
--genome Reference genome fasta file
--genome_gff Reference gff file
--genome_cdna Reference cdna file
Optional configuration arguments:
--methods Select one or more RNAseq counting methods [default: 'gsnap,hisat2,kallisto,salmon']
-profile Configuration profile to use. Can use multiple (comma separated)
Available: local, slurm [default:local]
--fastqc_app Link to fastqc executable [default: 'fastqc']
--multiqc_app Link to multiqc executable [default: 'multiqc']
--parallel_app Link to parallel executable [default: 'parallel']
--kallisto_app Link to kallisto executable [default: 'kallisto']
--salmon_app Link to salmon executable [default: 'salmon']
--gsnap_app Link to gsnap executable [default: 'gsnap']
--featureCounts_app Link to featureCounts executable [default: 'featureCounts']
Optional other arguments:
--threads Threads per process [default:4 for local, 16 for slurm]
--queueSize Maximum jobs to submit to slurm [default:20]
--account HPC account name for slurm sbatch, atlas and ceres requires this
--help
"""
}
if(params.help){
helpMsg()
exit 0
}
// === Define Processes
process fastqc {
tag "batched"
label 'fastqc'
publishDir "${params.outdir}/01_Quality-Control", mode: 'copy',
saveAs: { filename -> filename.indexOf(".zip") > 0 ? "zips/$filename" : "$filename" }
input: path(read)
output: path("*_fastqc.{zip,html}")
script:
"""
#! /usr/bin/env bash
PROC=\$((`nproc`))
${parallel_app} -j \${PROC} "${fastqc_app} {1}" ::: ${read}
"""
}
process multiqc {
label 'multiqc'
publishDir "${params.outdir}/01_Quality-Control", mode: 'copy',
saveAs: { filename -> filename.indexOf(".zip") > 0 ? "zips/$filename" : "$filename" }
input: path fastqc_htmls
output: path "multiqc_report.html"
script:
"""
#! /usr/bin/env bash
$multiqc_app .
"""
}
process kallisto_index {
tag "$genome_cdna"
label 'kallisto'
publishDir "${params.outdir}/03_Kallisto", mode: 'copy'
input: path(genome_cdna)
output: path("${genome_cdna.simpleName}.idx")
script:
"""
#! /usr/bin/env bash
$kallisto_app index \
-i ${genome_cdna.simpleName}.idx ${genome_cdna}
"""
}
process kallisto_quant {
tag "${readname}"
label 'kallisto'
publishDir "${params.outdir}/03_Kallisto", mode: 'copy'
input: tuple path(genome_index), val(readname), path(read_pairs)
output: path("*")
script:
"""
#! /usr/bin/env bash
PROC=\$((`nproc`))
${kallisto_app} quant \
-i ${genome_index} \
-o ${readname}_quant \
-b 20 -t \$PROC \
${read_pairs}
"""
}
process salmon_index {
tag "$genome_cdna"
label 'salmon'
publishDir "${params.outdir}/03_Salmon", mode: 'copy'
input: path(genome_cdna)
output: tuple val("${genome_cdna.simpleName}"), path("*")
script:
"""
#! /usr/bin/env bash
$salmon_app index \
-i ${genome_cdna.simpleName} \
-t ${genome_cdna}
"""
}
process salmon_quant {
tag "${readname}"
label 'salmon'
publishDir "${params.outdir}/03_Salmon", mode: 'copy'
input:
tuple val(genome_index), path(genome_index_files), val(readname), path(read_pairs)
output:
path("*")
script:
"""
#! /usr/bin/env bash
PROC=\$((`nproc`))
$salmon_app quant \
-l A -p \$PROC \
--validateMappings \
-i ${genome_index} \
-1 ${read_pairs.get(0)} \
-2 ${read_pairs.get(1)} \
-o ${readname}_quant
"""
}
process gsnap_index {
tag "${genome_gz.simpleName}"
label 'gsnap'
publishDir "${params.outdir}/03_GSNAP", mode: 'copy'
input:
path(genome_gz)
output:
tuple val("${genome_gz.simpleName}"), path("*")
script:
"""
#! /usr/bin/env bash
gmap_build \
--gunzip \
-d ${genome_gz.simpleName} \
-D gmapdb \
${genome_gz}
"""
}
process gsnap_align {
tag "${readname}"
label 'gsnap'
publishDir "${params.outdir}/03_GSNAP", mode: 'copy'
input: tuple val(genome_name), path(gmap_dir),val(readname), path(read_pairs)
output: path("*")
script:
"""
#! /usr/bin/env bash
PROC=\$(((`nproc`-1)*3/4+1))
PROC2=\$(((`nproc`-1)*1/4+1))
${gsnap_app} \
--gunzip \
-d ${genome_name} \
-D gmapdb/ \
-N 1 -t \$PROC -B 4 -m 5 \
--input-buffer-size=1000000 \
--output-buffer-size=1000000 \
-A sam \
${read_pairs} |
samtools view --threads \$PROC -bS - > ${readname}.bam
"""
}
process featureCounts_gene {
tag "${read_bam.simpleName}"
label 'gsnap'
publishDir "${params.outdir}/03_GSNAP", mode: 'copy'
input: tuple path(read_bam), path(genome_gff)
output: path("*")
script:
"""
#! /usr/bin/env bash
PROC=\$((`nproc`))
$featureCounts_app \
-T \$PROC \
-t gene \
-g ID \
-p \
-a ${genome_gff} \
-o ${read_bam.simpleName}_genecounts.txt \
${read_bam}
"""
}
process featureCounts_mRNA {
tag "${read_bam.simpleName}"
label 'gsnap'
publishDir "${params.outdir}/03_GSNAP", mode: 'copy'
input:
tuple path(read_bam), path(genome_gff)
output:
path("*")
script:
"""
#! /usr/bin/env bash
PROC=\$((`nproc`))
$featureCounts_app \
-T \$PROC -p \
-t mRNA \
-g ID \
-a ${genome_gff} \
-o ${read_bam.simpleName}_mRNAcounts.txt \
${read_bam}
"""
}
process featureCounts_geneMult {
tag "${read_bam.simpleName}"
label 'gsnap'
publishDir "${params.outdir}/03_GSNAP", mode: 'copy'
input:
tuple path(read_bam), path(genome_gff)
output:
path("*")
script:
"""
#! /usr/bin/env bash
PROC=\$((`nproc`))
$featureCounts_app \
-T \$PROC -M -p \
-t gene \
-g ID \
-a ${genome_gff} \
-o ${read_bam.simpleName}_geneMultcounts.txt \
${read_bam}
"""
}
// === Main Workflow
workflow {
/* Read, reference, and gff channels */
readsflat_ch = channel.fromPath(params.reads, checkIfExists:true)
reads_ch = channel.fromFilePairs(params.reads, checkIfExists:true)
if(params.methods =~ /gsnap/) {
genome_ch = channel.fromPath(params.genome, checkIfExists:true)
gff_ch = channel.fromPath(params.genome_gff, checkIfExists:true)
}
if(params.methods =~ /kallisto/ || params.methods =~ /salmon/){
cdna_ch = channel.fromPath(params.genome_cdna, checkIfExists:true)
}
/* 01_Quality-Control */
readsflat_ch.collate(8) | fastqc | collect | multiqc
/* 03_Kallisto */
if(params.methods =~ /kallisto/){
cdna_ch | kallisto_index | combine(reads_ch) | kallisto_quant
}
/* 03_Salmon */
if(params.methods =~ /salmon/){
cdna_ch | salmon_index | combine(reads_ch) | salmon_quant
}
/* 03_GSNAP */
if(params.methods =~ /gsnap/){
genome_ch | gsnap_index | combine(reads_ch) | gsnap_align | combine(gff_ch) |
( featureCounts_gene & featureCounts_mRNA & featureCounts_geneMult)
}
}