diff --git a/modules/nf-core/dragmap/align/main.nf b/modules/nf-core/dragmap/align/main.nf index 6945cf62499..3af939c4c62 100644 --- a/modules/nf-core/dragmap/align/main.nf +++ b/modules/nf-core/dragmap/align/main.nf @@ -10,11 +10,16 @@ process DRAGMAP_ALIGN { input: tuple val(meta) , path(reads) tuple val(meta2), path(hashmap) + tuple val(meta3), path(fasta) val sort_bam output: - tuple val(meta), path("*.bam"), emit: bam - tuple val(meta), path('*.log'), emit: log + tuple val(meta), path("*.sam") , emit: sam , optional: true + tuple val(meta), path("*.bam") , emit: bam , optional: true + tuple val(meta), path("*.cram") , emit: cram , optional: true + tuple val(meta), path("*.crai") , emit: crai , optional: true + tuple val(meta), path("*.csi") , emit: csi , optional: true + tuple val(meta), path('*.log') , emit: log path "versions.yml" , emit: versions when: @@ -24,8 +29,13 @@ process DRAGMAP_ALIGN { def args = task.ext.args ?: '' def args2 = task.ext.args2 ?: '' def prefix = task.ext.prefix ?: "${meta.id}" - def reads_command = meta.single_end ? "-1 $reads" : "-1 ${reads[0]} -2 ${reads[1]}" - def samtools_command = sort_bam ? 'sort' : 'view' + def reads_command = meta.single_end ? "-1 $reads" : "-1 ${reads[0]} -2 ${reads[1]}" + def samtools_command = sort_bam ? 'sort' : 'view' + def extension_pattern = /(--output-fmt|-O)+\s+(\S+)/ + def extension_matcher = (args2 =~ extension_pattern) + def extension = extension_matcher.getCount() > 0 ? extension_matcher[0][2].toLowerCase() : "bam" + def reference = fasta && extension=="cram" ? "--reference ${fasta}" : "" + if (!fasta && extension=="cram") error "Fasta reference is required for CRAM output" """ dragen-os \\ @@ -34,7 +44,7 @@ process DRAGMAP_ALIGN { --num-threads $task.cpus \\ $reads_command \\ 2> >(tee ${prefix}.dragmap.log >&2) \\ - | samtools $samtools_command $args2 --threads $task.cpus -o ${prefix}.bam - + | samtools $samtools_command $args2 --threads $task.cpus ${reference} -o ${prefix}.${extension} - cat <<-END_VERSIONS > versions.yml "${task.process}": @@ -45,9 +55,27 @@ process DRAGMAP_ALIGN { """ stub: + def args = task.ext.args ?: '' + def args2 = task.ext.args2 ?: '' def prefix = task.ext.prefix ?: "${meta.id}" + def reads_command = meta.single_end ? "-1 $reads" : "-1 ${reads[0]} -2 ${reads[1]}" + def samtools_command = sort_bam ? 'sort' : 'view' + def extension_pattern = /(--output-fmt|-O)+\s+(\S+)/ + def extension_matcher = (args2 =~ extension_pattern) + def extension = extension_matcher.getCount() > 0 ? extension_matcher[0][2].toLowerCase() : "bam" + def reference = fasta && extension=="cram" ? "--reference ${fasta}" : "" + if (!fasta && extension=="cram") error "Fasta reference is required for CRAM output" + + def create_index = "" + if (extension == "cram") { + create_index = "touch ${prefix}.crai" + } else if (extension == "bam") { + create_index = "touch ${prefix}.csi" + } + """ - touch ${prefix}.bam + touch ${prefix}.${extension} + ${create_index} touch ${prefix}.log cat <<-END_VERSIONS > versions.yml diff --git a/modules/nf-core/dragmap/align/meta.yml b/modules/nf-core/dragmap/align/meta.yml index 8a7f84db0e2..2270bd3397d 100644 --- a/modules/nf-core/dragmap/align/meta.yml +++ b/modules/nf-core/dragmap/align/meta.yml @@ -33,6 +33,15 @@ input: type: file description: DRAGMAP hash table pattern: "Directory containing DRAGMAP hash table *.{cmp,.bin,.txt}" + - meta3: + type: map + description: | + Groovy Map containing reference information + e.g. [ id:'genome'] + - fasta: + type: file + description: Genome fasta reference files + pattern: "*.{fa,fasta,fna}" output: - bam: type: file diff --git a/modules/nf-core/dragmap/align/tests/main.nf.test b/modules/nf-core/dragmap/align/tests/main.nf.test index ab6a8d1d266..d688c291c13 100644 --- a/modules/nf-core/dragmap/align/tests/main.nf.test +++ b/modules/nf-core/dragmap/align/tests/main.nf.test @@ -9,7 +9,7 @@ nextflow_process { tag "dragmap/align" tag "dragmap/hashtable" - test("sarscov2 - fastq, hashtable, false") { + test("sarscov2 - fastq, hashtable, fasta, false") { setup { run("DRAGMAP_HASHTABLE") { @@ -33,7 +33,8 @@ nextflow_process { file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_1.fastq.gz', checkIfExists: true) ] input[1] = DRAGMAP_HASHTABLE.out.hashmap - input[2] = false //sort + input[2] = [[id:'test'],file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)] + input[3] = false //sort """ } } @@ -51,7 +52,7 @@ nextflow_process { } - test("sarscov2 - fastq, hashtable, true") { + test("sarscov2 - fastq, hashtable, fasta, true") { setup { run("DRAGMAP_HASHTABLE") { @@ -75,7 +76,8 @@ nextflow_process { file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_1.fastq.gz', checkIfExists: true) ] input[1] = DRAGMAP_HASHTABLE.out.hashmap - input[2] = true //sort + input[2] = [[id:'test'],file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)] + input[3] = true //sort """ } } @@ -93,7 +95,7 @@ nextflow_process { } - test("sarscov2 - [fastq1, fastq2], hashtable, false") { + test("sarscov2 - [fastq1, fastq2], hashtable, fasta, false") { setup { run("DRAGMAP_HASHTABLE") { @@ -120,7 +122,8 @@ nextflow_process { ] ] input[1] = DRAGMAP_HASHTABLE.out.hashmap - input[2] = false //sort + input[2] = [[id:'test'],file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)] + input[3] = false //sort """ } } @@ -138,7 +141,7 @@ nextflow_process { } - test("sarscov2 - [fastq1, fastq2], hashtable, true") { + test("sarscov2 - [fastq1, fastq2], hashtable, fasta, true") { setup { run("DRAGMAP_HASHTABLE") { @@ -165,7 +168,8 @@ nextflow_process { ] ] input[1] = DRAGMAP_HASHTABLE.out.hashmap - input[2] = true //sort + input[2] = [[id:'test'],file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)] + input[3] = true //sort """ } } @@ -183,7 +187,7 @@ nextflow_process { } - test("homo_sapiens - [fastq1, fastq2], hashtable, true") { + test("homo_sapiens - [fastq1, fastq2], hashtable, fasta, true") { setup { run("DRAGMAP_HASHTABLE") { @@ -210,7 +214,8 @@ nextflow_process { ] ] input[1] = DRAGMAP_HASHTABLE.out.hashmap - input[2] = true //sort + input[2] = [[id:'test'],file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)] + input[3] = true //sort """ } } @@ -228,7 +233,7 @@ nextflow_process { } - test("sarscov2 - [fastq1, fastq2], hashtable, true - stub") { + test("sarscov2 - [fastq1, fastq2], hashtable, fasta, true - stub") { options "-stub" setup { @@ -256,7 +261,8 @@ nextflow_process { ] ] input[1] = DRAGMAP_HASHTABLE.out.hashmap - input[2] = true //sort + input[2] = [[id:'test'],file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)] + input[3] = true //sort """ } } diff --git a/modules/nf-core/dragmap/align/tests/main.nf.test.snap b/modules/nf-core/dragmap/align/tests/main.nf.test.snap index 32d88a27965..4bd60ebf49d 100644 --- a/modules/nf-core/dragmap/align/tests/main.nf.test.snap +++ b/modules/nf-core/dragmap/align/tests/main.nf.test.snap @@ -1,5 +1,5 @@ { - "homo_sapiens - [fastq1, fastq2], hashtable, true": { + "sarscov2 - [fastq1, fastq2], hashtable, fasta, false": { "content": [ "test.bam", [ @@ -12,17 +12,13 @@ ], "versions.yml" ], - "timestamp": "2023-11-23T10:12:03.844836279" + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-20T10:46:54.961203552" }, - "sarscov2 - [fastq1, fastq2], hashtable, true - stub": { - "content": [ - "test.bam", - "test.log", - "versions.yml" - ], - "timestamp": "2023-11-22T13:41:18.016853266" - }, - "sarscov2 - fastq, hashtable, false": { + "homo_sapiens - [fastq1, fastq2], hashtable, fasta, true": { "content": [ "test.bam", [ @@ -35,9 +31,13 @@ ], "versions.yml" ], - "timestamp": "2023-11-23T10:11:33.956661024" + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-20T10:47:24.495131137" }, - "sarscov2 - fastq, hashtable, true": { + "sarscov2 - fastq, hashtable, fasta, true": { "content": [ "test.bam", [ @@ -50,9 +50,13 @@ ], "versions.yml" ], - "timestamp": "2023-11-23T10:11:40.270598375" + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-20T10:46:42.57679755" }, - "sarscov2 - [fastq1, fastq2], hashtable, false": { + "sarscov2 - [fastq1, fastq2], hashtable, fasta, true": { "content": [ "test.bam", [ @@ -65,9 +69,25 @@ ], "versions.yml" ], - "timestamp": "2023-11-23T10:11:46.928978876" + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-20T10:47:08.943445149" + }, + "sarscov2 - [fastq1, fastq2], hashtable, fasta, true - stub": { + "content": [ + "test.bam", + "test.log", + "versions.yml" + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-20T10:47:38.346392133" }, - "sarscov2 - [fastq1, fastq2], hashtable, true": { + "sarscov2 - fastq, hashtable, fasta, false": { "content": [ "test.bam", [ @@ -80,6 +100,10 @@ ], "versions.yml" ], - "timestamp": "2023-11-23T10:11:53.506727278" + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-20T10:46:28.406548681" } } \ No newline at end of file diff --git a/subworkflows/nf-core/fastq_align_dna/main.nf b/subworkflows/nf-core/fastq_align_dna/main.nf index b710a4a6403..f064852e3a0 100644 --- a/subworkflows/nf-core/fastq_align_dna/main.nf +++ b/subworkflows/nf-core/fastq_align_dna/main.nf @@ -47,7 +47,7 @@ workflow FASTQ_ALIGN_DNA { ch_versions = ch_versions.mix(BWAMEM2_MEM.out.versions) break case 'dragmap': - DRAGMAP_ALIGN(ch_reads, ch_aligner_index, sort) // If aligner is dragmap + DRAGMAP_ALIGN(ch_reads, ch_aligner_index, ch_fasta, sort) // If aligner is dragmap ch_bam = ch_bam.mix(DRAGMAP_ALIGN.out.bam) ch_reports = ch_reports.mix(DRAGMAP_ALIGN.out.log) ch_versions = ch_versions.mix(DRAGMAP_ALIGN.out.versions)