New module: metabat2 (#875)

* add pydamage module

* remove TODOs

* split module by subcommands

* update version parsing

* remove forgotten TODOs

* update module names

* remove old holistic module

* Update modules/pydamage/analyze/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* add keywords

* update resource requirement

* Update modules/pydamage/filter/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/pydamage/filter/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* merge from upstream

* update pydamage from upstream

* add freebayes

* update pydamage test from upstream

* fix meta.yml

* update functions.nf

* update test.yml

* update version parsing

* update version parsing

* fix indentation

* Update modules/freebayes/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/freebayes/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/freebayes/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* add optional inputs

* Update modules/freebayes/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* add bed test

* add metabat2 module

* only freebayes

* remove metabat2

* update md5sum because of vcf including date of the day

* add keyword

* rescue conflicted files

* attempt to fix ECLint

* add pytest workflow for metabat

* remove -

* Update modules/metabat2/jgisummarizebamcontigdepths/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/metabat2/metabat2/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/metabat2/metabat2/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/metabat2/jgisummarizebamcontigdepths/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* add optional inputs/outpus

* remove trailing whitespace

* compressing and removing not reproducible md5sums

* follow symlinks while decompressing

* Update tests/modules/metabat2/metabat2/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update tests/modules/metabat2/metabat2/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* split tests

* export env variable

* Update modules/metabat2/jgisummarizebamcontigdepths/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/metabat2/jgisummarizebamcontigdepths/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/metabat2/metabat2/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/metabat2/metabat2/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* answer PR comments and switch to bgzip

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>
Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
Co-authored-by: Gregor Sturm <mail@gregor-sturm.de>
This commit is contained in:
Maxime Borry 2021-11-08 21:08:26 +01:00 committed by GitHub
parent c10f9eb817
commit e0ada7d219
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 448 additions and 0 deletions

View file

@ -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"
}
}

View file

@ -0,0 +1,44 @@
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS {
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::metabat2=2.15" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/metabat2:2.15--h986a166_1"
} else {
container "quay.io/biocontainers/metabat2:2.15--h986a166_1"
}
input:
tuple val(meta), path(bam), path(bai)
output:
tuple val(meta), path("*.txt.gz"), emit: depth
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
export OMP_NUM_THREADS=$task.cpus
jgi_summarize_bam_contig_depths \\
--outputDepth ${prefix}.txt \\
$options.args \\
$bam
bgzip --threads $task.cpus ${prefix}.txt
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( metabat2 --help 2>&1 | head -n 2 | tail -n 1| sed 's/.*\\:\\([0-9]*\\.[0-9]*\\).*/\\1/' )
END_VERSIONS
"""
}

View file

@ -0,0 +1,50 @@
name: metabat2_jgisummarizebamcontigdepths
description: Depth computation per contig step of metabat2
keywords:
- sort
- binning
- depth
- bam
- coverage
- de novo assembly
tools:
- metabat2:
description: Metagenome binning
homepage: https://bitbucket.org/berkeleylab/metabat/src/master/
documentation: https://bitbucket.org/berkeleylab/metabat/src/master/
tool_dev_url: https://bitbucket.org/berkeleylab/metabat/src/master/
doi: "10.7717/peerj.7359"
licence: ['BSD-3-clause-LBNL']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: Sorted BAM file of reads aligned on the assembled contigs
pattern: "*.bam"
- bai:
type: file
description: BAM index file
pattern: "*.bam.bai"
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"
- depth:
type: file
description: Text file listing the coverage per contig
pattern: ".txt.gz"
authors:
- "@maxibor"

View file

@ -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"
}
}

View file

@ -0,0 +1,53 @@
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process METABAT2_METABAT2 {
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::metabat2=2.15" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/metabat2:2.15--h986a166_1"
} else {
container "quay.io/biocontainers/metabat2:2.15--h986a166_1"
}
input:
tuple val(meta), path(fasta), path(depth)
output:
tuple val(meta), path("bins/*.fa.gz") , optional:true , emit: fasta
tuple val(meta), path("*.tsv.gz"), optional:true , emit: membership
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def decompress_depth = depth ? "gzip -d -f $depth" : ""
def depth_file = depth ? "-a ${depth.baseName}" : ""
"""
$decompress_depth
metabat2 \\
$options.args \\
-i $fasta \\
$depth_file \\
-t $task.cpus \\
--saveCls \\
-o metabat2/${prefix}
mv metabat2/${prefix} ${prefix}.tsv
mv metabat2 bins
bgzip --threads $task.cpus ${prefix}.tsv
bgzip --threads $task.cpus bins/*.fa
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( metabat2 --help 2>&1 | head -n 2 | tail -n 1| sed 's/.*\\:\\([0-9]*\\.[0-9]*\\).*/\\1/' )
END_VERSIONS
"""
}

View file

@ -0,0 +1,56 @@
name: metabat2_metabat2
keywords:
- sort
- binning
- depth
- bam
- coverage
- de novo assembly
tools:
- metabat2:
description: Metagenome binning
homepage: https://bitbucket.org/berkeleylab/metabat/src/master/
documentation: https://bitbucket.org/berkeleylab/metabat/src/master/
tool_dev_url: https://bitbucket.org/berkeleylab/metabat/src/master/
doi: "10.7717/peerj.7359"
licence: ['BSD-3-clause-LBNL']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- fasta:
type: file
description: Fasta file of the assembled contigs
pattern: "*.{fa,fas,fasta,fna,fa.gz,fas.gz,fasta.gz,fna.gz}"
- depth:
type: file
description: |
Optional text file listing the coverage per contig pre-generated
by metabat2_jgisummarizebamcontigdepths
pattern: "*.txt"
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"
- fasta:
type: file
description: Bins created from assembled contigs in fasta file
pattern: "*.fa.gz"
- membership:
type: file
description: cluster memberships as a matrix format.
pattern: "*.tsv.gz"
authors:
- "@maxibor"

View file

@ -774,10 +774,19 @@ megahit:
- modules/megahit/** - modules/megahit/**
- tests/modules/megahit/** - tests/modules/megahit/**
metabat2/jgisummarizebamcontigdepths:
- modules/metabat2/jgisummarizebamcontigdepths/**
- tests/modules/metabat2/jgisummarizebamcontigdepths/**
metabat2/metabat2:
- modules/metabat2/metabat2/**
- tests/modules/metabat2/metabat2/**
meningotype: meningotype:
- modules/meningotype/** - modules/meningotype/**
- tests/modules/meningotype/** - tests/modules/meningotype/**
metaphlan3: metaphlan3:
- modules/metaphlan3/** - modules/metaphlan3/**
- tests/modules/metaphlan3/** - tests/modules/metaphlan3/**

View file

@ -0,0 +1,14 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS } from '../../../../modules/metabat2/jgisummarizebamcontigdepths/main.nf' addParams( options: [:] )
workflow test_metabat2_jgisummarizebamcontigdepths {
input = [ [ id:'test' ], // meta map
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS ( input )
}

View file

@ -0,0 +1,8 @@
- name: metabat2 jgisummarizebamcontigdepths test_metabat2_jgisummarizebamcontigdepths
command: nextflow run tests/modules/metabat2/jgisummarizebamcontigdepths -entry test_metabat2_jgisummarizebamcontigdepths -c tests/config/nextflow.config
tags:
- metabat2/jgisummarizebamcontigdepths
- metabat2
files:
- path: output/metabat2/test.txt.gz
md5sum: 8f735aa408d6c90e5a0310e06ace7a9a

View file

@ -0,0 +1,35 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { METABAT2_METABAT2 } from '../../../../modules/metabat2/metabat2/main.nf' addParams( options: [args: '--minContig 1500 --minCV 0.1 --minCVSum 0.1 --minClsSize 10 --minS 2'] )
include { METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS } from '../../../../modules/metabat2/jgisummarizebamcontigdepths/main.nf' addParams( options: [:] )
workflow test_metabat2_no_depth {
input_depth = [ [ id:'test', single_end:false ], // meta map
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
Channel.fromPath(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
.map { it -> [[ id:'test', single_end:false ], it, []] }
.set { input_metabat2 }
METABAT2_METABAT2 ( input_metabat2 )
}
workflow test_metabat2_depth {
input_depth = [ [ id:'test', single_end:false ], // meta map
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ]
METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS ( input_depth )
Channel.fromPath(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
.map { it -> [[ id:'test', single_end:false ], it] }
.join(METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS.out.depth)
.set { input_metabat2 }
METABAT2_METABAT2 ( input_metabat2 )
}

View file

@ -0,0 +1,23 @@
- name: metabat2 metabat2 test_metabat2_no_depth
command: nextflow run tests/modules/metabat2/metabat2 -entry test_metabat2_no_depth -c tests/config/nextflow.config
tags:
- metabat2/metabat2
- metabat2
files:
- path: output/metabat2/bins/test.1.fa.gz
md5sum: 0e9bce5b5a0033fd4411a21dec881170
- path: output/metabat2/test.tsv.gz
md5sum: ea77e8c4426d2337419905b57f1ec335
- name: metabat2 metabat2 test_metabat2_depth
command: nextflow run tests/modules/metabat2/metabat2 -entry test_metabat2_depth -c tests/config/nextflow.config
tags:
- metabat2/metabat2
- metabat2
files:
- path: output/metabat2/bins/test.1.fa.gz
md5sum: 0e9bce5b5a0033fd4411a21dec881170
- path: output/metabat2/test.tsv.gz
md5sum: ea77e8c4426d2337419905b57f1ec335
- path: output/metabat2/test.txt.gz
md5sum: 8f735aa408d6c90e5a0310e06ace7a9a