diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c4e5e4..971c9bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#73](https://github.com/nf-core/bamtofastq/pull/73) Sync TEMPLATE with tools 2.12 +### `Fixed` + +- [#77](https://github.com/nf-core/bamtofastq/pull/77) Fix detection of paired-end or single-end for input with less than 1000 reads. + ## v2.1.0 - Grace Hopper ### `Added` diff --git a/modules/local/check_paired_end.nf b/modules/local/check_paired_end.nf index 7d757ee8..52a31cef 100644 --- a/modules/local/check_paired_end.nf +++ b/modules/local/check_paired_end.nf @@ -24,7 +24,13 @@ process CHECK_IF_PAIRED_END { def prefix = task.ext.prefix ?: "${meta.id}" def reference = meta.filetype == "cram" ? "--reference ${fasta}" : "" """ - if [ \$({ samtools view -H $reference $input -@$task.cpus ; samtools view $reference $input -@$task.cpus | head -n1000; } | samtools view $reference -c -f 1 -@$task.cpus | awk '{print \$1/1000}') = "1" ]; then + if [ "\$( samtools view $reference $input -@$task.cpus | head -n1000 | wc -l)" -lt "1000" ]; then + LINES_TO_CHK=\$( samtools view $reference $input -@$task.cpus | wc -l) + else + LINES_TO_CHK=1000 + fi + + if [ \$({ samtools view -H $reference $input -@$task.cpus ; samtools view $reference $input -@$task.cpus | head -n\$LINES_TO_CHK; } | samtools view $reference -c -f 1 -@$task.cpus | awk -v lines=\$LINES_TO_CHK '{print \$1/lines}') = "1" ]; then echo 1 > ${prefix}.paired.txt else echo 1 > ${prefix}.single.txt