From bedc2972eb30a36a439b8cfda44db27c726d46c4 Mon Sep 17 00:00:00 2001 From: FriederikeHanssen Date: Wed, 17 Feb 2021 17:09:24 +0100 Subject: [PATCH] Add seqkit split2 --- software/seqkit/split2/functions.nf | 59 ++++++++++++++++++++ software/seqkit/split2/main.nf | 85 +++++++++++++++++++++++++++++ software/seqkit/split2/meta.yml | 68 +++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 software/seqkit/split2/functions.nf create mode 100644 software/seqkit/split2/main.nf create mode 100644 software/seqkit/split2/meta.yml diff --git a/software/seqkit/split2/functions.nf b/software/seqkit/split2/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/seqkit/split2/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/seqkit/split2/main.nf b/software/seqkit/split2/main.nf new file mode 100644 index 00000000..b9413537 --- /dev/null +++ b/software/seqkit/split2/main.nf @@ -0,0 +1,85 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +// TODO nf-core: If in doubt look at other nf-core/modules to see how we are doing things! :) +// https://github.com/nf-core/modules/tree/master/software +// You can also ask for help via your pull request or on the #modules channel on the nf-core Slack workspace: +// https://nf-co.re/join + +// TODO nf-core: The key words "MUST", "MUST NOT", "SHOULD", etc. are to be interpreted as described in RFC 2119 (https://tools.ietf.org/html/rfc2119). +// TODO nf-core: A module file SHOULD only define input and output files as command-line parameters. +// All other parameters MUST be provided as a string i.e. "options.args" +// where "params.options" is a Groovy Map that MUST be provided via the addParams section of the including workflow. +// Any parameters that need to be evaluated in the context of a particular sample +// e.g. single-end/paired-end data MUST also be defined and evaluated appropriately. +// TODO nf-core: Software that can be piped together SHOULD be added to separate module files +// unless there is a run-time, storage advantage in implementing in this way +// e.g. bwa mem | samtools view -B -T ref.fasta to output BAM instead of SAM. +// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, "fake files" MAY be used to work around this issue. + +params.options = [:] +def options = initOptions(params.options) + +process SEQKIT_SPLIT2 { + 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::seqkit=0.15.0" : null) + + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/seqkit:0.15.0--0" + } else { + container "quay.io/biocontainers/seqkit:0.15.0--0" + } + + input: + tuple val(meta), path(read1), path(read2) + + // TODO nf-core: Where applicable all sample-specific information e.g. "id", "single_end", "read_group" + // MUST be provided as an input via a Groovy Map called "meta". + // This information may not be required in some instances e.g. indexing reference genome files: + // https://github.com/nf-core/modules/blob/master/software/bwa/index/main.nf + // TODO nf-core: Where applicable please provide/convert compressed files as input/output + // e.g. "*.fastq.gz" and NOT "*.fastq", "*.bam" and NOT "*.sam" etc. + + output: + tuple val(meta), path("*.fq.gz"), emit: reads + path("*.version.txt") , emit: version + + + script: + def software = getSoftwareName(task.process) + + //TODO not sure if this is useful here, as the splits need to be named individually, and this would make the prefix the same and the outputname I am afraid. + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + + if(meta.single_end){ //TODO: I guess since optionally inputs are not possible right now, we need two modules, one for single_end and one for paired_end + """ + seqkit \ + split2 \ + $options.args \ + --threads $task.cpus \ + -1 $read1 \ + -O $prefix + + + echo \$(seqkit --version 2>&1) | sed 's/^.*seqkit //; s/Using.*\$//' > ${software}.version.txt + """ + } else { + """ + seqkit \ + split2 \ + $options.args \ + --threads $task.cpus \ + -1 $read1 \ + -2 $read2 \ + -O $prefix + + echo \$(seqkit --version 2>&1) | sed 's/^.*seqkit //; s/Using.*\$//' > ${software}.version.txt + """ + } +} diff --git a/software/seqkit/split2/meta.yml b/software/seqkit/split2/meta.yml new file mode 100644 index 00000000..002ac970 --- /dev/null +++ b/software/seqkit/split2/meta.yml @@ -0,0 +1,68 @@ +name: seqkit_split2 +## TODO nf-core: Add a description and keywords +description: Split single or paired-end fastq.gz files +keywords: + - split + - fastq +tools: + - seqkit: + ## TODO nf-core: Add a description and other details for the software below + description: | + Cross-platform and ultrafast toolkit for FASTA/Q file manipulation, written by Wei Shen. + homepage: https://github.com/shenwei356/seqkit + documentation: https://bioinf.shenwei.me/seqkit/ + doi: 10.1371/journal.pone.0163962 +## TODO nf-core: If you are using any additional "params" in the main.nf script of the module add them below +params: + - outdir: + type: string + description: | + The pipeline's output directory. By default, the module will + output files into `$params.outdir/` + - publish_dir_mode: + type: string + description: | + Value for the Nextflow `publishDir` mode parameter. + Available: symlink, rellink, link, copy, copyNoFollow, move. + - enable_conda: + type: boolean + description: | + Run the module with Conda using the software specified + via the `conda` directive + - singularity_pull_docker_container: + type: boolean + description: | + Instead of directly downloading Singularity images for use with Singularity, + force the workflow to pull and convert Docker containers instead. +## TODO nf-core: Add a description of all of the variables used as input +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - read1: + type: file + description: First FastQ file + pattern: "*.{fq.gz/fastq.gz}" + - read2: + type: file + description: Second FastQ file + pattern: "*.{fq.gz/fastq.gz}" +## TODO nf-core: Add a description of all of the variables used as output +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - reads: + type: file + description: Split fastq files + pattern: "*.{fq.gz}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@FriederikeHanssen"