diff --git a/modules/cmseq/polymut/functions.nf b/modules/cmseq/polymut/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/cmseq/polymut/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/cmseq/polymut/main.nf b/modules/cmseq/polymut/main.nf new file mode 100644 index 00000000..4c061e26 --- /dev/null +++ b/modules/cmseq/polymut/main.nf @@ -0,0 +1,46 @@ +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +def VERSION = '1.0.4' + +process CMSEQ_POLYMUT { + tag "$meta.id" + label 'process_low' + 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::cmseq=1.0.4" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/cmseq:1.0.4--pyhb7b1952_0" + } else { + container "quay.io/biocontainers/cmseq:1.0.4--pyhb7b1952_0" + } + + input: + tuple val(meta), path(bam), path(bai), path(gff), path(fasta) + + output: + tuple val(meta), path("*.txt"), emit: polymut + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def fasta_refid = fasta ? "-c $fasta" : "" + def sortindex = bai ? "" : "--sortindex" + """ + polymut.py \\ + $options.args \\ + $sortindex \\ + $fasta_refid \\ + --gff_file $gff \\ + $bam > ${prefix}.txt + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( echo $VERSION ) + END_VERSIONS + """ +} diff --git a/modules/cmseq/polymut/meta.yml b/modules/cmseq/polymut/meta.yml new file mode 100644 index 00000000..49e6b519 --- /dev/null +++ b/modules/cmseq/polymut/meta.yml @@ -0,0 +1,61 @@ +name: cmseq_polymut +description: Calculates polymorphic site rates over protein coding genes +keywords: + - polymut + - polymorphic + - mags + - assembly + - polymorphic sites + - estimation + - protein coding genes + - cmseq + - bam + - coverage +tools: + - cmseq: + description: Set of utilities on sequences and BAM files + homepage: https://github.com/SegataLab/cmseq + documentation: https://github.com/SegataLab/cmseq + tool_dev_url: https://github.com/SegataLab/cmseq + licence: ['MIT License'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM file + pattern: "*.bam" + - bai: + type: file + description: BAM index file + pattern: "*.bai" + - gff: + type: file + description: GFF file used to extract protein-coding genes + pattern: "*.gff" + - fasta: + type: file + description: Optional fasta file to run on a subset of references in the BAM file. + pattern: .{fa,fasta,fas,fna} + +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" + - polymut: + type: file + description: Polymut report in `.txt` format. + pattern: "*.txt" + +authors: + - "@maxibor" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 39a1393d..2e5b55f1 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -274,6 +274,10 @@ chromap/index: - modules/chromap/index/** - tests/modules/chromap/index/** +cmseq/polymut: + - modules/cmseq/polymut/** + - tests/modules/cmseq/polymut/** + cnvkit: - modules/cnvkit/** - tests/modules/cnvkit/** diff --git a/tests/modules/cmseq/polymut/main.nf b/tests/modules/cmseq/polymut/main.nf new file mode 100644 index 00000000..729ed38f --- /dev/null +++ b/tests/modules/cmseq/polymut/main.nf @@ -0,0 +1,38 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { CMSEQ_POLYMUT } from '../../../../modules/cmseq/polymut/main.nf' addParams( options: [:] ) + +workflow test_cmseq_polymut_1 { + + input_1 = [ [ 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']['genome']['genome_gff3'], checkIfExists: true), + [] ] + + CMSEQ_POLYMUT( input_1 ) + +} + +workflow test_cmseq_polymut_2 { + input_2 = [ [ 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), + file(params.test_data['sarscov2']['genome']['genome_gff3'], checkIfExists: true), + [] ] + + CMSEQ_POLYMUT( input_2 ) +} + +workflow test_cmseq_polymut_3 { + input_3 = [ [ 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), + file(params.test_data['sarscov2']['genome']['genome_gff3'], checkIfExists: true), + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true), ] + + CMSEQ_POLYMUT( input_3 ) +} + diff --git a/tests/modules/cmseq/polymut/test.yml b/tests/modules/cmseq/polymut/test.yml new file mode 100644 index 00000000..2a989cb9 --- /dev/null +++ b/tests/modules/cmseq/polymut/test.yml @@ -0,0 +1,26 @@ +- name: cmseq polymut test_cmseq_polymut_1 + command: nextflow run tests/modules/cmseq/polymut -entry test_cmseq_polymut_1 -c tests/config/nextflow.config + tags: + - cmseq/polymut + - cmseq + files: + - path: output/cmseq/test.txt + md5sum: fd325c1724ee23d132a9115c64494efc + +- name: cmseq polymut test_cmseq_polymut_2 + command: nextflow run tests/modules/cmseq/polymut -entry test_cmseq_polymut_2 -c tests/config/nextflow.config + tags: + - cmseq/polymut + - cmseq + files: + - path: output/cmseq/test.txt + md5sum: fd325c1724ee23d132a9115c64494efc + +- name: cmseq polymut test_cmseq_polymut_3 + command: nextflow run tests/modules/cmseq/polymut -entry test_cmseq_polymut_3 -c tests/config/nextflow.config + tags: + - cmseq/polymut + - cmseq + files: + - path: output/cmseq/test.txt + md5sum: fd325c1724ee23d132a9115c64494efc