From 25943a4c23c6ab585e740599df246b66078e966a Mon Sep 17 00:00:00 2001 From: Ramprasad Neethiraj <20065894+ramprasadn@users.noreply.github.com> Date: Wed, 22 Sep 2021 14:31:01 +0200 Subject: [PATCH] Add glnexus (#729) * Add glnexus * Fix lint error * Refactor * Suggested changes Co-authored-by: Harshil Patel --- modules/glnexus/functions.nf | 68 +++++++++++++++++++++++++++++++++ modules/glnexus/main.nf | 49 ++++++++++++++++++++++++ modules/glnexus/meta.yml | 36 +++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/glnexus/main.nf | 13 +++++++ tests/modules/glnexus/test.yml | 7 ++++ 6 files changed, 177 insertions(+) create mode 100644 modules/glnexus/functions.nf create mode 100644 modules/glnexus/main.nf create mode 100644 modules/glnexus/meta.yml create mode 100644 tests/modules/glnexus/main.nf create mode 100644 tests/modules/glnexus/test.yml diff --git a/modules/glnexus/functions.nf b/modules/glnexus/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/glnexus/functions.nf @@ -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" + } + } +} diff --git a/modules/glnexus/main.nf b/modules/glnexus/main.nf new file mode 100644 index 00000000..dadb9d60 --- /dev/null +++ b/modules/glnexus/main.nf @@ -0,0 +1,49 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process GLNEXUS { + 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::glnexus=1.4.1" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/glnexus:1.4.1--h40d77a6_0" + } else { + container "quay.io/biocontainers/glnexus:1.4.1--h40d77a6_0" + } + + input: + tuple val(meta), path(gvcfs) + + output: + tuple val(meta), path("*.bcf"), emit: bcf + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + + // Make list of GVCFs to merge + def input = gvcfs.collect { it.toString() } + def avail_mem = 3 + if (!task.memory) { + log.info '[Glnexus] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.' + } else { + avail_mem = task.memory.giga + } + """ + glnexus_cli \\ + --threads $task.cpus \\ + --mem-gbytes $avail_mem \\ + $options.args \\ + ${input.join(' ')} \\ + > ${prefix}.bcf + echo \$(glnexus_cli 2>&1) | head -n 1 | sed 's/^.*release //; s/ .*\$//' > ${software}.version.txt + """ +} diff --git a/modules/glnexus/meta.yml b/modules/glnexus/meta.yml new file mode 100644 index 00000000..f64a812e --- /dev/null +++ b/modules/glnexus/meta.yml @@ -0,0 +1,36 @@ +name: glnexus +description: merge gVCF files and perform joint variant calling +keywords: + - merge + - gvcf +tools: + - glnexus: + description: scalable gVCF merging and joint variant calling for population sequencing projects. + homepage: https://github.com/dnanexus-rnd/GLnexus + documentation: https://github.com/dnanexus-rnd/GLnexus/wiki/Getting-Started + tool_dev_url: None + doi: https://doi.org/10.1101/343970 + licence: ['Apache License 2.0'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test' ] + - gvcfs: + type: list + description: Input genomic vcf files + pattern: "*.{gvcf,gvcf.gz,g.vcf,g.vcf.gz}" + +output: + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - bcf: + type: file + description: merged BCF file + pattern: "*.bcf" +authors: + - "@ramprasadn" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 43974ff7..5307d684 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -422,6 +422,10 @@ gffread: - modules/gffread/** - tests/modules/gffread/** +glnexus: + - modules/glnexus/** + - tests/modules/glnexus/** + graphmap2/align: - modules/graphmap2/align/** - tests/modules/graphmap2/align/** diff --git a/tests/modules/glnexus/main.nf b/tests/modules/glnexus/main.nf new file mode 100644 index 00000000..2a79b2fa --- /dev/null +++ b/tests/modules/glnexus/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GLNEXUS } from '../../../modules/glnexus/main.nf' addParams( options: [:] ) + +workflow test_glnexus { + input = [ [ id:'test' ], // meta map + [ file(params.test_data['homo_sapiens']['illumina']['test_genome_vcf_gz'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test2_genome_vcf_gz'], checkIfExists: true) ] + ] + GLNEXUS ( input ) +} diff --git a/tests/modules/glnexus/test.yml b/tests/modules/glnexus/test.yml new file mode 100644 index 00000000..c7b255ee --- /dev/null +++ b/tests/modules/glnexus/test.yml @@ -0,0 +1,7 @@ +- name: glnexus test_glnexus + command: nextflow run tests/modules/glnexus -entry test_glnexus -c tests/config/nextflow.config + tags: + - glnexus + files: + - path: output/glnexus/test.bcf + md5sum: 33ac8c9f3ff54e6a23177ba94a449173