Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit 95d8ebd

Browse files
committed
count reads for fastq files also
1 parent 550c051 commit 95d8ebd

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

main.nf

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,16 @@ process get_fastq_files_single {
252252
val samplename from sample_list_dirse.flatMap{ it.readLines() }
253253
output:
254254
set val(samplename), file("${samplename}.fastq.gz") optional true into ch_fastqs_dirse
255+
file('numreads.txt') optional true into ch_numreads_fastq_se
255256
script:
256257
"""
257258
name=${params.fastqdir}/${samplename}.fastq.gz
258259
if [[ ! -e \$name ]]; then
259-
echo "Count file \$name not found"
260+
echo "Fastq file \$name not found"
260261
false
261262
else
262263
ln -s \$name .
264+
echo \$(( \$(zcat \$fname | wc -l) / 4)) > numreads.txt
263265
fi
264266
"""
265267
}
@@ -275,14 +277,19 @@ process get_fastq_files {
275277
val samplename from sample_list_dirpe.flatMap{ it.readLines() }
276278
output:
277279
set val(samplename), file("${samplename}_?.fastq.gz") optional true into ch_fastqs_dirpe
280+
file('numreads.txt') optional true into ch_numreads_fastq
278281
script:
279282
"""
280283
list=( \$(ls ${params.fastqdir}/${samplename}_{1,2}.fastq.gz) )
281284
if [[ 2 == \${#list[@]} ]]; then
282-
ln -s \${list[0]} .
283-
ln -s \${list[1]} .
285+
f1=\${list[0]}
286+
f2=\${list[1]}
287+
ln -s \$f1 .
288+
ln -s \$f2 .
289+
echo \$(( \$(zcat \$f1 | wc -l) / 2)) > numreads.txt
290+
# TODO: we could do the same for f2 and introduce check. #shouldWe?
284291
else
285-
echo "Count mismatch sample ${samplename} found (\${list[@]})"
292+
echo "File count error sample ${samplename} found (\${list[@]})"
286293
false
287294
fi
288295
"""
@@ -301,7 +308,7 @@ process crams_to_fastq {
301308
output:
302309
set val(samplename), file("${samplename}_?.fastq.gz") optional true into ch_fastqs_irods
303310
file('*.lostcause.txt') optional true into ch_lostcause_cram
304-
file('numreads.txt') optional true into ch_numreads
311+
file('numreads.txt') optional true into ch_numreads_crams
305312
script:
306313

307314
// 0.7 factor below: see https://github.com/samtools/samtools/issues/494
@@ -929,7 +936,8 @@ EOF
929936
"""
930937
}
931938

932-
ch_numreads
939+
ch_numreads_crams
940+
.mix(ch_numreads_fastq, ch_numreads_fastq_se)
933941
.map { it.text.trim().toBigInteger() }
934942
.sum()
935943
.subscribe{ n_numreads = it }

0 commit comments

Comments
 (0)