@@ -48,7 +48,7 @@ params.help = null
48
48
49
49
log. info " "
50
50
log. info " --------------------------------------------------------"
51
- log. info " RNAseq-nf 2.3 .0: alignment, QC, and reads counting workflow for RNA sequencing "
51
+ log. info " RNAseq-nf 2.4 .0: alignment, QC, and reads counting workflow for RNA sequencing "
52
52
log. info " --------------------------------------------------------"
53
53
log. info " Copyright (C) IARC/WHO"
54
54
log. info " This program comes with ABSOLUTELY NO WARRANTY; for details see LICENSE"
@@ -132,6 +132,9 @@ if (params.help) {
132
132
log. info " help = ${ params.help} "
133
133
}
134
134
135
+ suffix2 = params. suffix2
136
+ if (suffix2== " null" ) suffix2 = null
137
+
135
138
// multiqc config file
136
139
ch_config_for_multiqc = file(params. multiqc_config)
137
140
@@ -216,31 +219,19 @@ if(mode=='bam'){
216
219
if (mode== ' fastq' ){
217
220
println " fastq mode"
218
221
219
- keys1 = file(params. input_folder). listFiles(). findAll { it. name ==~ / .*${params.suffix1}.${params.fastq_ext}/ }. collect { it. getName() }
220
- .collect { it. replace(" ${ params.suffix1} .${ params.fastq_ext} " ,' ' ) }
221
- keys2 = file(params. input_folder). listFiles(). findAll { it. name ==~ / .*${params.suffix2}.${params.fastq_ext}/ }. collect { it. getName() }
222
- .collect { it. replace(" ${ params.suffix2} .${ params.fastq_ext} " ,' ' ) }
223
- if ( ! (keys1. containsAll(keys2)) || ! (keys2. containsAll(keys1)) ) {println " \n ERROR : There is not at least one fastq without its mate, please check your fastq files." ; System . exit(0 )}
224
-
225
- readPairs0 = Channel . fromFilePairs(params. input_folder + " /*{${ params.suffix1} ,${ params.suffix2} }" + ' .' + params. fastq_ext)
222
+ if (suffix2){
223
+ println " paired library"
224
+ readPairs0 = Channel . fromFilePairs(params. input_folder + " /*{${ params.suffix1} ,${ params.suffix2} }" + ' .' + params. fastq_ext)
226
225
.map { row -> [ row[0 ] , " " , row[1 ][0 ], row[1 ][1 ] ] }
227
- .subscribe{ row -> println " ${ row} " }
228
-
229
- // Gather files ending with _1 suffix
230
- reads1 = Channel
231
- .fromPath( params. input_folder+ ' /*' + params. suffix1+ ' .' + params. fastq_ext )
232
- .map { path -> [ path. name. replace(" ${ params.suffix1} .${ params.fastq_ext} " ," " ), path ] }
233
-
234
- // Gather files ending with _2 suffix
235
- reads2 = Channel
236
- .fromPath( params. input_folder+ ' /*' + params. suffix2+ ' .' + params. fastq_ext )
237
- .map { path -> [ path. name. replace(" ${ params.suffix2} .${ params.fastq_ext} " ," " ), path ] }
238
-
239
- // Match the pairs on two channels having the same 'key' (name) and emit a new pair containing the expected files
240
- reads1
241
- .phase(reads2)
242
- .map { pair1, pair2 -> [ pair1[0 ] , " " , pair1[1 ], pair2[1 ] ] }
243
- .into{ readPairs ; readPairs2}
226
+ .view()
227
+ .into{ readPairs ; readPairs2}
228
+ }else {
229
+ println " single library"
230
+ readPairs0 = Channel . fromPath(params. input_folder + " /*${ params.suffix1} " + ' .' + params. fastq_ext)
231
+ .map { row -> [ row. name. replace(" ${ params.suffix1} .${ params.fastq_ext} " ," " ) , " " , row , file(" NO_fastq2" ) ] }
232
+ .view()
233
+ .into{ readPairs ; readPairs2}
234
+ }
244
235
}
245
236
}
246
237
@@ -262,10 +253,17 @@ process fastqc_pretrim {
262
253
shell:
263
254
basename1= pair1. name. replace(" .${ params.fastq_ext} " ," " ) // baseName.split("\\.")[0]
264
255
basename2= pair2. name. replace(" .${ params.fastq_ext} " ," " ) // baseName.split("\\.")[0]
256
+ if (suffix2){
257
+ pairs= " ${ pair1} ${ pair2} "
258
+ }else {
259
+ pairs= " ${ pair1} "
260
+ }
265
261
'''
266
- fastqc -t !{task.cpus} !{pair1} !{pair2 }
262
+ fastqc -t !{task.cpus} !{pairs }
267
263
mv !{basename1}_fastqc.zip !{file_tag}!{params.suffix1}!{rg}_pretrim_fastqc.zip
268
- mv !{basename2}_fastqc.zip !{file_tag}!{params.suffix2}!{rg}_pretrim_fastqc.zip
264
+ if [ ! -L NO_fastq2 ]
265
+ then mv !{basename2}_fastqc.zip !{file_tag}!{params.suffix2}!{rg}_pretrim_fastqc.zip
266
+ fi
269
267
'''
270
268
}
271
269
@@ -281,7 +279,7 @@ if(params.cutadapt!=null){
281
279
282
280
output:
283
281
set val(file_tag), val(rg) , file(" ${ file_tag}${ rg} *val_1.fq.gz" ), file(" ${ file_tag}${ rg} *val_2.fq.gz" ) into readPairs3
284
- file(" *_val_* _fastqc.zip" ) into fastqc_postpairs
282
+ file(" *_fastqc.zip" ) into fastqc_postpairs
285
283
file(" *trimming_report.txt" ) into trimming_reports
286
284
287
285
publishDir " ${ params.output_folder} /QC/adapter_trimming" , mode: ' copy' , pattern: ' {*report.txt,*fastqc.zip}'
@@ -290,8 +288,19 @@ if(params.cutadapt!=null){
290
288
cpu_tg = params. cpu_trim - 1
291
289
cpu_tg2 = cpu_tg. div(3.5 )
292
290
cpu_tg3 = Math . round(Math . ceil(cpu_tg2))
291
+ if (suffix2){
292
+ pairs= " ${ pair1} ${ pair2} "
293
+ opts= " --paired "
294
+ }else {
295
+ pairs= " ${ pair1} "
296
+ opts= " "
297
+ }
293
298
'''
294
- trim_galore --paired --fastqc --gzip --basename !{file_tag}!{rg} -j !{cpu_tg3} !{pair1} !{pair2}
299
+ trim_galore !{opts} --fastqc --gzip --basename !{file_tag}!{rg} -j !{cpu_tg3} !{pairs}
300
+ if [ ! -L NO_fastq2 ]
301
+ mv !{file_tag}!{rg}_trimmed.fq.gz !{file_tag}!{rg}_val_1.fq.gz
302
+ then touch !{file_tag}!{rg}_val_2.fq.gz
303
+ fi
295
304
'''
296
305
}
297
306
}else {
@@ -337,23 +346,32 @@ process alignment {
337
346
sort_threads = params. cpu. intdiv(2 ) - 1
338
347
sort_mem = params. mem. intdiv(4 )
339
348
input_f1= " ${ pair1[0]} "
340
- input_f2= " ${ pair2[0]} "
341
349
rgtmp= " ${ rg[0]} "
342
350
if (rgtmp== " " ) rgtmp= " ${ file_tag} "
343
351
rgline= " ID:${ rgtmp} SM:${ file_tag} ${ params.RG} "
344
352
for ( p1tmp in pair1. drop(1 ) ){
345
- input_f1= input_f1+ " ,${ p1tmp} "
346
- }
347
- for ( p2tmp in pair2. drop(1 ) ){
348
- input_f2= input_f2+ " ,${ p2tmp} "
353
+ input_f1= input_f1+ " ,${ p1tmp} "
349
354
}
350
355
for ( rgtmp in rg. drop(1 ) ){
351
- if (rgtmp== " " ) rgtmp= " ${ file_tag} "
356
+ if (rgtmp== " " ) rgtmp= " ${ file_tag} "
352
357
rgline= rgline+ " , ID:${ rgtmp} SM:${ file_tag} ${ params.RG} "
353
358
}
354
- MQ = " "
359
+ if (suffix2){
360
+ input_f2= " ${ pair2[0]} "
361
+ for ( p2tmp in pair2. drop(1 ) ){
362
+ input_f2= input_f2+ " ,${ p2tmp} "
363
+ }
364
+ pairs= " ${ input_f1} ${ input_f2} "
365
+ }else {
366
+ pairs= " ${ input_f1} "
367
+ }
355
368
'''
356
- STAR --outSAMattrRGline !{rgline} --outSAMmapqUnique !{params.STAR_mapqUnique} --chimSegmentMin 12 --chimJunctionOverhangMin 12 --chimSegmentReadGapMax 3 --alignSJDBoverhangMin 10 --alignMatesGapMax 100000 --alignIntronMax 100000 --alignSJstitchMismatchNmax 5 -1 5 5 --outSAMstrandField intronMotif --chimMultimapScoreRange 10 --chimMultimapNmax 10 --chimNonchimScoreDropMin 10 --peOverlapNbasesMin 12 --peOverlapMMp 0.1 --chimOutJunctionFormat 1 --twopassMode Basic --outReadsUnmapped None --runThreadN !{align_threads} --genomeDir . --sjdbGTFfile !{gtf} --readFilesCommand zcat --readFilesIn !{input_f1} !{input_f2} --outStd SAM | samblaster --addMateTags | sambamba view -S -f bam -l 0 /dev/stdin | sambamba sort -t !{sort_threads} -m !{sort_mem}G --tmpdir=!{file_tag}_tmp -o !{file_tag}.bam /dev/stdin
369
+ STAR --outSAMattrRGline !{rgline} --outSAMmapqUnique !{params.STAR_mapqUnique} --chimSegmentMin 12 --chimJunctionOverhangMin 12 \
370
+ --chimSegmentReadGapMax 3 --alignSJDBoverhangMin 10 --alignMatesGapMax 100000 --alignIntronMax 100000 \
371
+ --alignSJstitchMismatchNmax 5 -1 5 5 --outSAMstrandField intronMotif --chimMultimapScoreRange 10 --chimMultimapNmax 10 \
372
+ --chimNonchimScoreDropMin 10 --peOverlapNbasesMin 12 --peOverlapMMp 0.1 --chimOutJunctionFormat 1 --twopassMode Basic \
373
+ --outReadsUnmapped None --runThreadN !{align_threads} --genomeDir . --sjdbGTFfile !{gtf} --readFilesCommand zcat \
374
+ --readFilesIn !{pairs} --outStd SAM | samblaster --addMateTags | sambamba view -S -f bam -l 0 /dev/stdin | sambamba sort -t !{sort_threads} -m !{sort_mem}G --tmpdir=!{file_tag}_tmp -o !{file_tag}.bam /dev/stdin
357
375
mv Chimeric.out.junction STAR.!{file_tag}.Chimeric.SJ.out.junction
358
376
mv SJ.out.tab STAR.!{file_tag}.SJ.out.tab
359
377
mv Log.final.out STAR.!{file_tag}.Log.final.out
0 commit comments