From f6785dafb84714f2b303344219e13543ed3d0947 Mon Sep 17 00:00:00 2001 From: Julian Libiseller-Egger Date: Mon, 10 Jul 2023 15:11:33 +0000 Subject: [PATCH] fix bug making mosdepth fail when length of the reference was smaller than --number_depth_windows [CW-2372] --- CHANGELOG.md | 4 ++++ modules/local/pipeline.nf | 12 ++++++++---- nextflow.config | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74703c2..62d6090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v0.2.2] +### Fixed +- Bug where the `mosdepth` process would fail if the length of a reference sequence was smaller than the number of depth windows requested. + ## [v0.2.1] ### Changed - GitHub issue templates diff --git a/modules/local/pipeline.nf b/modules/local/pipeline.nf index f530cfd..7f38709 100644 --- a/modules/local/pipeline.nf +++ b/modules/local/pipeline.nf @@ -37,12 +37,16 @@ process mosdepth { script: int mosdepth_extra_threads = task.cpus - 1 """ - # get window length for reference + # get the length of the reference ref_length=\$(samtools idxstats input.bam | awk '\$1 == "$ref_id" {print \$2}') - window_length=\$(expr \$ref_length / $n_windows) - # if the reference is very short, `window_length` might be `0` --> set to `1` - [ "\$window_length" -eq "0" ] && window_length=1 + # calculate the corresponding window length (check `ref_length` first because + # `expr a / b` returns non-zero exit code when `a < b`) + if [ "\$ref_length" -lt "$n_windows" ]; then + window_length=1 + else + window_length=\$(expr \$ref_length / $n_windows) + fi # get the depths (we could add `-x`, but it loses a lot of detail from the depth # curves) diff --git a/nextflow.config b/nextflow.config index d9b2aa7..d95620a 100644 --- a/nextflow.config +++ b/nextflow.config @@ -65,7 +65,7 @@ manifest { description = 'Amplicon workflow' mainScript = 'main.nf' nextflowVersion = '>=22.10.8' - version = 'v0.2.1' + version = 'v0.2.2' } epi2melabs {