From 67b3e00f588ba473dd32bd8115eaddb4c52509c8 Mon Sep 17 00:00:00 2001 From: Erkison Ewomazino Odih Date: Wed, 24 Mar 2021 06:05:45 +0100 Subject: [PATCH] add flash module (#341) * add flash module * remove todo * run tests Co-authored-by: Harshil Patel --- software/flash/functions.nf | 60 ++++++++++++++++++++++++++++++++ software/flash/main.nf | 40 +++++++++++++++++++++ software/flash/meta.yml | 44 +++++++++++++++++++++++ tests/config/pytest_software.yml | 4 +++ tests/software/flash/main.nf | 15 ++++++++ tests/software/flash/test.yml | 11 ++++++ 6 files changed, 174 insertions(+) create mode 100644 software/flash/functions.nf create mode 100644 software/flash/main.nf create mode 100644 software/flash/meta.yml create mode 100644 tests/software/flash/main.nf create mode 100644 tests/software/flash/test.yml diff --git a/software/flash/functions.nf b/software/flash/functions.nf new file mode 100644 index 00000000..646c0ff1 --- /dev/null +++ b/software/flash/functions.nf @@ -0,0 +1,60 @@ +/* + * ----------------------------------------------------- + * 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_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" + } + } +} \ No newline at end of file diff --git a/software/flash/main.nf b/software/flash/main.nf new file mode 100644 index 00000000..399a2705 --- /dev/null +++ b/software/flash/main.nf @@ -0,0 +1,40 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process FLASH { + 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::flash=1.2.11" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/flash:1.2.11--hed695b0_5" + } else { + container "quay.io/biocontainers/flash:1.2.11--hed695b0_5" + } + + input: + tuple val(meta), path(reads) + + output: + tuple val(meta), path("*.merged.*.fastq.gz"), emit: reads + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def merged = "-o ${prefix}.merged" + def input_reads = "${reads[0]} ${reads[1]}" + """ + flash \\ + $options.args \\ + $merged \\ + -z \\ + $input_reads + echo \$(flash --version) > ${software}.version.txt + """ +} diff --git a/software/flash/meta.yml b/software/flash/meta.yml new file mode 100644 index 00000000..6ab6c522 --- /dev/null +++ b/software/flash/meta.yml @@ -0,0 +1,44 @@ +name: flash +description: Perform merging of mate paired-end sequencing reads +keywords: + - sort + - reads merging + - merge mate pairs +tools: + - flash: + description: | + Merge mates from fragments that are shorter than twice the read length + homepage: https://ccb.jhu.edu/software/FLASH/ + documentation: {} + doi: 10.1093/bioinformatics/btr507 + licence: ['GPL v3+'] + +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 2; i.e., paired-end data. + pattern: "*fastq.gz" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - reads: + type: file + description: The merged fastq reads + pattern: "*fastq.gz" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + +authors: + - "@Erkison" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 1b47d547..41f7d4d5 100755 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -178,6 +178,10 @@ fastqc: - software/fastqc/** - tests/software/fastqc/** +flash: + - software/flash/** + - tests/software/flash/** + gatk4_applybqsr: - software/gatk4/applybqsr/** - tests/software/gatk4/applybqsr/** diff --git a/tests/software/flash/main.nf b/tests/software/flash/main.nf new file mode 100644 index 00000000..b22ec8dc --- /dev/null +++ b/tests/software/flash/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { FLASH } from '../../../software/flash/main.nf' addParams( options: [args:'-m 20 -M 100'] ) + +workflow test_flash { + + 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) ] ] + + FLASH ( input ) +} diff --git a/tests/software/flash/test.yml b/tests/software/flash/test.yml new file mode 100644 index 00000000..411f4d69 --- /dev/null +++ b/tests/software/flash/test.yml @@ -0,0 +1,11 @@ +- name: flash test_flash + command: nextflow run tests/software/flash -entry test_flash -c tests/config/nextflow.config + tags: + - flash + files: + - path: output/flash/test.merged.notCombined_2.fastq.gz + md5sum: 96ec044281fe60e0061976d928810314 + - path: output/flash/test.merged.extendedFrags.fastq.gz + md5sum: da20afa705e8ea881e66960bb75607c9 + - path: output/flash/test.merged.notCombined_1.fastq.gz + md5sum: 32451c87f89172c764bec19136592d29