Add metaphlan3 module (#543)

* Add metaphlan3 module

* remove whitespace
This commit is contained in:
MGordon09 2021-06-25 07:15:15 +01:00 committed by GitHub
parent e0b7952b56
commit 4d711a1428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 356 additions and 0 deletions

View file

@ -0,0 +1,68 @@
//
// 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()
}
//
// 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) {
if (!args.filename.endsWith('.version.txt')) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
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,50 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process METAPHLAN3 {
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::metaphlan=3.0.10" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/metaphlan:3.0.10--pyhb7b1952_0"
} else {
container "quay.io/biocontainers/metaphlan:3.0.10--pyhb7b1952_0"
}
input:
tuple val(meta), path(input)
path metaphlan_db
output:
tuple val(meta), path("*_profile.txt") , emit: profile
tuple val(meta), path("*.biom") , emit: biom
tuple val(meta), path('*.bowtie2out.txt'), optional:true, emit: bt2out
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def input_type = ("$input".endsWith(".fastq.gz")) ? "--input_type fastq" : ("$input".contains(".fasta")) ? "--input_type fasta" : ("$input".endsWith(".bowtie2out.txt")) ? "--input_type bowtie2out" : "--input_type sam"
def input_data = ("$input_type".contains("fastq")) && !meta.single_end ? "${input[0]},${input[1]}" : "$input"
def bowtie2_out = "$input_type" == "--input_type bowtie2out" || "$input_type" == "--input_type sam" ? '' : "--bowtie2out ${prefix}.bowtie2out.txt"
"""
metaphlan \\
--nproc $task.cpus \\
$input_type \\
$input_data \\
$options.args \\
$bowtie2_out \\
--bowtie2db ${metaphlan_db} \\
--biom ${prefix}.biom \\
--output_file ${prefix}_profile.txt
echo \$(metaphlan --version 2>&1) | awk '{print \$3}' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,52 @@
name: metaphlan3
description: MetaPhlAn is a tool for profiling the composition of microbial communities from metagenomic shotgun sequencing data.
keywords:
- metagenomics
- classification
- fastq
- bam
- fasta
tools:
- metaphlan3:
description: Identify clades (phyla to species) present in the metagenome obtained from a microbiome sample and their relative abundance
homepage: https://huttenhower.sph.harvard.edu/metaphlan/
documentation: https://github.com/biobakery/MetaPhlAn
doi: "10.7554/eLife.65088"
licence: ['MIT License']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- input:
type: file
description: Metaphlan 3.0 can classify the metagenome from a variety of input data types, including FASTQ files (single-end and paired-end), FASTA, bowtie2-produced SAM files (produced from alignments to the MetaPHlAn marker database) and intermediate bowtie2 alignment files (bowtie2out)
pattern: "*.{fastq.gz, fasta, fasta.gz, sam, bowtie2out.txt}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
- profile:
type: file
description: Tab-separated output file of the predicted taxon relative abundances
pattern: "*.{txt}"
- biom:
type: file
description: General-use format for representing biological sample by observation contingency tables
pattern: "*.{biom}"
- bowtie2out:
type: file
description: Intermediate Bowtie2 output produced from mapping the metagenome against the MetaPHlAn marker database ( not compatible with `bowtie2out` files generated with MetaPhlAn versions below 3 )
pattern: "*.{bowtie2out.txt}"
authors:
- "@MGordon09"

View file

@ -422,6 +422,10 @@ mash/sketch:
- software/mash/sketch/**
- tests/software/mash/sketch/**
metaphlan3:
- software/metaphlan3/**
- tests/software/metaphlan3/**
methyldackel/extract:
- software/methyldackel/extract/**
- tests/software/methyldackel/extract/**

View file

@ -0,0 +1,59 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { UNTAR } from '../../../software/untar/main.nf' addParams( options: [:] )
include { SAMTOOLS_VIEW } from '../../../software/samtools/view/main.nf' addParams( options: ['suffix': '.sam'] )
include { METAPHLAN3 } from '../../../software/metaphlan3/main.nf' addParams( options: [ 'args':'--index mpa_v30_CHOCOPhlAn_201901 --add_viruses --bt2_ps very-sensitive-local' ] )
workflow test_metaphlan3_single_end {
input = [ [ id:'test', single_end:true ], // meta map
[ file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) ]
]
db = channel.fromPath('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/metaphlan_database.tar.gz', type: 'dir', checkIfExists: true)
UNTAR ( db )
METAPHLAN3 ( input, UNTAR.out.untar )
}
workflow test_metaphlan3_paired_end {
input = [ [ id:'test', single_end:false ], // meta map
[ file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) ]
]
db = channel.fromPath('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/metaphlan_database.tar.gz', type: 'dir', checkIfExists: true)
UNTAR ( db )
METAPHLAN3 ( input, UNTAR.out.untar )
}
workflow test_metaphlan3_sam {
input = [ [ id:'test'], // meta map
[ file(params.test_data['sarscov2']['illumina']['test_single_end_bam'], checkIfExists: true) ]
]
db = channel.fromPath('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/metaphlan_database.tar.gz', type: 'dir', checkIfExists: true)
UNTAR ( db )
SAMTOOLS_VIEW ( input )
METAPHLAN3 ( SAMTOOLS_VIEW.out.bam, UNTAR.out.untar )
}
workflow test_metaphlan3_fasta {
input = [ [ id:'test', single_end:true], // meta map
[ file(params.test_data['sarscov2']['genome']['transcriptome_fasta'], checkIfExists: true) ]
]
db = channel.fromPath('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/metaphlan_database.tar.gz', type: 'dir', checkIfExists: true)
UNTAR ( db )
METAPHLAN3 ( input, UNTAR.out.untar )
}

View file

@ -0,0 +1,123 @@
- name: metaphlan3 test_metaphlan3_single_end
command: nextflow run tests/software/metaphlan3 -entry test_metaphlan3_single_end -c tests/config/nextflow.config
tags:
- metaphlan3
files:
- path: output/metaphlan3/test.biom
contains:
- '"format": "Biological Observation Matrix 1.0.0","format_url": "http://biom-format.org","generated_by"'
- path: output/metaphlan3/test.bowtie2out.txt
md5sum: ef46a9c6a8ce9cae26fbfd5527116fd5
- path: output/metaphlan3/test_profile.txt
md5sum: 72d40ee2304c162f3c165e1e578ed152
- path: output/untar/metaphlan_database/mpa_latest
md5sum: b1337362f607000384563a56a6ff4790
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.1.bt2
md5sum: d52a98fe273742ade7c744b819a7c5c1
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.2.bt2
md5sum: b14cc7faf3a4fae792160c917aebfe03
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.3.bt2
md5sum: 1bca5df879f2c6fad0c54984d0651bfb
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.4.bt2
md5sum: 249ee1c672d52d50cee41cb94b6adc42
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.fasta
md5sum: d3efe201c9eb449e877ead36656abf5f
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.pkl
md5sum: b208bb15eaef50d91cc7d5e35a1518ee
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.1.bt2
md5sum: ed05be063280e8629193e52903b07591
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.2.bt2
md5sum: 1ca16b905abf657b88ca2bc12e7ad404
- name: metaphlan3 test_metaphlan3_paired_end
command: nextflow run tests/software/metaphlan3 -entry test_metaphlan3_paired_end -c tests/config/nextflow.config
tags:
- metaphlan3
files:
- path: output/metaphlan3/test.biom
contains:
- '"format": "Biological Observation Matrix 1.0.0","format_url": "http://biom-format.org","generated_by"'
- path: output/metaphlan3/test.bowtie2out.txt
md5sum: ce11486fcc0e68fe7152867a3634e09a
- path: output/metaphlan3/test_profile.txt
md5sum: fcf99fec08ee00db6ef2c12fb93bc14b
- path: output/untar/metaphlan_database/mpa_latest
md5sum: b1337362f607000384563a56a6ff4790
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.1.bt2
md5sum: d52a98fe273742ade7c744b819a7c5c1
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.2.bt2
md5sum: b14cc7faf3a4fae792160c917aebfe03
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.3.bt2
md5sum: 1bca5df879f2c6fad0c54984d0651bfb
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.4.bt2
md5sum: 249ee1c672d52d50cee41cb94b6adc42
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.fasta
md5sum: d3efe201c9eb449e877ead36656abf5f
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.pkl
md5sum: b208bb15eaef50d91cc7d5e35a1518ee
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.1.bt2
md5sum: ed05be063280e8629193e52903b07591
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.2.bt2
md5sum: 1ca16b905abf657b88ca2bc12e7ad404
- name: metaphlan3 test_metaphlan3_sam
command: nextflow run tests/software/metaphlan3 -entry test_metaphlan3_sam -c tests/config/nextflow.config
tags:
- metaphlan3
files:
- path: output/metaphlan3/test.biom
contains:
- '"format": "Biological Observation Matrix 1.0.0","format_url": "http://biom-format.org","generated_by"'
- path: output/metaphlan3/test_profile.txt
md5sum: e050d49f7df8a23617880ef9ed7745a0
- path: output/samtools/test.sam.bam
md5sum: 1d5be3c91979ead358e3980e3e7c9acf
- path: output/untar/metaphlan_database/mpa_latest
md5sum: b1337362f607000384563a56a6ff4790
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.1.bt2
md5sum: d52a98fe273742ade7c744b819a7c5c1
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.2.bt2
md5sum: b14cc7faf3a4fae792160c917aebfe03
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.3.bt2
md5sum: 1bca5df879f2c6fad0c54984d0651bfb
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.4.bt2
md5sum: 249ee1c672d52d50cee41cb94b6adc42
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.fasta
md5sum: d3efe201c9eb449e877ead36656abf5f
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.pkl
md5sum: b208bb15eaef50d91cc7d5e35a1518ee
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.1.bt2
md5sum: ed05be063280e8629193e52903b07591
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.2.bt2
md5sum: 1ca16b905abf657b88ca2bc12e7ad404
- name: metaphlan3 test_metaphlan3_fasta
command: nextflow run tests/software/metaphlan3 -entry test_metaphlan3_fasta -c tests/config/nextflow.config
tags:
- metaphlan3
files:
- path: output/metaphlan3/test.biom
contains:
- '"format": "Biological Observation Matrix 1.0.0","format_url": "http://biom-format.org","generated_by"'
- path: output/metaphlan3/test.bowtie2out.txt
md5sum: fece494a410b8328608a11de10af6396
- path: output/metaphlan3/test_profile.txt
md5sum: d148c4203e5a9d59f5eea57207e40769
- path: output/untar/metaphlan_database/mpa_latest
md5sum: b1337362f607000384563a56a6ff4790
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.1.bt2
md5sum: d52a98fe273742ade7c744b819a7c5c1
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.2.bt2
md5sum: b14cc7faf3a4fae792160c917aebfe03
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.3.bt2
md5sum: 1bca5df879f2c6fad0c54984d0651bfb
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.4.bt2
md5sum: 249ee1c672d52d50cee41cb94b6adc42
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.fasta
md5sum: d3efe201c9eb449e877ead36656abf5f
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.pkl
md5sum: b208bb15eaef50d91cc7d5e35a1518ee
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.1.bt2
md5sum: ed05be063280e8629193e52903b07591
- path: output/untar/metaphlan_database/mpa_v30_CHOCOPhlAn_201901.rev.2.bt2
md5sum: 1ca16b905abf657b88ca2bc12e7ad404