From 16062f6425481c160297c6530f359f4e02194d52 Mon Sep 17 00:00:00 2001 From: ilight1542 Date: Tue, 2 Nov 2021 12:52:12 +0100 Subject: [PATCH] partial implementation of unifiedgenotyper --- modules/gatk3/unifiedgenotyper/functions.nf | 78 +++++++++++++++++++ modules/gatk3/unifiedgenotyper/main.nf | 46 +++++++++++ modules/gatk3/unifiedgenotyper/meta.yml | 41 ++++++++++ tests/config/pytest_modules.yml | 4 + tests/modules/gatk3/unifiedgenotyper/main.nf | 12 +++ tests/modules/gatk3/unifiedgenotyper/test.yml | 10 +++ 6 files changed, 191 insertions(+) create mode 100644 modules/gatk3/unifiedgenotyper/functions.nf create mode 100644 modules/gatk3/unifiedgenotyper/main.nf create mode 100644 modules/gatk3/unifiedgenotyper/meta.yml create mode 100644 tests/modules/gatk3/unifiedgenotyper/main.nf create mode 100644 tests/modules/gatk3/unifiedgenotyper/test.yml diff --git a/modules/gatk3/unifiedgenotyper/functions.nf b/modules/gatk3/unifiedgenotyper/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/gatk3/unifiedgenotyper/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/gatk3/unifiedgenotyper/main.nf b/modules/gatk3/unifiedgenotyper/main.nf new file mode 100644 index 00000000..e4b79524 --- /dev/null +++ b/modules/gatk3/unifiedgenotyper/main.nf @@ -0,0 +1,46 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process GATK3_UNIFIEDGENOTYPER { + tag '$bam' + 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:[:], publish_by_meta:[]) } + + // TODO nf-core: List required Conda package(s). + // Software MUST be pinned to channel (i.e. "bioconda"), version (i.e. "1.10"). + // For Conda, the build (i.e. "h9402c20_2") must be EXCLUDED to support installation on different operating systems. + // TODO nf-core: See section in main README for further information regarding finding and adding container addresses to the section below. + conda (params.enable_conda ? "YOUR-TOOL-HERE" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/YOUR-TOOL-HERE" + } else { + container "quay.io/biocontainers/YOUR-TOOL-HERE" + } + + input: + path bam + path ref + + output: + path "*.vcf", emit: vcf + path "versions.yml", emit: versions + + script: + """ + gatk -T UnifiedGenotyper \\ + -R $ref \\ + -I $bam \\ + -o $vcf \\ + $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( samtools --version 2>&1 | sed 's/^.*samtools //; s/Using.*\$//' ) + END_VERSIONS + """ +} diff --git a/modules/gatk3/unifiedgenotyper/meta.yml b/modules/gatk3/unifiedgenotyper/meta.yml new file mode 100644 index 00000000..3fb1616b --- /dev/null +++ b/modules/gatk3/unifiedgenotyper/meta.yml @@ -0,0 +1,41 @@ +name: gatk3_unifiedgenotyper +description: UnifiedGenotyper from GATK 3.5, replaced by haplotyper caller. only use if needed for multivcfanalyzer +keywords: + - gatk + - unifiedgenotyper + - vcf + - multivcfanalyzer +tools: + - gatk3: + description: + Developed in the Data Sciences Platform at the Broad Institute, the toolkit offers a wide variety of tools + with a primary focus on variant discovery and genotyping. Its powerful processing engine + and high-performance computing features make it capable of taking on projects of any size. Release 3.5 + homepage: https://gatk.broadinstitute.org/hc/en-us + documentation: https://sites.google.com/a/broadinstitute.org/legacy-gatk-forum-discussions/tutorials/2804-howto-Call-variants-with-the-UnifiedGenotyper + tool_dev_url: https://gatk.broadinstitute.org/hc/en-us + doi: 10.1158/1538-7445.AM2017-3590 + licence: ['Apache-2.0'] + +input: + - bam: + type: file + description: BAM file for input + pattern: "*.{bam}" + - ref: + type: file + description: reference file used for mapping + pattern: "*.fa" + +output: + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - vcf: + type: file + description: unfiltered variant call format file + pattern: "*.{vcf}" + +authors: + - "@yocra3" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 98a6204c..e0d485a2 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -390,6 +390,10 @@ freebayes: - modules/freebayes/** - tests/modules/freebayes/** +gatk3/unifiedgenotyper: + - modules/gatk3/unifiedgenotyper/** + - tests/modules/gatk3/unifiedgenotyper/** + gatk4/applybqsr: - modules/gatk4/applybqsr/** - tests/modules/gatk4/applybqsr/** diff --git a/tests/modules/gatk3/unifiedgenotyper/main.nf b/tests/modules/gatk3/unifiedgenotyper/main.nf new file mode 100644 index 00000000..22d495ec --- /dev/null +++ b/tests/modules/gatk3/unifiedgenotyper/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GATK3_UNIFIEDGENOTYPER } from '../../../../modules/gatk3/unifiedgenotyper/main.nf' addParams( options: [:] ) + +workflow test_gatk3_unifiedgenotyper { + + input = file(params.test_data['sarscov2']['illumina']['test_single_end_bam'], checkIfExists: true) + + GATK3_UNIFIEDGENOTYPER ( input ) +} diff --git a/tests/modules/gatk3/unifiedgenotyper/test.yml b/tests/modules/gatk3/unifiedgenotyper/test.yml new file mode 100644 index 00000000..0ca98e0f --- /dev/null +++ b/tests/modules/gatk3/unifiedgenotyper/test.yml @@ -0,0 +1,10 @@ +## TODO nf-core: Please run the following command to build this file: +# nf-core modules create-test-yml gatk3/unifiedgenotyper +- name: gatk3 unifiedgenotyper + command: nextflow run ./tests/modules/gatk3/unifiedgenotyper -entry test_gatk3_unifiedgenotyper -c tests/config/nextflow.config + tags: + - gatk3 + - gatk3/unifiedgenotyper + files: + - path: output/gatk3/test.bam + md5sum: e667c7caad0bc4b7ac383fd023c654fc