From cbc47767f7bb4751a9d178395bd66f051401a0c1 Mon Sep 17 00:00:00 2001 From: Matthias De Smet <11850640+matthdsm@users.noreply.github.com> Date: Fri, 13 May 2022 15:26:41 +0200 Subject: [PATCH] add sort option to bowtie2 --- modules/bowtie2/align/main.nf | 6 +++--- modules/bowtie2/align/meta.yml | 9 +++++++++ tests/modules/bowtie2/align/main.nf | 29 +++++++++++++++++++++++----- tests/modules/bowtie2/align/test.yml | 10 ++++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/modules/bowtie2/align/main.nf b/modules/bowtie2/align/main.nf index e4bb4327..c74e376f 100644 --- a/modules/bowtie2/align/main.nf +++ b/modules/bowtie2/align/main.nf @@ -11,6 +11,7 @@ process BOWTIE2_ALIGN { tuple val(meta), path(reads) path index val save_unaligned + val sort_bam output: tuple val(meta), path("*.bam") , emit: bam @@ -36,8 +37,7 @@ process BOWTIE2_ALIGN { reads_args = "-1 ${reads[0]} -2 ${reads[1]}" } - def samtools_command = "samtools view -@ $task.cpus --bam --with-header ${args2} > ${prefix}.bam" - + def samtools_command = sort_bam ? 'sort' : 'view' """ INDEX=`find -L ./ -name "*.rev.1.bt2" | sed "s/.rev.1.bt2//"` @@ -51,7 +51,7 @@ process BOWTIE2_ALIGN { $unaligned \\ $args \\ 2> ${prefix}.bowtie2.log \\ - | $samtools_command + | samtools $samtools_command $args2 --threads $task.cpus -o ${prefix}.bam - if [ -f ${prefix}.unmapped.fastq.1.gz ]; then mv ${prefix}.unmapped.fastq.1.gz ${prefix}.unmapped_1.fastq.gz diff --git a/modules/bowtie2/align/meta.yml b/modules/bowtie2/align/meta.yml index f80421ec..c99fa4e3 100644 --- a/modules/bowtie2/align/meta.yml +++ b/modules/bowtie2/align/meta.yml @@ -29,6 +29,15 @@ input: type: file description: Bowtie2 genome index files pattern: "*.ebwt" + - save_unaligned: + type: boolean + description: | + Save reads that do not map to the reference (true) or discard them (false) + (default: false) + - sort_bam: + type: boolean + description: use samtools sort (true) or samtools view (false) + pattern: "true or false" output: - bam: type: file diff --git a/tests/modules/bowtie2/align/main.nf b/tests/modules/bowtie2/align/main.nf index 42e2306a..75ab33ac 100644 --- a/tests/modules/bowtie2/align/main.nf +++ b/tests/modules/bowtie2/align/main.nf @@ -14,9 +14,25 @@ workflow test_bowtie2_align_single_end { ] fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) save_unaligned = false + sort = false BOWTIE2_BUILD ( fasta ) - BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned ) + BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned, sort ) +} + +workflow test_bowtie2_align_single_end_sorted { + input = [ + [ id:'test', single_end:true ], // meta map + [ + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) + ] + ] + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + save_unaligned = false + sort = true + + BOWTIE2_BUILD ( fasta ) + BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned, sort ) } workflow test_bowtie2_align_paired_end { @@ -29,9 +45,10 @@ workflow test_bowtie2_align_paired_end { ] fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) save_unaligned = false + sort = false BOWTIE2_BUILD ( fasta ) - BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned ) + BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned, sort ) } workflow test_bowtie2_align_single_end_large_index { @@ -43,9 +60,10 @@ workflow test_bowtie2_align_single_end_large_index { ] fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) save_unaligned = false + sort = false BOWTIE2_BUILD ( fasta ) - BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned ) + BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned, sort ) } workflow test_bowtie2_align_paired_end_large_index { @@ -58,7 +76,8 @@ workflow test_bowtie2_align_paired_end_large_index { ] fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) save_unaligned = false + sort = false BOWTIE2_BUILD ( fasta ) - BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned ) -} \ No newline at end of file + BOWTIE2_ALIGN ( input, BOWTIE2_BUILD.out.index, save_unaligned, sort ) +} diff --git a/tests/modules/bowtie2/align/test.yml b/tests/modules/bowtie2/align/test.yml index 103d65e9..4f8e4ff1 100644 --- a/tests/modules/bowtie2/align/test.yml +++ b/tests/modules/bowtie2/align/test.yml @@ -8,6 +8,16 @@ - path: ./output/bowtie2/test.bowtie2.log - path: ./output/bowtie2/versions.yml +- name: bowtie2 align test_bowtie2_align_single_end + command: nextflow run ./tests/modules/bowtie2/align -entry test_bowtie2_align_single_end_sorted -c ./tests/config/nextflow.config -c ./tests/modules/bowtie2/align/nextflow.config + tags: + - bowtie2 + - bowtie2/align + files: + - path: ./output/bowtie2/test.bam + - path: ./output/bowtie2/test.bowtie2.log + - path: ./output/bowtie2/versions.yml + - name: bowtie2 align test_bowtie2_align_paired_end command: nextflow run tests/modules/bowtie2/align -entry test_bowtie2_align_paired_end -c tests/config/nextflow.config -c tests/modules/bowtie2/align/nextflow.config tags: