From 01fb8851c3e778052d342059736ecc09abab2e0d Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 11:47:58 +0200
Subject: [PATCH 1/9] mosdept: cram compatiblility

---
 modules/mosdepth/main.nf        | 33 +++--------
 modules/mosdepth/meta.yml       | 13 +++--
 tests/modules/mosdepth/main.nf  | 55 +++++++++++-------
 tests/modules/mosdepth/test.yml | 98 +++++++++++++++++++--------------
 4 files changed, 106 insertions(+), 93 deletions(-)

diff --git a/modules/mosdepth/main.nf b/modules/mosdepth/main.nf
index ff91e06f..894df1ae 100644
--- a/modules/mosdepth/main.nf
+++ b/modules/mosdepth/main.nf
@@ -10,13 +10,13 @@ process MOSDEPTH {
     input:
     tuple val(meta), path(bam), path(bai)
     path  bed
-    val   window_size
+    path  fasta
 
     output:
     tuple val(meta), path('*.global.dist.txt')    , emit: global_txt
     tuple val(meta), path('*.region.dist.txt')    , emit: regions_txt , optional:true
     tuple val(meta), path('*.summary.txt')        , emit: summary_txt
-    tuple val(meta), path('*.per-base.d4')        , emit: d4          , optional:true
+    tuple val(meta), path('*.per-base.d4')        , emit: per_base_d4 , optional:true
     tuple val(meta), path('*.per-base.bed.gz')    , emit: per_base_bed, optional:true
     tuple val(meta), path('*.per-base.bed.gz.csi'), emit: per_base_csi, optional:true
     tuple val(meta), path('*.regions.bed.gz')     , emit: regions_bed , optional:true
@@ -29,36 +29,17 @@ process MOSDEPTH {
     script:
     def args = task.ext.args ?: ''
     def prefix = task.ext.prefix ?: "${meta.id}"
-    if (window_size) {
-        interval = "--by ${window_size}"
-    } else if ( bed ) {
-        interval = "--by ${bed}"
-    } else {
-        interval = ""
-    }
+    def reference = fasta ? "--fasta ${fasta}" : ""
+    def interval = bed ? "--by ${bed}" : ""
+
     """
     mosdepth \\
+        --threads ${task.cpus} \\
         $interval \\
+        $reference \\
         $args \\
         $prefix \\
         $bam
-    cat <<-END_VERSIONS > versions.yml
-    "${task.process}":
-        mosdepth: \$(mosdepth --version 2>&1 | sed 's/^.*mosdepth //; s/ .*\$//')
-    END_VERSIONS
-    """
-
-    stub:
-    def prefix = task.ext.prefix ?: "${meta.id}"
-    """
-    touch ${prefix}.global.dist.txt
-    touch ${prefix}.region.dist.txt
-    touch ${prefix}.summary.txt
-    touch ${prefix}.per-base.d4
-    touch ${prefix}.per-base.bed.gz
-    touch ${prefix}.per-base.bed.gz.csi
-    touch ${prefix}.regions.bed.gz
-    touch ${prefix}.regions.bed.gz.csi
 
     cat <<-END_VERSIONS > versions.yml
     "${task.process}":
diff --git a/modules/mosdepth/meta.yml b/modules/mosdepth/meta.yml
index 636e966b..6e9e34c9 100644
--- a/modules/mosdepth/meta.yml
+++ b/modules/mosdepth/meta.yml
@@ -30,10 +30,10 @@ input:
       type: file
       description: BED file with intersected intervals
       pattern: "*.{bed}"
-  - window_size:
-      type: integer
-      description: Window size
-      pattern: "[0-9]+"
+  - fasta:
+      type: file
+      description: Reference genome FASTA file
+      pattern: "*.{fa,fasta}"
 output:
   - meta:
       type: map
@@ -60,6 +60,10 @@ output:
       type: file
       description: Index file for BED file with per-base coverage
       pattern: "*.{per-base.bed.gz.csi}"
+  - per_base_d4:
+      type: file
+      description: D4 file with per-base coverage
+      pattern: "*.{per-base.d4}"
   - regions_bed:
       type: file
       description: BED file with per-region coverage
@@ -76,3 +80,4 @@ authors:
   - "@joseespinosa"
   - "@drpatelh"
   - "@ramprasadn"
+  - "@matthdsm"
diff --git a/tests/modules/mosdepth/main.nf b/tests/modules/mosdepth/main.nf
index ddd68129..86ca0e86 100644
--- a/tests/modules/mosdepth/main.nf
+++ b/tests/modules/mosdepth/main.nf
@@ -5,32 +5,45 @@ nextflow.enable.dsl = 2
 include { MOSDEPTH } from '../../../modules/mosdepth/main.nf'
 
 workflow test_mosdepth {
-    input  = [ [ id:'test', single_end:true ],
-               [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
-               [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
-             ]
+    input  = [
+                [ id:'test', single_end:true ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
+            ]
 
     MOSDEPTH ( input, [], [] )
 }
 
-
-workflow test_mosdepth_window {
-    input  = [ [ id:'test', single_end:true ],
-               [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
-               [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
-             ]
-    window = 100
-
-    MOSDEPTH ( input, [], window )
-}
-
-
 workflow test_mosdepth_bed {
-    input  = [ [ id:'test', single_end:true ],
-               [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
-               [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
-             ]
-    bed  = [ file(params.test_data['sarscov2']['genome']['test_bed'], checkIfExists: true) ]
+    input  = [
+                [ id:'test', single_end:true ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
+            ]
+    bed  = [ file(params.test_data['homo_sapiens']['genome']['genome_bed'], checkIfExists: true) ]
 
     MOSDEPTH ( input, bed, [] )
 }
+
+workflow test_mosdepth_cram {
+    input  = [
+                [ id:'test', single_end:true ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_cram'], checkIfExists: true) ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_cram_crai'], checkIfExists: true) ]
+            ]
+    fasta = [ file(params.test_data['homo_sapiens']['genome']['genome_fasta'], checkIfExists: true) ]
+
+    MOSDEPTH ( input, [], fasta )
+}
+
+workflow test_mosdepth_cram_bed {
+    input  = [
+                [ id:'test', single_end:true ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_cram'], checkIfExists: true) ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_cram_crai'], checkIfExists: true) ]
+            ]
+    bed  = [ file(params.test_data['homo_sapiens']['genome']['genome_bed'], checkIfExists: true) ]
+    fasta = [ file(params.test_data['homo_sapiens']['genome']['genome_fasta'], checkIfExists: true) ]
+
+    MOSDEPTH ( input, bed, fasta )
+}
diff --git a/tests/modules/mosdepth/test.yml b/tests/modules/mosdepth/test.yml
index c66e0b89..2cacb185 100644
--- a/tests/modules/mosdepth/test.yml
+++ b/tests/modules/mosdepth/test.yml
@@ -1,53 +1,67 @@
-- name: mosdepth
-  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth -c ./tests/config/nextflow.config -c ./tests/modules/mosdepth/nextflow.config
+- name: mosdepth test_mosdepth
+  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
   tags:
     - mosdepth
   files:
-    - path: ./output/mosdepth/test.per-base.bed.gz.csi
-      md5sum: b2aad62c41a7146680d31df505fcc8c5
-    - path: ./output/mosdepth/test.per-base.bed.gz
-      md5sum: 11b3f649072c2c7453febb085b1a9c33
-    - path: ./output/mosdepth/test.mosdepth.global.dist.txt
-      md5sum: 2a1de1b0ecc361a21cd296ec4e1efd6a
-    - path: ./output/mosdepth/test.mosdepth.summary.txt
-      md5sum: 7b249dd3b3e58cc122fbd25ea84aa25d
+    - path: output/mosdepth/test.mosdepth.global.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.summary.txt
+      md5sum: 4f0d231060cbde4efdd673863bd2fb59
+    - path: output/mosdepth/test.per-base.bed.gz
+      md5sum: bc1df47d46f818fee5275975925d769a
+    - path: output/mosdepth/test.per-base.bed.gz.csi
+      md5sum: 9e649ac749ff6c6073bef5ab63e8aaa4
 
-- name: mosdepth window
-  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_window -c ./tests/config/nextflow.config -c ./tests/modules/mosdepth/nextflow.config
+- name: mosdepth test_mosdepth_bed
+  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_bed -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
   tags:
     - mosdepth
   files:
-    - path: ./output/mosdepth/test.per-base.bed.gz.csi
-      md5sum: b2aad62c41a7146680d31df505fcc8c5
-    - path: ./output/mosdepth/test.per-base.bed.gz
-      md5sum: 11b3f649072c2c7453febb085b1a9c33
-    - path: ./output/mosdepth/test.mosdepth.global.dist.txt
-      md5sum: 2a1de1b0ecc361a21cd296ec4e1efd6a
-    - path: ./output/mosdepth/test.regions.bed.gz
-      md5sum: 64e1ced01c4443d7c1796ef553992f0c
-    - path: ./output/mosdepth/test.regions.bed.gz.csi
-      md5sum: 9e312b4b0784bd46dfbd23b3a8afed6a
-    - path: ./output/mosdepth/test.mosdepth.region.dist.txt
-      md5sum: 65fbc824c4212c6884354d8ac72ad37e
-    - path: ./output/mosdepth/test.mosdepth.summary.txt
-      md5sum: 11804907dab069ddb99ca97bf2698572
+    - path: output/mosdepth/test.mosdepth.global.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.region.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.summary.txt
+      md5sum: 96c037f769974b904beb53edc4f56d82
+    - path: output/mosdepth/test.per-base.bed.gz
+      md5sum: bc1df47d46f818fee5275975925d769a
+    - path: output/mosdepth/test.per-base.bed.gz.csi
+      md5sum: 9e649ac749ff6c6073bef5ab63e8aaa4
+    - path: output/mosdepth/test.regions.bed.gz
+      md5sum: 5d398caf7171ec4406278e2add3009ae
+    - path: output/mosdepth/test.regions.bed.gz.csi
+      md5sum: 47669cfe41f3e222e74d81e1b1be191f
 
-- name: mosdepth bed
-  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_bed -c ./tests/config/nextflow.config -c ./tests/modules/mosdepth/nextflow.config
+- name: mosdepth test_mosdepth_cram
+  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_cram -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
   tags:
     - mosdepth
   files:
-    - path: ./output/mosdepth/test.per-base.bed.gz.csi
-      md5sum: b2aad62c41a7146680d31df505fcc8c5
-    - path: ./output/mosdepth/test.per-base.bed.gz
-      md5sum: 11b3f649072c2c7453febb085b1a9c33
-    - path: ./output/mosdepth/test.mosdepth.global.dist.txt
-      md5sum: 2a1de1b0ecc361a21cd296ec4e1efd6a
-    - path: ./output/mosdepth/test.regions.bed.gz
-      md5sum: 347f877700d1dc42c95157199eff25d5
-    - path: ./output/mosdepth/test.regions.bed.gz.csi
-      md5sum: ed5fbf46e3bdcbf60094df295bc40356
-    - path: ./output/mosdepth/test.mosdepth.region.dist.txt
-      md5sum: 295564628113d2ec0ca34d7f661cfea8
-    - path: ./output/mosdepth/test.mosdepth.summary.txt
-      md5sum: b07817412fd17819c14541e63bc4926c
+    - path: output/mosdepth/test.mosdepth.global.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.summary.txt
+      md5sum: 4f0d231060cbde4efdd673863bd2fb59
+    - path: output/mosdepth/test.per-base.bed.gz
+      md5sum: bc1df47d46f818fee5275975925d769a
+    - path: output/mosdepth/test.per-base.bed.gz.csi
+      md5sum: 9e649ac749ff6c6073bef5ab63e8aaa4
+
+- name: mosdepth test_mosdepth_cram_bed
+  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_cram_bed -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
+  tags:
+    - mosdepth
+  files:
+    - path: output/mosdepth/test.mosdepth.global.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.region.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.summary.txt
+      md5sum: 96c037f769974b904beb53edc4f56d82
+    - path: output/mosdepth/test.per-base.bed.gz
+      md5sum: bc1df47d46f818fee5275975925d769a
+    - path: output/mosdepth/test.per-base.bed.gz.csi
+      md5sum: 9e649ac749ff6c6073bef5ab63e8aaa4
+    - path: output/mosdepth/test.regions.bed.gz
+      md5sum: 5d398caf7171ec4406278e2add3009ae
+    - path: output/mosdepth/test.regions.bed.gz.csi
+      md5sum: 47669cfe41f3e222e74d81e1b1be191f

From b5850fd47157627b43fe6c80fd9defb097df893e Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 12:16:03 +0200
Subject: [PATCH 2/9] add stub

---
 modules/mosdepth/main.nf | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/modules/mosdepth/main.nf b/modules/mosdepth/main.nf
index 894df1ae..1f503c6b 100644
--- a/modules/mosdepth/main.nf
+++ b/modules/mosdepth/main.nf
@@ -46,4 +46,22 @@ process MOSDEPTH {
         mosdepth: \$(mosdepth --version 2>&1 | sed 's/^.*mosdepth //; s/ .*\$//')
     END_VERSIONS
     """
+
+    stub:
+    def prefix = task.ext.prefix ?: "${meta.id}"
+    """
+    touch ${prefix}.global.dist.txt
+    touch ${prefix}.region.dist.txt
+    touch ${prefix}.summary.txt
+    touch ${prefix}.per-base.d4
+    touch ${prefix}.per-base.bed.gz
+    touch ${prefix}.per-base.bed.gz.csi
+    touch ${prefix}.regions.bed.gz
+    touch ${prefix}.regions.bed.gz.csi
+
+    cat <<-END_VERSIONS > versions.yml
+    "${task.process}":
+        mosdepth: \$(mosdepth --version 2>&1 | sed 's/^.*mosdepth //; s/ .*\$//')
+    END_VERSIONS
+    """
 }

From 7e777c6626064d7463ecbf91c2c599db85eec647 Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 12:25:31 +0200
Subject: [PATCH 3/9] add error is  is provided twice

---
 modules/mosdepth/main.nf | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/modules/mosdepth/main.nf b/modules/mosdepth/main.nf
index 1f503c6b..a5218286 100644
--- a/modules/mosdepth/main.nf
+++ b/modules/mosdepth/main.nf
@@ -31,6 +31,9 @@ process MOSDEPTH {
     def prefix = task.ext.prefix ?: "${meta.id}"
     def reference = fasta ? "--fasta ${fasta}" : ""
     def interval = bed ? "--by ${bed}" : ""
+    if (bed && ext.args.contains("--by")) {
+        exit 1, "--by can only be specified once."
+    }
 
     """
     mosdepth \\

From 858cbe80c67093a39486bbb545b91c95077615bd Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 12:43:49 +0200
Subject: [PATCH 4/9] add must fail test

---
 modules/mosdepth/main.nf               |  2 +-
 tests/modules/mosdepth/main.nf         | 14 +++++++++++++-
 tests/modules/mosdepth/nextflow.config |  4 +++-
 tests/modules/mosdepth/test.yml        |  6 ++++++
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/modules/mosdepth/main.nf b/modules/mosdepth/main.nf
index a5218286..39586797 100644
--- a/modules/mosdepth/main.nf
+++ b/modules/mosdepth/main.nf
@@ -31,7 +31,7 @@ process MOSDEPTH {
     def prefix = task.ext.prefix ?: "${meta.id}"
     def reference = fasta ? "--fasta ${fasta}" : ""
     def interval = bed ? "--by ${bed}" : ""
-    if (bed && ext.args.contains("--by")) {
+    if (bed && args.contains("--by")) {
         exit 1, "--by can only be specified once."
     }
 
diff --git a/tests/modules/mosdepth/main.nf b/tests/modules/mosdepth/main.nf
index 86ca0e86..eab47e89 100644
--- a/tests/modules/mosdepth/main.nf
+++ b/tests/modules/mosdepth/main.nf
@@ -2,7 +2,8 @@
 
 nextflow.enable.dsl = 2
 
-include { MOSDEPTH } from '../../../modules/mosdepth/main.nf'
+include { MOSDEPTH                  } from '../../../modules/mosdepth/main.nf'
+include { MOSDEPTH as MOSDEPTH_FAIL } from '../../../modules/mosdepth/main.nf'
 
 workflow test_mosdepth {
     input  = [
@@ -47,3 +48,14 @@ workflow test_mosdepth_cram_bed {
 
     MOSDEPTH ( input, bed, fasta )
 }
+
+workflow test_mosdepth_fail {
+    input  = [
+                [ id:'test', single_end:true ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
+            ]
+    bed  = [ file(params.test_data['homo_sapiens']['genome']['genome_bed'], checkIfExists: true) ]
+
+    MOSDEPTH_FAIL ( input, bed, [] )
+}
diff --git a/tests/modules/mosdepth/nextflow.config b/tests/modules/mosdepth/nextflow.config
index 8730f1c4..85674a3c 100644
--- a/tests/modules/mosdepth/nextflow.config
+++ b/tests/modules/mosdepth/nextflow.config
@@ -1,5 +1,7 @@
 process {
 
     publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
-
+    withName: MOSDEPTH_FAIL {
+        ext.args = "--by 100"
+    }
 }
diff --git a/tests/modules/mosdepth/test.yml b/tests/modules/mosdepth/test.yml
index 2cacb185..4eaf9bf1 100644
--- a/tests/modules/mosdepth/test.yml
+++ b/tests/modules/mosdepth/test.yml
@@ -65,3 +65,9 @@
       md5sum: 5d398caf7171ec4406278e2add3009ae
     - path: output/mosdepth/test.regions.bed.gz.csi
       md5sum: 47669cfe41f3e222e74d81e1b1be191f
+
+- name: mosdepth test_mosdepth_fail
+  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_fail -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
+  tags:
+    - mosdepth
+  exitcode: 1

From 5bc2d419a94ec8b916739205961c115f62eec9c6 Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 13:23:00 +0200
Subject: [PATCH 5/9] fix fail test

---
 tests/modules/mosdepth/test.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/modules/mosdepth/test.yml b/tests/modules/mosdepth/test.yml
index 4eaf9bf1..a927396c 100644
--- a/tests/modules/mosdepth/test.yml
+++ b/tests/modules/mosdepth/test.yml
@@ -70,4 +70,4 @@
   command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_fail -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
   tags:
     - mosdepth
-  exitcode: 1
+  exit_code: 1

From a2a8e09762a5aec8985f0d93125eafe3a6d2d365 Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 13:45:52 +0200
Subject: [PATCH 6/9] Update modules/mosdepth/main.nf

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
---
 modules/mosdepth/main.nf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/mosdepth/main.nf b/modules/mosdepth/main.nf
index 39586797..5f6538e7 100644
--- a/modules/mosdepth/main.nf
+++ b/modules/mosdepth/main.nf
@@ -32,7 +32,7 @@ process MOSDEPTH {
     def reference = fasta ? "--fasta ${fasta}" : ""
     def interval = bed ? "--by ${bed}" : ""
     if (bed && args.contains("--by")) {
-        exit 1, "--by can only be specified once."
+        exit 1, "'--by' can only be specified once when running mosdepth! Either remove input BED file definition or remove '--by' from 'ext.args' definition"
     }
 
     """

From 749edce06945870a708397e37be4042048aaeb50 Mon Sep 17 00:00:00 2001
From: SusiJo <susanne.jodoin@gmx.de>
Date: Tue, 24 May 2022 14:20:19 +0200
Subject: [PATCH 7/9] add prefix

---
 modules/cnvkit/reference/main.nf | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/cnvkit/reference/main.nf b/modules/cnvkit/reference/main.nf
index 992d768f..bf4b3c21 100644
--- a/modules/cnvkit/reference/main.nf
+++ b/modules/cnvkit/reference/main.nf
@@ -21,6 +21,7 @@ process CNVKIT_REFERENCE {
 
     script:
     def args = task.ext.args ?: ''
+    def prefix = task.ext.prefix ?: "${meta.id}"
 
     """
     cnvkit.py \\
@@ -28,7 +29,7 @@ process CNVKIT_REFERENCE {
         --fasta $fasta \\
         --targets $targets \\
         --antitargets $antitargets \\
-        --output reference.cnn \\
+        --output ${prefix}.reference.cnn \\
         $args
 
     cat <<-END_VERSIONS > versions.yml

From 8381a5e5dd73228b3fe744e51f1964d62c28c1e5 Mon Sep 17 00:00:00 2001
From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com>
Date: Tue, 24 May 2022 14:43:40 +0200
Subject: [PATCH 8/9] add window test

---
 tests/modules/mosdepth/main.nf         | 16 ++++++++++++++--
 tests/modules/mosdepth/nextflow.config |  3 +++
 tests/modules/mosdepth/test.yml        | 20 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/tests/modules/mosdepth/main.nf b/tests/modules/mosdepth/main.nf
index eab47e89..96a9ef20 100644
--- a/tests/modules/mosdepth/main.nf
+++ b/tests/modules/mosdepth/main.nf
@@ -2,8 +2,9 @@
 
 nextflow.enable.dsl = 2
 
-include { MOSDEPTH                  } from '../../../modules/mosdepth/main.nf'
-include { MOSDEPTH as MOSDEPTH_FAIL } from '../../../modules/mosdepth/main.nf'
+include { MOSDEPTH                    } from '../../../modules/mosdepth/main.nf'
+include { MOSDEPTH as MOSDEPTH_FAIL   } from '../../../modules/mosdepth/main.nf'
+include { MOSDEPTH as MOSDEPTH_WINDOW } from '../../../modules/mosdepth/main.nf'
 
 workflow test_mosdepth {
     input  = [
@@ -49,6 +50,17 @@ workflow test_mosdepth_cram_bed {
     MOSDEPTH ( input, bed, fasta )
 }
 
+workflow test_mosdepth_window {
+    input  = [
+                [ id:'test', single_end:true ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ],
+                [ file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
+            ]
+    bed  = [ file(params.test_data['homo_sapiens']['genome']['genome_bed'], checkIfExists: true) ]
+
+    MOSDEPTH_WINDOW ( input, [], [] )
+}
+
 workflow test_mosdepth_fail {
     input  = [
                 [ id:'test', single_end:true ],
diff --git a/tests/modules/mosdepth/nextflow.config b/tests/modules/mosdepth/nextflow.config
index 85674a3c..4a6153e6 100644
--- a/tests/modules/mosdepth/nextflow.config
+++ b/tests/modules/mosdepth/nextflow.config
@@ -4,4 +4,7 @@ process {
     withName: MOSDEPTH_FAIL {
         ext.args = "--by 100"
     }
+    withName: MOSDEPTH_WINDOW {
+        ext.args = "--by 100"
+    }
 }
diff --git a/tests/modules/mosdepth/test.yml b/tests/modules/mosdepth/test.yml
index a927396c..a3115d6e 100644
--- a/tests/modules/mosdepth/test.yml
+++ b/tests/modules/mosdepth/test.yml
@@ -66,6 +66,26 @@
     - path: output/mosdepth/test.regions.bed.gz.csi
       md5sum: 47669cfe41f3e222e74d81e1b1be191f
 
+- name: mosdepth test_mosdepth_window
+  command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_window -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
+  tags:
+    - mosdepth
+  files:
+    - path: output/mosdepth/test.mosdepth.global.dist.txt
+      md5sum: e82e90c7d508a135b5a8a7cd6933452e
+    - path: output/mosdepth/test.mosdepth.region.dist.txt
+      md5sum: 39e0e707ec32feb5176fd20a95f1f468
+    - path: output/mosdepth/test.mosdepth.summary.txt
+      md5sum: 96c037f769974b904beb53edc4f56d82
+    - path: output/mosdepth/test.per-base.bed.gz
+      md5sum: bc1df47d46f818fee5275975925d769a
+    - path: output/mosdepth/test.per-base.bed.gz.csi
+      md5sum: 9e649ac749ff6c6073bef5ab63e8aaa4
+    - path: output/mosdepth/test.regions.bed.gz
+      md5sum: f02e2cb49cc050e13d76942d6960827a
+    - path: output/mosdepth/test.regions.bed.gz.csi
+      md5sum: 257d67678136963d9dd904330079609d
+
 - name: mosdepth test_mosdepth_fail
   command: nextflow run ./tests/modules/mosdepth -entry test_mosdepth_fail -c ./tests/config/nextflow.config  -c ./tests/modules/mosdepth/nextflow.config
   tags:

From 8208140d21f3a754fff2e177db7a0e570fa2af6e Mon Sep 17 00:00:00 2001
From: SusiJo <susanne.jodoin@gmx.de>
Date: Tue, 24 May 2022 14:59:52 +0200
Subject: [PATCH 9/9] missing meta.id changed

---
 modules/cnvkit/reference/main.nf        | 2 +-
 tests/modules/cnvkit/reference/test.yml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/cnvkit/reference/main.nf b/modules/cnvkit/reference/main.nf
index d5b8baa0..10458f27 100644
--- a/modules/cnvkit/reference/main.nf
+++ b/modules/cnvkit/reference/main.nf
@@ -21,7 +21,7 @@ process CNVKIT_REFERENCE {
 
     script:
     def args = task.ext.args ?: ''
-    def prefix = task.ext.prefix ?: "${meta.id}"
+    def prefix = task.ext.prefix ?: targets.BaseName
 
     """
     cnvkit.py \\
diff --git a/tests/modules/cnvkit/reference/test.yml b/tests/modules/cnvkit/reference/test.yml
index b1b8c896..a5baf0a2 100644
--- a/tests/modules/cnvkit/reference/test.yml
+++ b/tests/modules/cnvkit/reference/test.yml
@@ -4,5 +4,5 @@
     - cnvkit/reference
     - cnvkit
   files:
-    - path: output/cnvkit/reference.cnn
+    - path: output/cnvkit/multi_intervals.reference.cnn
       md5sum: 7c4a7902f5ab101b1f9d6038d331b3d9