Add glnexus (#729)

* Add glnexus

* Fix lint error

* Refactor

* Suggested changes

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
Ramprasad Neethiraj 2021-09-22 14:31:01 +02:00 committed by GitHub
parent 5758e9f451
commit 25943a4c23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 177 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"
}
}
}

49
modules/glnexus/main.nf Normal file
View file

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

36
modules/glnexus/meta.yml Normal file
View file

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

View file

@ -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/**

View file

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

View file

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