From 7afb962f0bd5d9b504331082fa4bafd498074a4b Mon Sep 17 00:00:00 2001 From: GCJMackenzie <43276267+GCJMackenzie@users.noreply.github.com> Date: Fri, 29 Oct 2021 17:21:34 +0100 Subject: [PATCH] New module genomicsdbimport (#857) * saving changes to checkout * saving to sort out other branch * removed yml tracking of files that cant be tracked due to directory name changing between runs * test data added, ready for pr * fix eol linting error * Update modules/gatk4/genomicsdbimport/main.nf Co-authored-by: Francesco L <53608000+lescai@users.noreply.github.com> * merging with master * update push to show progress * tests now working untar able to pass data to genomicsdbimport * commit to checkout * tests updated, module reworked to simplify and emit updated gendb * Apply suggestions from code review Co-authored-by: Harshil Patel * update meta.yml Priority of input options changed, updated to reflect this * Update test.yml name prefix changed in main script, test.yml updated to reflect this * fix tests due to review changes Co-authored-by: GCJMackenzie Co-authored-by: Francesco L <53608000+lescai@users.noreply.github.com> Co-authored-by: Harshil Patel --- modules/gatk4/genomicsdbimport/functions.nf | 78 ++++++++++++++++++ modules/gatk4/genomicsdbimport/main.nf | 67 ++++++++++++++++ modules/gatk4/genomicsdbimport/meta.yml | 80 +++++++++++++++++++ tests/config/pytest_modules.yml | 4 + tests/config/test_data.config | 2 + tests/modules/gatk4/genomicsdbimport/main.nf | 61 ++++++++++++++ tests/modules/gatk4/genomicsdbimport/test.yml | 50 ++++++++++++ 7 files changed, 342 insertions(+) create mode 100644 modules/gatk4/genomicsdbimport/functions.nf create mode 100644 modules/gatk4/genomicsdbimport/main.nf create mode 100644 modules/gatk4/genomicsdbimport/meta.yml create mode 100644 tests/modules/gatk4/genomicsdbimport/main.nf create mode 100644 tests/modules/gatk4/genomicsdbimport/test.yml diff --git a/modules/gatk4/genomicsdbimport/functions.nf b/modules/gatk4/genomicsdbimport/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/gatk4/genomicsdbimport/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/gatk4/genomicsdbimport/main.nf b/modules/gatk4/genomicsdbimport/main.nf new file mode 100644 index 00000000..aa4fceb0 --- /dev/null +++ b/modules/gatk4/genomicsdbimport/main.nf @@ -0,0 +1,67 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process GATK4_GENOMICSDBIMPORT { + 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::gatk4=4.2.0.0" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/gatk4:4.2.0.0--0" + } else { + container "quay.io/biocontainers/gatk4:4.2.0.0--0" + } + + input: + tuple val(meta), path(vcf), path(tbi), path(intervalfile), val(intervalval), path(wspace) + val run_intlist + val run_updatewspace + val input_map + + output: + tuple val(meta), path("*_genomicsdb") , optional:true, emit: genomicsdb + tuple val(meta), path("$updated_db") , optional:true, emit: updatedb + tuple val(meta), path("*.interval_list"), optional:true, emit: intervallist + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + + // settings for running default create gendb mode + def inputs_command = input_map ? "--sample-name-map ${vcf[0]}" : "${'-V ' + vcf.join(' -V')}" + def dir_command = "--genomicsdb-workspace-path ${prefix}" + def intervals_command = intervalfile ? " -L ${intervalfile} " : " -L ${intervalval} " + + // settings changed for running get intervals list mode if run_intlist is true + if (run_intlist) { + inputs_command = '' + dir_command = "--genomicsdb-update-workspace-path ${wspace}" + intervals_command = "--output-interval-list-to-file ${prefix}.interval_list" + } + + // settings changed for running update gendb mode. inputs_command same as default, update_db forces module to emit the updated gendb + if (run_updatewspace) { + dir_command = "--genomicsdb-update-workspace-path ${wspace}" + intervals_command = '' + updated_db = wspace.toString() + } + + """ + gatk GenomicsDBImport \\ + $inputs_command \\ + $dir_command \\ + $intervals_command \\ + $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$(echo \$(gatk --version 2>&1) | sed 's/^.*(GATK) v//; s/ .*\$//') + END_VERSIONS + """ +} diff --git a/modules/gatk4/genomicsdbimport/meta.yml b/modules/gatk4/genomicsdbimport/meta.yml new file mode 100644 index 00000000..f7a32e7e --- /dev/null +++ b/modules/gatk4/genomicsdbimport/meta.yml @@ -0,0 +1,80 @@ +name: gatk4_genomicsdbimport +description: merge GVCFs from multiple samples. For use in joint genotyping or somatic panel of normal creation. +keywords: + - gatk4 + - genomicsdbimport + - genomicsdb + - panelofnormalscreation + - jointgenotyping +tools: + - gatk4: + 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. + homepage: https://gatk.broadinstitute.org/hc/en-us + documentation: https://gatk.broadinstitute.org/hc/en-us/categories/360002369672s + doi: 10.1158/1538-7445.AM2017-3590 + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test'] + - vcf: + type: list + description: either a list of vcf files to be used to create or update a genomicsdb, or a file that contains a map to vcf files to be used. + pattern: "*.vcf.gz" + + - tbi: + type: list + description: list of tbi files that match with the input vcf files + pattern: "*.vcf.gz_tbi" + + - wspace: + type: path + description: path to an existing genomicsdb to be used in update db mode or get intervals mode. This WILL NOT specify name of a new genomicsdb in create db mode. + pattern: "/path/to/existing/gendb" + + - intervalfile: + type: file + description: file containing the intervals to be used when creating the genomicsdb + pattern: "*.interval_list" + + - intervalval: + type: string + description: if an intervals file has not been spcified, the value enetered here will be used as an interval via the "-L" argument + pattern: "example: chr1:1000-10000" + + - run_intlist: + type: boolean + description: Specify whether to run get interval list mode, this option cannot be specified at the same time as run_updatewspace. + pattern: "true/false" + + - run_updatewspace: + type: boolean + description: Specify whether to run update genomicsdb mode, this option takes priority over run_intlist. + pattern: "true/false" + + - input_map: + type: boolean + description: Specify whether the vcf input is providing a list of vcf file(s) or a single file containing a map of paths to vcf files to be used to create or update a genomicsdb. + pattern: "*.sample_map" + +output: + - genomicsdb: + type: directory + description: Directory containing the files that compose the genomicsdb workspace, this is only output for create mode, as update changes an existing db + pattern: "*_genomicsdb" + - intervallist: + type: file + description: File containing the intervals used to generate the genomicsdb, only created by get intervals mode. + pattern: "*.interval_list" + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@GCJMackenzie" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index d7fed0c0..db10b55b 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -450,6 +450,10 @@ gatk4/fastqtosam: - modules/gatk4/fastqtosam/** - tests/modules/gatk4/fastqtosam/** +gatk4/genomicsdbimport: + - modules/gatk4/genomicsdbimport/** + - tests/modules/gatk4/genomicsdbimport/** + gatk4/filtermutectcalls: - modules/gatk4/filtermutectcalls/** - tests/modules/gatk4/filtermutectcalls/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index c05e1c8f..d0489e03 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -103,6 +103,7 @@ params { genome_dict = "${test_data_dir}/genomics/homo_sapiens/genome/genome.dict" genome_gff3 = "${test_data_dir}/genomics/homo_sapiens/genome/genome.gff3" genome_gtf = "${test_data_dir}/genomics/homo_sapiens/genome/genome.gtf" + genome_interval_list = "${test_data_dir}/genomics/homo_sapiens/genome/genome.interval_list" genome_sizes = "${test_data_dir}/genomics/homo_sapiens/genome/genome.sizes" genome_bed = "${test_data_dir}/genomics/homo_sapiens/genome/genome.bed" genome_header = "${test_data_dir}/genomics/homo_sapiens/genome/genome.header" @@ -181,6 +182,7 @@ params { test2_baserecalibrator_table = "${test_data_dir}/genomics/homo_sapiens/illumina/gatk/test2.baserecalibrator.table" test_pileups_table = "${test_data_dir}/genomics/homo_sapiens/illumina/gatk/test.pileups.table" test2_pileups_table = "${test_data_dir}/genomics/homo_sapiens/illumina/gatk/test2.pileups.table" + test_genomicsdb_tar_gz = "${test_data_dir}/genomics/homo_sapiens/illumina/gatk/test_genomicsdb.tar.gz" test_test2_paired_mutect2_calls_vcf_gz = "${test_data_dir}/genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz" test_test2_paired_mutect2_calls_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi" diff --git a/tests/modules/gatk4/genomicsdbimport/main.nf b/tests/modules/gatk4/genomicsdbimport/main.nf new file mode 100644 index 00000000..ef67b04a --- /dev/null +++ b/tests/modules/gatk4/genomicsdbimport/main.nf @@ -0,0 +1,61 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { UNTAR } from '../../../../modules/untar/main.nf' addParams( options: [:] ) +include { GATK4_GENOMICSDBIMPORT } from '../../../../modules/gatk4/genomicsdbimport/main.nf' addParams( options: [:] ) + +workflow test_gatk4_genomicsdbimport_create_genomicsdb { + + input = [ [ id:'test_genomicsdb'], // meta map + file(params.test_data['homo_sapiens']['illumina']['test_genome_vcf_gz'], checkIfExists: true) , + file(params.test_data['homo_sapiens']['illumina']['test_genome_vcf_gz_tbi'], checkIfExists: true) , + file(params.test_data['homo_sapiens']['genome']['genome_interval_list'], checkIfExists: true) , + [] , + [] ] + + run_intlist = false + run_updatewspace = false + input_map = false + + GATK4_GENOMICSDBIMPORT ( input, run_intlist, run_updatewspace, input_map ) +} + +workflow test_gatk4_genomicsdbimport_get_intervalslist { + db = file(params.test_data['homo_sapiens']['illumina']['test_genomicsdb_tar_gz'], checkIfExists: true) + + UNTAR ( db ) + + def input = Channel.of([ [ id:'test_genomicsdb'], // meta map + [] , + [] , + [] , + [] ]) + .combine(UNTAR.out.untar) + + run_intlist = true + run_updatewspace = false + input_map = false + + GATK4_GENOMICSDBIMPORT ( input, run_intlist, run_updatewspace, input_map ) +} + +workflow test_gatk4_genomicsdbimport_update_genomicsdb { + db = file(params.test_data['homo_sapiens']['illumina']['test_genomicsdb_tar_gz'], checkIfExists: true) + + UNTAR ( db ) + + def input = Channel.of([ [ id:'test_genomicsdb'], // meta map + file( params.test_data['homo_sapiens']['illumina']['test2_genome_vcf_gz'] , checkIfExists: true) , + file( params.test_data['homo_sapiens']['illumina']['test2_genome_vcf_gz_tbi'] , checkIfExists: true) , + [] , + [] ]) + .combine(UNTAR.out.untar) + + run_intlist = false + run_updatewspace = true + input_map = false + + GATK4_GENOMICSDBIMPORT ( input, run_intlist, run_updatewspace, input_map ) + +} diff --git a/tests/modules/gatk4/genomicsdbimport/test.yml b/tests/modules/gatk4/genomicsdbimport/test.yml new file mode 100644 index 00000000..68f5ae7a --- /dev/null +++ b/tests/modules/gatk4/genomicsdbimport/test.yml @@ -0,0 +1,50 @@ +- name: gatk4 genomicsdbimport test_gatk4_genomicsdbimport_create_genomicsdb + command: nextflow run tests/modules/gatk4/genomicsdbimport -entry test_gatk4_genomicsdbimport_create_genomicsdb -c tests/config/nextflow.config + tags: + - gatk4/genomicsdbimport + - gatk4 + files: + - path: output/gatk4/test_genomicsdb/__tiledb_workspace.tdb + md5sum: d41d8cd98f00b204e9800998ecf8427e + - path: output/gatk4/test_genomicsdb/callset.json + md5sum: a7d07d1c86449bbb1091ff29368da07a + - path: output/gatk4/test_genomicsdb/chr22$1$40001/.__consolidation_lock + md5sum: d41d8cd98f00b204e9800998ecf8427e + - path: output/gatk4/test_genomicsdb/chr22$1$40001/__array_schema.tdb + - path: output/gatk4/test_genomicsdb/chr22$1$40001/genomicsdb_meta_dir/genomicsdb_column_bounds.json + md5sum: 2502f79658bc000578ebcfddfc1194c0 + - path: output/gatk4/test_genomicsdb/vcfheader.vcf + contains: + - "FORMAT=