From 53109d53c029c52cf70407eb135c1117356efcde Mon Sep 17 00:00:00 2001 From: Nicholas Toda <30317107+ntoda03@users.noreply.github.com> Date: Mon, 22 Mar 2021 19:26:02 +0100 Subject: [PATCH] add gatk4/fastqtosam #198 (#311) * Inital nf-core create * remove TODO comments, input and output files defined * add get version in script * added flow control for single/paired end data * added script main commands * removed completed TODO messages * removed completed TODO messages * added software info * added input reads description * added output description * added description and keywords * added single end test * added paired end test * fixed sample name flag * fixed reverse read variable * added test yaml * update for pytest_software * order in pytest_software was different * replaced functions.nf with copy from another module * simplify read command line Co-authored-by: Harshil Patel Co-authored-by: Nicholas TODA Co-authored-by: Harshil Patel --- software/gatk4/fastqtosam/functions.nf | 59 ++++++++++++++++++++++++ software/gatk4/fastqtosam/main.nf | 40 ++++++++++++++++ software/gatk4/fastqtosam/meta.yml | 47 +++++++++++++++++++ tests/config/pytest_software.yml | 4 ++ tests/software/gatk4/fastqtosam/main.nf | 24 ++++++++++ tests/software/gatk4/fastqtosam/test.yml | 19 ++++++++ 6 files changed, 193 insertions(+) create mode 100644 software/gatk4/fastqtosam/functions.nf create mode 100644 software/gatk4/fastqtosam/main.nf create mode 100644 software/gatk4/fastqtosam/meta.yml create mode 100644 tests/software/gatk4/fastqtosam/main.nf create mode 100644 tests/software/gatk4/fastqtosam/test.yml diff --git a/software/gatk4/fastqtosam/functions.nf b/software/gatk4/fastqtosam/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/gatk4/fastqtosam/functions.nf @@ -0,0 +1,59 @@ +/* + * ----------------------------------------------------- + * 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.publish_by_id = args.publish_by_id ?: false + 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_id) { + path_list.add(args.publish_id) + } + 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/software/gatk4/fastqtosam/main.nf b/software/gatk4/fastqtosam/main.nf new file mode 100644 index 00000000..4e37a4c5 --- /dev/null +++ b/software/gatk4/fastqtosam/main.nf @@ -0,0 +1,40 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process GATK4_FASTQTOSAM { + 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), publish_id: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(reads) + + output: + tuple val(meta), path("*.bam"), emit: bam + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def read_files = meta.single_end ? "-F1 $reads" : "-F1 ${reads[0]} -F2 ${reads[1]}" + """ + gatk FastqToSam \\ + $read_files \\ + -O ${prefix}.bam \\ + -SM $prefix \\ + $options.args + gatk --version | grep Picard | sed "s/Picard Version: //g" > ${software}.version.txt + """ +} diff --git a/software/gatk4/fastqtosam/meta.yml b/software/gatk4/fastqtosam/meta.yml new file mode 100644 index 00000000..d574d67b --- /dev/null +++ b/software/gatk4/fastqtosam/meta.yml @@ -0,0 +1,47 @@ +name: gatk4_fastqtosam +description: Converts FastQ file to BAM format +keywords: + - bam + - fastq + - convert +tools: + - gatk4: + description: Genome Analysis Toolkit (GATK4) + 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 + tool_dev_url: https://github.com/broadinstitute/gatk + doi: "10.1158/1538-7445.AM2017-3590" + licence: ['BSD-3-clause'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - reads: + type: file + description: List of input FastQ files of size 1 and 2 for single-end and paired-end data, + respectively. + pattern: "*.fastq.gz" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - bam: + type: file + description: Converted BAM file + pattern: "*.bam" + +authors: + - "@ntoda03" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 630012ba..df39d82f 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -178,6 +178,10 @@ gatk4_createsequencedictionary: - software/gatk4/createsequencedictionary/** - tests/software/gatk4/createsequencedictionary/** +gatk4_fastqtosam: + - software/gatk4/fastqtosam/** + - tests/software/gatk4/fastqtosam/** + gatk4_mergebamalignment: - software/gatk4/mergebamalignment/** - tests/software/gatk4/mergebamalignment/** diff --git a/tests/software/gatk4/fastqtosam/main.nf b/tests/software/gatk4/fastqtosam/main.nf new file mode 100644 index 00000000..5128c14d --- /dev/null +++ b/tests/software/gatk4/fastqtosam/main.nf @@ -0,0 +1,24 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GATK4_FASTQTOSAM } from '../../../../software/gatk4/fastqtosam/main.nf' addParams( options: [:] ) + +workflow test_gatk4_fastqtosam_single_end { + + def input = [] + input = [ [ id:'test', single_end:true ], // meta map + file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_1.fastq.gz", checkIfExists: true) ] + + GATK4_FASTQTOSAM ( input ) +} + +workflow test_gatk4_fastqtosam_paired_end { + + def input = [] + input = [ [ id:'test', single_end:false ], // meta map + file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_1.fastq.gz", checkIfExists: true), + file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_2.fastq.gz", checkIfExists: true) ] + + GATK4_FASTQTOSAM ( input ) +} diff --git a/tests/software/gatk4/fastqtosam/test.yml b/tests/software/gatk4/fastqtosam/test.yml new file mode 100644 index 00000000..7d4926b4 --- /dev/null +++ b/tests/software/gatk4/fastqtosam/test.yml @@ -0,0 +1,19 @@ +- name: gatk4 fastqtosam test_gatk4_fastqtosam_single_end + command: nextflow run tests/software/gatk4/fastqtosam -entry test_gatk4_fastqtosam_single_end -c tests/config/nextflow.config + tags: + - gatk4_fastqtosam_single_end + - gatk4_fastqtosam + - gatk4 + files: + - path: output/gatk4/test.bam + md5sum: 4967100b2e4912c0e4ce0976d946bafb + +- name: gatk4 fastqtosam test_gatk4_fastqtosam_paired_end + command: nextflow run tests/software/gatk4/fastqtosam -entry test_gatk4_fastqtosam_paired_end -c tests/config/nextflow.config + tags: + - gatk4_fastqtosam_paired_end + - gatk4_fastqtosam + - gatk4 + files: + - path: output/gatk4/test.bam + md5sum: 4967100b2e4912c0e4ce0976d946bafb