diff --git a/modules/bcftools/consensus/main.nf b/modules/bcftools/consensus/main.nf index 5d7cd74f..040e6534 100644 --- a/modules/bcftools/consensus/main.nf +++ b/modules/bcftools/consensus/main.nf @@ -18,9 +18,12 @@ process BCFTOOLS_CONSENSUS { def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" """ - cat $fasta | bcftools consensus $vcf $args > ${prefix}.fa - header=\$(head -n 1 ${prefix}.fa | sed 's/>//g') - sed -i 's/\${header}/${meta.id}/g' ${prefix}.fa + cat $fasta \\ + | bcftools \\ + consensus \\ + $vcf \\ + $args \\ + > ${prefix}.fa cat <<-END_VERSIONS > versions.yml "${task.process}": diff --git a/modules/bcftools/mpileup/main.nf b/modules/bcftools/mpileup/main.nf index 3583aac4..cdd38eec 100644 --- a/modules/bcftools/mpileup/main.nf +++ b/modules/bcftools/mpileup/main.nf @@ -9,12 +9,14 @@ process BCFTOOLS_MPILEUP { input: tuple val(meta), path(bam) - path fasta + path fasta + val save_mpileup output: tuple val(meta), path("*.gz") , emit: vcf tuple val(meta), path("*.tbi") , emit: tbi tuple val(meta), path("*stats.txt"), emit: stats + tuple val(meta), path("*.mpileup") , emit: mpileup, optional: true path "versions.yml" , emit: versions script: @@ -22,13 +24,16 @@ process BCFTOOLS_MPILEUP { def args2 = task.ext.args2 ?: '' def args3 = task.ext.args3 ?: '' def prefix = task.ext.prefix ?: "${meta.id}" + def mpileup = save_mpileup ? "| tee ${prefix}.mpileup" : "" """ echo "${meta.id}" > sample_name.list - bcftools mpileup \\ + bcftools \\ + mpileup \\ --fasta-ref $fasta \\ $args \\ $bam \\ + $mpileup \\ | bcftools call --output-type v $args2 \\ | bcftools reheader --samples sample_name.list \\ | bcftools view --output-file ${prefix}.vcf.gz --output-type z $args3 diff --git a/modules/bcftools/mpileup/meta.yml b/modules/bcftools/mpileup/meta.yml index c31180ee..483d0e71 100644 --- a/modules/bcftools/mpileup/meta.yml +++ b/modules/bcftools/mpileup/meta.yml @@ -26,6 +26,10 @@ input: type: file description: FASTA reference file pattern: "*.{fasta,fa}" + - save_mpileup: + type: boolean + description: Save mpileup file generated by bcftools mpileup + patter: "*.mpileup" output: - meta: type: map diff --git a/modules/ivar/consensus/main.nf b/modules/ivar/consensus/main.nf index 58d97c8c..96d00ce2 100644 --- a/modules/ivar/consensus/main.nf +++ b/modules/ivar/consensus/main.nf @@ -9,7 +9,8 @@ process IVAR_CONSENSUS { input: tuple val(meta), path(bam) - path fasta + path fasta + val save_mpileup output: tuple val(meta), path("*.fa") , emit: fasta @@ -21,14 +22,16 @@ process IVAR_CONSENSUS { def args = task.ext.args ?: '' def args2 = task.ext.args2 ?: '' def prefix = task.ext.prefix ?: "${meta.id}" - def save_mpileup = params.save_mpileup ? "tee ${prefix}.mpileup |" : "" + def mpileup = save_mpileup ? "| tee ${prefix}.mpileup" : "" """ - samtools mpileup \\ + samtools \\ + mpileup \\ --reference $fasta \\ $args2 \\ - $bam | \\ - $save_mpileup \\ - ivar consensus \\ + $bam \\ + $mpileup \\ + | ivar \\ + consensus \\ $args \\ -p $prefix diff --git a/modules/ivar/consensus/meta.yml b/modules/ivar/consensus/meta.yml index 2ee5f2c6..aa08ad98 100644 --- a/modules/ivar/consensus/meta.yml +++ b/modules/ivar/consensus/meta.yml @@ -25,6 +25,10 @@ input: type: file description: The reference sequence used for mapping and generating the BAM file pattern: "*.fa" + - save_mpileup: + type: boolean + description: Save mpileup file generated by ivar consensus + patter: "*.mpileup" output: - meta: type: map diff --git a/modules/ivar/variants/main.nf b/modules/ivar/variants/main.nf index fda6e0cc..bb6e402b 100644 --- a/modules/ivar/variants/main.nf +++ b/modules/ivar/variants/main.nf @@ -23,14 +23,16 @@ process IVAR_VARIANTS { def args2 = task.ext.args2 ?: '' def prefix = task.ext.prefix ?: "${meta.id}" def features = gff ? "-g $gff" : "" - def mpileup = save_mpileup ? "tee ${prefix}.mpileup |" : "" + def mpileup = save_mpileup ? "| tee ${prefix}.mpileup" : "" """ - samtools mpileup \\ + samtools \\ + mpileup \\ $args2 \\ --reference $fasta \\ - $bam | \\ - $mpileup \\ - ivar variants \\ + $bam \\ + $mpileup \\ + | ivar \\ + variants \\ $args \\ $features \\ -r $fasta \\ diff --git a/modules/ivar/variants/meta.yml b/modules/ivar/variants/meta.yml index 7c4297ca..29cbd958 100644 --- a/modules/ivar/variants/meta.yml +++ b/modules/ivar/variants/meta.yml @@ -32,6 +32,7 @@ input: - save_mpileup: type: boolean description: Save mpileup file generated by ivar variants + patter: "*.mpileup" output: - meta: type: map diff --git a/tests/modules/bcftools/consensus/main.nf b/tests/modules/bcftools/consensus/main.nf index ab00fbce..b2ee899b 100644 --- a/tests/modules/bcftools/consensus/main.nf +++ b/tests/modules/bcftools/consensus/main.nf @@ -5,11 +5,13 @@ nextflow.enable.dsl = 2 include { BCFTOOLS_CONSENSUS } from '../../../../modules/bcftools/consensus/main.nf' workflow test_bcftools_consensus { - input = [ [ id:'test' ], // meta map - [ file(params.test_data['sarscov2']['illumina']['test_vcf_gz'], checkIfExists: true) ], - [ file(params.test_data['sarscov2']['illumina']['test_vcf_gz_tbi'], checkIfExists: true) ], - [ file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] - ] + + input = [ + [ id:'test' ], // meta map + file(params.test_data['sarscov2']['illumina']['test_vcf_gz'], checkIfExists: true), + file(params.test_data['sarscov2']['illumina']['test_vcf_gz_tbi'], checkIfExists: true), + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + ] BCFTOOLS_CONSENSUS ( input ) } diff --git a/tests/modules/bcftools/mpileup/main.nf b/tests/modules/bcftools/mpileup/main.nf index 813ca408..1568f157 100644 --- a/tests/modules/bcftools/mpileup/main.nf +++ b/tests/modules/bcftools/mpileup/main.nf @@ -5,9 +5,25 @@ nextflow.enable.dsl = 2 include { BCFTOOLS_MPILEUP } from '../../../../modules/bcftools/mpileup/main.nf' workflow test_bcftools_mpileup { - input = [ [ id:'test' ], // meta map - [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ]] - fasta = [ file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] - BCFTOOLS_MPILEUP ( input, fasta ) + input = [ + [ id:'test' ], // meta map + [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ] + ] + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + save_mpileup = false + + BCFTOOLS_MPILEUP ( input, fasta, save_mpileup ) +} + +workflow test_bcftools_save_mpileup { + + input = [ + [ id:'test' ], // meta map + [ file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) ] + ] + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + save_mpileup = true + + BCFTOOLS_MPILEUP ( input, fasta, save_mpileup ) } diff --git a/tests/modules/bcftools/mpileup/test.yml b/tests/modules/bcftools/mpileup/test.yml index e3a515e6..35c33553 100644 --- a/tests/modules/bcftools/mpileup/test.yml +++ b/tests/modules/bcftools/mpileup/test.yml @@ -10,3 +10,18 @@ md5sum: ae0f17dcc2cb27034d848699b824c516 - path: output/bcftools/test.vcf.gz md5sum: e9e520663875c66296f3bff0fa226c40 + +- name: bcftools mpileup test_bcftools_save_mpileup + command: nextflow run ./tests/modules/bcftools/mpileup -entry test_bcftools_save_mpileup -c ./tests/config/nextflow.config -c ./tests/modules/bcftools/mpileup/nextflow.config + tags: + - bcftools/mpileup + - bcftools + files: + - path: output/bcftools/test.bcftools_stats.txt + md5sum: 72c506e633413c6b439f95336933984e + - path: output/bcftools/test.vcf.gz.tbi + md5sum: ae0f17dcc2cb27034d848699b824c516 + - path: output/bcftools/test.vcf.gz + md5sum: e9e520663875c66296f3bff0fa226c40 + - path: output/bcftools/test.mpileup + md5sum: fe0e45a57ffdfb253ed6794f8356a3f0 diff --git a/tests/modules/ivar/consensus/main.nf b/tests/modules/ivar/consensus/main.nf index d0807984..27ac83f9 100644 --- a/tests/modules/ivar/consensus/main.nf +++ b/tests/modules/ivar/consensus/main.nf @@ -2,14 +2,28 @@ nextflow.enable.dsl = 2 -params.save_mpileup = true include { IVAR_CONSENSUS } from '../../../../modules/ivar/consensus/main.nf' workflow test_ivar_consensus { - input = [ [ id:'test'], - file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) - ] + + input = [ + [ id:'test'], + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) - - IVAR_CONSENSUS ( input, fasta ) + save_mpileup = false + + IVAR_CONSENSUS ( input, fasta, save_mpileup) +} + +workflow test_ivar_consensus_mpileup { + + input = [ + [ id:'test'], + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + save_mpileup = true + + IVAR_CONSENSUS ( input, fasta, save_mpileup) } diff --git a/tests/modules/ivar/consensus/test.yml b/tests/modules/ivar/consensus/test.yml index caaa640f..c045eebb 100644 --- a/tests/modules/ivar/consensus/test.yml +++ b/tests/modules/ivar/consensus/test.yml @@ -1,5 +1,16 @@ -- name: ivar consensus +- name: ivar consensus test_ivar_consensus command: nextflow run ./tests/modules/ivar/consensus -entry test_ivar_consensus -c ./tests/config/nextflow.config -c ./tests/modules/ivar/consensus/nextflow.config + tags: + - ivar + - ivar/consensus + files: + - path: output/ivar/test.fa + md5sum: 9e21a64818f4302b4dece5480fa5e8b8 + - path: output/ivar/test.qual.txt + md5sum: 68b329da9893e34099c7d8ad5cb9c940 + +- name: ivar consensus test_ivar_consensus_mpileup + command: nextflow run ./tests/modules/ivar/consensus -entry test_ivar_consensus_mpileup -c ./tests/config/nextflow.config -c ./tests/modules/ivar/consensus/nextflow.config tags: - ivar - ivar/consensus