add module for tbprofiler (#947)

* add module for tbprofiler

* Update test.yml

* Update meta.yml

Co-authored-by: Abhinav Sharma <abhi18av@users.noreply.github.com>
Co-authored-by: FriederikeHanssen <Friederike.hanssen@qbic.uni-tuebingen.de>
This commit is contained in:
Robert A. Petit III 2021-11-15 07:35:55 -07:00 committed by GitHub
parent 2c3c87a10f
commit 7be60774b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 234 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,48 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process TBPROFILER_PROFILE {
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::tb-profiler=3.0.8" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/tb-profiler:3.0.8--pypyh5e36f6f_0"
} else {
container "quay.io/biocontainers/tb-profiler:3.0.8--pypyh5e36f6f_0"
}
input:
tuple val(meta), path(reads)
output:
tuple val(meta), path("bam/*.bam") , emit: bam
tuple val(meta), path("results/*.csv") , emit: csv, optional: true
tuple val(meta), path("results/*.json"), emit: json
tuple val(meta), path("results/*.txt") , emit: txt, optional: true
tuple val(meta), path("vcf/*.vcf.gz") , emit: vcf
path "versions.yml" , emit: versions
script:
prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def input_reads = meta.single_end ? "--read1 $reads" : "--read1 ${reads[0]} --read2 ${reads[1]}"
"""
tb-profiler \\
profile \\
$options.args \\
--prefix ${prefix} \\
--threads $task.cpus \\
$input_reads
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( echo \$(tb-profiler --version 2>&1) | sed 's/TBProfiler version //')
END_VERSIONS
"""
}

View file

@ -0,0 +1,59 @@
name: tbprofiler_profile
description: A tool to detect resistance and lineages of M. tuberculosis genomes
keywords:
- Mycobacterium tuberculosis
- resistance
- serotype
tools:
- tbprofiler:
description: Profiling tool for Mycobacterium tuberculosis to detect drug resistance and lineage from WGS data
homepage: https://github.com/jodyphelan/TBProfiler
documentation: https://jodyphelan.gitbook.io/tb-profiler/
tool_dev_url: https://github.com/jodyphelan/TBProfiler
doi: "10.1186/s13073-019-0650-x"
licence: ['GPL v3']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- reads:
type: file
description: FASTQ file
pattern: "*.{fastq.gz,fq.gz}"
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"
- bam:
type: file
description: BAM file with alignment details
pattern: "*.bam"
- csv:
type: file
description: Optional CSV formated result file of resistance and strain type
pattern: "*.csv"
- json:
type: file
description: JSON formated result file of resistance and strain type
pattern: "*.json"
- txt:
type: file
description: Optional text file of resistance and strain type
pattern: "*.txt"
- vcf:
type: file
description: VCF with variant info again refernce genomes
pattern: "*.vcf"
authors:
- "@rpetit3"

View file

@ -1251,6 +1251,10 @@ tabix/tabix:
- modules/tabix/tabix/**
- tests/modules/tabix/tabix/**
tbprofiler/profile:
- modules/tbprofiler/profile/**
- tests/modules/tbprofiler/profile/**
tiddit/cov:
- modules/tiddit/cov/**
- tests/modules/tiddit/cov/**

View file

@ -0,0 +1,24 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { TBPROFILER_PROFILE as TBPROFILER_PROFILE_ILLUMINA } from '../../../../modules/tbprofiler/profile/main.nf' addParams( options: [args: '--platform illumina'] )
include { TBPROFILER_PROFILE as TBPROFILER_PROFILE_NANOPORE} from '../../../../modules/tbprofiler/profile/main.nf' addParams( options: [args: '--platform nanopore'] )
workflow test_tbprofiler_profile_illumina {
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) ] ]
TBPROFILER_PROFILE_ILLUMINA ( input )
}
workflow test_tbprofiler_profile_nanopore {
input = [ [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['nanopore']['test_fastq_gz'], checkIfExists: true) ]
TBPROFILER_PROFILE_NANOPORE ( input )
}

View file

@ -0,0 +1,21 @@
- name: tbprofiler profile illumina
command: nextflow run ./tests/modules/tbprofiler/profile -entry test_tbprofiler_profile_illumina -c tests/config/nextflow.config
tags:
- tbprofiler
- tbprofiler/profile
files:
- path: output/tbprofiler/bam/test.bam
- path: output/tbprofiler/results/test.results.json
contains: ['genome_positions', 'locus_tag', 'tbprofiler_version']
- path: output/tbprofiler/vcf/test.targets.csq.vcf.gz
- name: tbprofiler profile nanopore
command: nextflow run ./tests/modules/tbprofiler/profile -entry test_tbprofiler_profile_nanopore -c tests/config/nextflow.config
tags:
- tbprofiler
- tbprofiler/profile
files:
- path: output/tbprofiler/bam/test.bam
- path: output/tbprofiler/results/test.results.json
contains: ['genome_positions', 'locus_tag', 'tbprofiler_version']
- path: output/tbprofiler/vcf/test.targets.csq.vcf.gz