From 977d96ed0bd7d813b6f5498e9423d70a02e190ac Mon Sep 17 00:00:00 2001 From: avantonder Date: Fri, 29 Oct 2021 13:33:38 +0100 Subject: [PATCH] Add Racon module to nf-core/modules (#949) * add racon * add racon * add racon * add racon module * add racon module * edit racon module * edit racon module * edit racon module * edit racon module Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com> Co-authored-by: Chris Cheshire --- modules/racon/functions.nf | 78 +++++++++++++++++++++++++++ modules/racon/main.nf | 45 ++++++++++++++++ modules/racon/meta.yml | 52 ++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/config/test_data.config | 5 +- tests/modules/minimap2/align/test.yml | 2 +- tests/modules/racon/main.nf | 15 ++++++ tests/modules/racon/test.yml | 7 +++ 8 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 modules/racon/functions.nf create mode 100644 modules/racon/main.nf create mode 100644 modules/racon/meta.yml create mode 100644 tests/modules/racon/main.nf create mode 100644 tests/modules/racon/test.yml diff --git a/modules/racon/functions.nf b/modules/racon/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/racon/functions.nf @@ -0,0 +1,78 @@ +// +// Utility functions used in nf-core DSL2 module files +// + +// +// Extract name of software tool from process name using $task.process +// +def getSoftwareName(task_process) { + return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase() +} + +// +// Extract name of module from process name using $task.process +// +def getProcessName(task_process) { + return task_process.tokenize(':')[-1] +} + +// +// Function to initialise default values and to generate a Groovy Map of available options for nf-core modules +// +def initOptions(Map args) { + def Map options = [:] + options.args = args.args ?: '' + options.args2 = args.args2 ?: '' + options.args3 = args.args3 ?: '' + options.publish_by_meta = args.publish_by_meta ?: [] + options.publish_dir = args.publish_dir ?: '' + options.publish_files = args.publish_files + options.suffix = args.suffix ?: '' + return options +} + +// +// Tidy up and join elements of a list to return a path string +// +def getPathFromList(path_list) { + def paths = path_list.findAll { item -> !item?.trim().isEmpty() } // Remove empty entries + paths = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes + return paths.join('/') +} + +// +// Function to save/publish module results +// +def saveFiles(Map args) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + + // Do not publish versions.yml unless running from pytest workflow + if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) { + return null + } + if (ioptions.publish_by_meta) { + def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta + for (key in key_list) { + if (args.meta && key instanceof String) { + def path = key + if (args.meta.containsKey(key)) { + path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key] + } + path = path instanceof String ? path : '' + path_list.add(path) + } + } + } + if (ioptions.publish_files instanceof Map) { + for (ext in ioptions.publish_files) { + if (args.filename.endsWith(ext.key)) { + def ext_list = path_list.collect() + ext_list.add(ext.value) + return "${getPathFromList(ext_list)}/$args.filename" + } + } + } else if (ioptions.publish_files == null) { + return "${getPathFromList(path_list)}/$args.filename" + } +} diff --git a/modules/racon/main.nf b/modules/racon/main.nf new file mode 100644 index 00000000..60a5061e --- /dev/null +++ b/modules/racon/main.nf @@ -0,0 +1,45 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process RACON { + tag "$meta.id" + label 'process_high' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) } + + conda (params.enable_conda ? "bioconda::racon=1.4.20" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/racon:1.4.20--h9a82719_1" + } else { + container "quay.io/biocontainers/racon:1.4.20--h9a82719_1" + } + + input: + tuple val(meta), path(reads), path(assembly), path(paf) + + output: + tuple val(meta), path('*_assembly_consensus.fasta.gz') , emit: improved_assembly + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + racon -t "${task.cpus}" \\ + "${reads}" \\ + "${paf}" \\ + $options.args \\ + "${assembly}" > \\ + ${prefix}_assembly_consensus.fasta + + gzip -n ${prefix}_assembly_consensus.fasta + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( racon --version 2>&1 | sed 's/^.*v//' ) + END_VERSIONS + """ +} diff --git a/modules/racon/meta.yml b/modules/racon/meta.yml new file mode 100644 index 00000000..2428f044 --- /dev/null +++ b/modules/racon/meta.yml @@ -0,0 +1,52 @@ +name: racon +description: Consensus module for raw de novo DNA assembly of long uncorrected reads +keywords: + - assembly + - pacbio + - nanopore + - polish +tools: + - racon: + description: Ultrafast consensus module for raw de novo genome assembly of long uncorrected reads. + homepage: https://github.com/lbcb-sci/racon + documentation: https://github.com/lbcb-sci/racon + tool_dev_url: https://github.com/lbcb-sci/racon + doi: https://doi.org/10.1101/gr.214270.116 + licence: ['MIT'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - reads: + type: file + description: List of input FastQ files. Racon expects single end reads + pattern: "*.{fastq,fastq.gz,fq,fq.gz}" + - assembly: + type: file + description: Genome assembly to be improved + pattern: "*.{fasta,fa}" + - paf: + type: file + description: Alignment in PAF format + pattern: "*.paf" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - improved_assembly: + type: file + description: Improved genome assembly + pattern: "*_assembly_consensus.fasta.gz" + +authors: + - "@avantonder" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 4fdd8303..155ed78d 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -923,6 +923,10 @@ quast: - modules/quast/** - tests/modules/quast/** +racon: + - modules/racon/** + - tests/modules/racon/** + rapidnj: - modules/rapidnj/** - tests/modules/rapidnj/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index e8729b9b..c05e1c8f 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -11,6 +11,7 @@ params { genome_gff3 = "${test_data_dir}/genomics/sarscov2/genome/genome.gff3" genome_gff3_gz = "${test_data_dir}/genomics/sarscov2/genome/genome.gff3.gz" genome_gtf = "${test_data_dir}/genomics/sarscov2/genome/genome.gtf" + genome_paf = "${test_data_dir}/genomics/sarscov2/genome/genome.paf" genome_sizes = "${test_data_dir}/genomics/sarscov2/genome/genome.sizes" transcriptome_fasta = "${test_data_dir}/genomics/sarscov2/genome/transcriptome.fasta" transcriptome_paf = "${test_data_dir}/genomics/sarscov2/genome/transcriptome.paf" @@ -243,6 +244,7 @@ params { 'bacteroides_fragilis'{ 'genome' { genome_fna_gz = "${test_data_dir}/genomics/bacteroides_fragilis/genome/genome.fna.gz" + genome_paf = "${test_data_dir}/genomics/bacteroides_fragilis/genome/genome.paf" } 'illumina' { test1_contigs_fa_gz = "${test_data_dir}/genomics/bacteroides_fragilis/illumina/fasta/test1.contigs.fa.gz" @@ -253,7 +255,8 @@ params { } 'nanopore' { test_fastq_gz = "${test_data_dir}/genomics/bacteroides_fragilis/nanopore/fastq/test.fastq.gz" + overlap_paf = "${test_data_dir}/genomics/bacteroides_fragilis/nanopore/overlap.paf" } - } + } } } diff --git a/tests/modules/minimap2/align/test.yml b/tests/modules/minimap2/align/test.yml index f9b762bb..3309bf4b 100644 --- a/tests/modules/minimap2/align/test.yml +++ b/tests/modules/minimap2/align/test.yml @@ -14,4 +14,4 @@ - minimap2/align files: - path: ./output/minimap2/test.paf - md5sum: 5e7b55a26bf0ea3a2843423d3e0b9a28 + md5sum: 5e7b55a26bf0ea3a2843423d3e0b9a28 \ No newline at end of file diff --git a/tests/modules/racon/main.nf b/tests/modules/racon/main.nf new file mode 100644 index 00000000..b6b864e1 --- /dev/null +++ b/tests/modules/racon/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { RACON } from '../../../modules/racon/main.nf' addParams( options: [:] ) + +workflow test_racon { + input = [ [ id:'test', single_end:true ], // meta map + file(params.test_data['bacteroides_fragilis']['nanopore']['test_fastq_gz'], checkIfExists: true), + file(params.test_data['bacteroides_fragilis']['genome']['genome_fna_gz'], checkIfExists: true), + file(params.test_data['bacteroides_fragilis']['genome']['genome_paf'], checkIfExists: true) + ] + + RACON ( input ) +} \ No newline at end of file diff --git a/tests/modules/racon/test.yml b/tests/modules/racon/test.yml new file mode 100644 index 00000000..dc8e57dc --- /dev/null +++ b/tests/modules/racon/test.yml @@ -0,0 +1,7 @@ +- name: racon test_racon + command: nextflow run tests/modules/racon -entry test_racon -c tests/config/nextflow.config + tags: + - racon + files: + - path: output/racon/test_assembly_consensus.fasta.gz + md5sum: 96a0ba94c6154f6f37b5a76a0207eb6f