Skip to content

Commit

Permalink
split truncate concat into two processes/
Browse files Browse the repository at this point in the history
  • Loading branch information
simonleandergrimm committed Dec 11, 2024
1 parent 4b966d8 commit 7a3a59b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
44 changes: 24 additions & 20 deletions modules/local/truncateConcat/main.nf
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
// Truncate concatenated read files for trial run
process TRUNCATE_CONCAT {
process TRUNCATE_CONCAT_PAIRED {
label "single"
label "BBTools"
input:
tuple val(sample), path(reads)
val n_reads
val single_end
output:

tuple val(sample), path({
single_end ?
"${sample}_trunc.fastq.gz" :
"${sample}_trunc_{1,2}.fastq.gz"
}), emit: reads
tuple val(sample), path("${sample}_trunc_{1,2}.fastq.gz"), emit: reads
shell:
'''
echo "Number of output reads: !{n_reads}"
n_lines=$(expr !{n_reads} \\* 4)
echo "Number of output lines: ${n_lines}"
if [ $(echo "!{reads}" | wc -w) -eq 2 ]; then
echo "Processing paired-end reads"
o1=!{sample}_trunc_1.fastq.gz
o2=!{sample}_trunc_2.fastq.gz
zcat !{reads[0]} | head -n ${n_lines} | gzip -c > ${o1}
zcat !{reads[1]} | head -n ${n_lines} | gzip -c > ${o2}
else
echo "Processing single-end reads"
o=!{sample}_trunc.fastq.gz
zcat !{reads[0]} | head -n ${n_lines} | gzip -c > ${o}
fi
o1=!{sample}_trunc_1.fastq.gz
o2=!{sample}_trunc_2.fastq.gz
zcat !{reads[0]} | head -n ${n_lines} | gzip -c > ${o1}
zcat !{reads[1]} | head -n ${n_lines} | gzip -c > ${o2}
'''
}

process TRUNCATE_CONCAT_SINGLE {
label "single"
label "BBTools"
input:
tuple val(sample), path(reads)
val n_reads
output:
tuple val(sample), path("${sample}_trunc.fastq.gz"), emit: reads
shell:
'''
echo "Number of output reads: !{n_reads}"
n_lines=$(expr !{n_reads} \\* 4)
echo "Number of output lines: ${n_lines}"
o=!{sample}_trunc.fastq.gz
zcat !{reads[0]} | head -n ${n_lines} | gzip -c > ${o}
'''
}
8 changes: 6 additions & 2 deletions subworkflows/local/raw/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
***************************/

include { QC } from "../../../subworkflows/local/qc"
include { TRUNCATE_CONCAT } from "../../../modules/local/truncateConcat"
if (params.single_end) {
include { TRUNCATE_CONCAT_SINGLE as TRUNCATE_CONCAT } from "../../../modules/local/truncateConcat"
} else {
include { TRUNCATE_CONCAT_PAIRED as TRUNCATE_CONCAT } from "../../../modules/local/truncateConcat"
}

/***********
| WORKFLOW |
Expand All @@ -23,7 +27,7 @@ workflow RAW {
single_end
main:
if ( n_reads_trunc > 0 ) {
out_ch = TRUNCATE_CONCAT(samplesheet_ch, n_reads_trunc, single_end)
out_ch = TRUNCATE_CONCAT(samplesheet_ch, n_reads_trunc)
} else {
out_ch = samplesheet_ch
}
Expand Down

0 comments on commit 7a3a59b

Please sign in to comment.