From bd2baa1e7c0f0e3d052e10406d2f86125c51af20 Mon Sep 17 00:00:00 2001 From: "James A. Fellows Yates" Date: Tue, 26 Oct 2021 23:07:33 +0200 Subject: [PATCH] New module: `maxbin2` (#895) * Specify more guidelines on input channels * Linting * Updates based on code review * Update README.md * Fix broken sentence * feat: add megahit module, currently decompressed output * Update main.nf * Update tests/modules/megahit/test.yml Co-authored-by: Maxime Borry * Apply suggestions from code review Co-authored-by: Harshil Patel * feat: compress all outputs, remove md5sums due to gz stochasicity * fix: wrong conda channel for pigz * fix: broken singleend tests and update meta.yml * Missed one * Apply suggestions from code review Co-authored-by: Harshil Patel * fix: pigz formatting * Apply suggestions from code review Co-authored-by: Harshil Patel * Apply suggestions from code review * Added, just need to finish tests once we have bacterial data * Add prelim test data * Fix version reporting * Add tests based on proposed test-dataset * Finalise new testdata * Fix md5sum issue by removing it... * Update main.nf * Apply suggestions from code review Co-authored-by: Harshil Patel Co-authored-by: Maxime Borry --- modules/maxbin2/functions.nf | 78 ++++++++++++++++++++++++++++++++ modules/maxbin2/main.nf | 53 ++++++++++++++++++++++ modules/maxbin2/meta.yml | 79 +++++++++++++++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/config/test_data.config | 15 +++++++ tests/modules/maxbin2/main.nf | 17 +++++++ tests/modules/maxbin2/test.yml | 15 +++++++ 7 files changed, 261 insertions(+) create mode 100644 modules/maxbin2/functions.nf create mode 100644 modules/maxbin2/main.nf create mode 100644 modules/maxbin2/meta.yml create mode 100644 tests/modules/maxbin2/main.nf create mode 100644 tests/modules/maxbin2/test.yml diff --git a/modules/maxbin2/functions.nf b/modules/maxbin2/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/maxbin2/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/maxbin2/main.nf b/modules/maxbin2/main.nf new file mode 100644 index 00000000..bcfa9590 --- /dev/null +++ b/modules/maxbin2/main.nf @@ -0,0 +1,53 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process MAXBIN2 { + tag "$meta.id" + label 'process_medium' + 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::maxbin2=2.2.7" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/maxbin2:2.2.7--he1b5a44_2" + } else { + container "quay.io/biocontainers/maxbin2:2.2.7--he1b5a44_2" + } + + input: + tuple val(meta), path(contigs), path(reads), path(abund) + + output: + tuple val(meta), path("*.fasta.gz") , emit: binned_fastas + tuple val(meta), path("*.summary") , emit: summary + tuple val(meta), path("*.log.gz") , emit: log + tuple val(meta), path("*.marker.gz") , emit: marker_counts + tuple val(meta), path("*.noclass.gz") , emit: unbinned_fasta + tuple val(meta), path("*.tooshort.gz"), emit: tooshort_fasta + tuple val(meta), path("*_bin.tar.gz") , emit: marker_bins , optional: true + tuple val(meta), path("*_gene.tar.gz"), emit: marker_genes, optional: true + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def associate_files = reads ? "-reads $reads" : "-abund $abund" + """ + run_MaxBin.pl \\ + -contig $contigs \\ + $associate_files \\ + -thread $task.cpus \\ + $options.args \\ + -out $prefix + + gzip *.fasta *.noclass *.tooshort *log *.marker + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + maxbin2: \$( run_MaxBin.pl -v | head -n 1 | sed 's/MaxBin //' ) + END_VERSIONS + """ +} diff --git a/modules/maxbin2/meta.yml b/modules/maxbin2/meta.yml new file mode 100644 index 00000000..358f8323 --- /dev/null +++ b/modules/maxbin2/meta.yml @@ -0,0 +1,79 @@ +name: maxbin2 +description: MaxBin is a software that is capable of clustering metagenomic contigs +keywords: + - metagenomics + - assembly + - binning + - maxbin2 + - de novo assembly + - mags + - metagenome-assembled genomes + - contigs +tools: + - maxbin2: + description: MaxBin is software for binning assembled metagenomic sequences based on an Expectation-Maximization algorithm. + homepage: https://sourceforge.net/projects/maxbin/ + documentation: https://sourceforge.net/projects/maxbin/ + tool_dev_url: https://sourceforge.net/projects/maxbin/ + doi: "10.1093/bioinformatics/btv638" + licence: ['BSD 3-clause'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - contigs: + type: file + description: Multi FASTA file containing assembled contigs of a given sample + pattern: "*.fasta" + - reads: + type: file + description: Reads used to assemble contigs in FASTA or FASTQ format. Do not supply at the same time as abundance files. + pattern: "*.fasta" + - abund: + type: file + description: Contig abundance files, i.e. reads against each contig. See MaxBin2 README for details. Do not supply at the same time as read files. + +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" + - binned_fastas: + type: file + description: Binned contigs, one per bin designated with numeric IDs + pattern: "*.fasta.gz" + - summary: + type: file + description: Summary file describing which contigs are being classified into which bin + pattern: "*.summary" + - log: + type: file + description: Log file recording the core steps of MaxBin algorithm + pattern: "*.log.gz" + - marker: + type: file + description: Marker gene presence numbers for each bin + pattern: "*.marker.gz" + - unbinned_fasta: + type: file + description: All sequences that pass the minimum length threshold but are not classified successfully. + pattern: "*.noclass.gz" + - tooshort_fasta: + type: file + description: All sequences that do not meet the minimum length threshold. + pattern: "*.tooshort.gz" + - marker_genes: + type: file + description: All sequences that do not meet the minimum length threshold. + pattern: "*.marker_of_each_gene.tar.gz" + +authors: + - "@jfy133" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 343a0fc2..98a6204c 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -686,6 +686,10 @@ mashtree: - modules/mashtree/** - tests/modules/mashtree/** +maxbin2: + - modules/maxbin2/** + - tests/modules/maxbin2/** + megahit: - modules/megahit/** - tests/modules/megahit/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index d7eda458..858e7737 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -239,5 +239,20 @@ params { hello = "${test_data_dir}/generic/txt/hello.txt" } } + 'bacteroides_fragilis'{ + 'genome' { + genome_fna_gz = "${test_data_dir}/genomics/bacteroides_fragilis/genome/genome.fna.gz" + } + 'illumina' { + test1_contigs_fa_gz = "${test_data_dir}/genomics/bacteroides_fragilis/illumina/fasta/test1.contigs.fa.gz" + test1_1_fastq_gz = "${test_data_dir}/genomics/bacteroides_fragilis/illumina/fastq/test1_1.fastq.gz" + test1_2_fastq_gz = "${test_data_dir}/genomics/bacteroides_fragilis/illumina/fastq/test1_2.fastq.gz" + test2_1_fastq_gz = "${test_data_dir}/genomics/bacteroides_fragilis/illumina/fastq/test2_1.fastq.gz" + test2_2_fastq_gz = "${test_data_dir}/genomics/bacteroides_fragilis/illumina/fastq/test2_2.fastq.gz" + } + 'nanopore' { + test_fastq_gz = "${test_data_dir}/genomics/bacteroides_fragilis/nanopore/fastq/test.fastq.gz" + } + } } } diff --git a/tests/modules/maxbin2/main.nf b/tests/modules/maxbin2/main.nf new file mode 100644 index 00000000..bede2c6a --- /dev/null +++ b/tests/modules/maxbin2/main.nf @@ -0,0 +1,17 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { MAXBIN2 } from '../../../modules/maxbin2/main.nf' addParams( options: [:] ) + +workflow test_maxbin2 { + + input = [ + [ id:'test1', single_end:false ], // meta map + file(params.test_data['bacteroides_fragilis']['illumina']['test1_contigs_fa_gz'], checkIfExists: true), + file(params.test_data['bacteroides_fragilis']['illumina']['test1_1_fastq_gz'], checkIfExists: true), + [] + ] + + MAXBIN2 ( input ) +} diff --git a/tests/modules/maxbin2/test.yml b/tests/modules/maxbin2/test.yml new file mode 100644 index 00000000..2721d17a --- /dev/null +++ b/tests/modules/maxbin2/test.yml @@ -0,0 +1,15 @@ +- name: maxbin2 + command: nextflow run ./tests/modules/maxbin2 -entry test_maxbin2 -c tests/config/nextflow.config + tags: + - maxbin2 + files: + - path: output/maxbin2/test1.001.fasta.gz + - path: output/maxbin2/test1.002.fasta.gz + - path: output/maxbin2/test1.log.gz + - path: output/maxbin2/test1.marker.gz + - path: output/maxbin2/test1.marker_of_each_bin.tar.gz + - path: output/maxbin2/test1.noclass.gz + - path: output/maxbin2/test1.summary + contains: + - "Bin name\tAbundance\tCompleteness\tGenome size\tGC content" + - path: output/maxbin2/test1.tooshort.gz