From 2763c5c42eb63a90c43592bc7354a8cbf2f5702a Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 8 Sep 2021 15:56:31 +0000 Subject: [PATCH 1/7] initial commit for draft [ci skip] --- modules/snpdists/functions.nf | 68 ++++++++++++++++++++++++++++ modules/snpdists/main.nf | 79 +++++++++++++++++++++++++++++++++ modules/snpdists/meta.yml | 47 ++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/snpdists/main.nf | 13 ++++++ tests/modules/snpdists/test.yml | 9 ++++ 6 files changed, 220 insertions(+) create mode 100644 modules/snpdists/functions.nf create mode 100644 modules/snpdists/main.nf create mode 100644 modules/snpdists/meta.yml create mode 100644 tests/modules/snpdists/main.nf create mode 100644 tests/modules/snpdists/test.yml diff --git a/modules/snpdists/functions.nf b/modules/snpdists/functions.nf new file mode 100644 index 00000000000..da9da093d3f --- /dev/null +++ b/modules/snpdists/functions.nf @@ -0,0 +1,68 @@ +// +// 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_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) { + if (!args.filename.endsWith('.version.txt')) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + 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/snpdists/main.nf b/modules/snpdists/main.nf new file mode 100644 index 00000000000..8285b507a3c --- /dev/null +++ b/modules/snpdists/main.nf @@ -0,0 +1,79 @@ +// 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: 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. it's ok to have a single module for bwa to output BAM instead of SAM: +// bwa mem | samtools view -B -T ref.fasta +// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, using an empty +// list (`[]`) instead of a file can be used to work around this issue. + +params.options = [:] +options = initOptions(params.options) + +process SNPDISTS { + 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']) } + + // 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 ? "bioconda::snp-dists=0.8.2" : 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: + // 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. + tuple val(meta), path(bam) + + output: + // TODO nf-core: Named file extensions MUST be emitted for ALL output channels + tuple val(meta), path("*.bam"), emit: bam + // TODO nf-core: List additional required output channels/values here + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + // TODO nf-core: Where possible, a command MUST be provided to obtain the version number of the software e.g. 1.10 + // If the software is unable to output a version number on the command-line then it can be manually specified + // e.g. https://github.com/nf-core/modules/blob/master/software/homer/annotatepeaks/main.nf + // TODO nf-core: It MUST be possible to pass additional parameters to the tool as a command-line string via the "$options.args" variable + // TODO nf-core: If the tool supports multi-threading then you MUST provide the appropriate parameter + // using the Nextflow "task" variable e.g. "--threads $task.cpus" + // TODO nf-core: Please replace the example samtools command below with your module's command + // TODO nf-core: Please indent the command appropriately (4 spaces!!) to help with readability ;) + """ + samtools \\ + sort \\ + $options.args \\ + -@ $task.cpus \\ + -o ${prefix}.bam \\ + -T $prefix \\ + $bam + + echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' > ${software}.version.txt + """ +} diff --git a/modules/snpdists/meta.yml b/modules/snpdists/meta.yml new file mode 100644 index 00000000000..da000fa9b49 --- /dev/null +++ b/modules/snpdists/meta.yml @@ -0,0 +1,47 @@ +name: snpdists +## TODO nf-core: Add a description of the module and list keywords +description: write your description here +keywords: + - sort +tools: + - snpdists: + ## TODO nf-core: Add a description and other details for the software below + description: Convert a FASTA alignment to SNP distance matrix + homepage: None + documentation: None + tool_dev_url: None + doi: "" + licence: ['GPL v3'] + +## 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 ] + ## TODO nf-core: Delete / customise this example input + - bam: + type: file + description: BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +## 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 ] + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + ## TODO nf-core: Delete / customise this example output + - bam: + type: file + description: Sorted BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +authors: + - "@abhi18av" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 0c43bd88b6c..69656efb5d6 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -795,6 +795,10 @@ shovill: - modules/shovill/** - tests/modules/shovill/** +snpdists: + - modules/snpdists/** + - tests/modules/snpdists/** + snpeff: - modules/snpeff/** - tests/modules/snpeff/** diff --git a/tests/modules/snpdists/main.nf b/tests/modules/snpdists/main.nf new file mode 100644 index 00000000000..67098965946 --- /dev/null +++ b/tests/modules/snpdists/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { SNPDISTS } from '../../../modules/snpdists/main.nf' addParams( options: [:] ) + +workflow test_snpdists { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) ] + + SNPDISTS ( input ) +} diff --git a/tests/modules/snpdists/test.yml b/tests/modules/snpdists/test.yml new file mode 100644 index 00000000000..c63b33bb4b7 --- /dev/null +++ b/tests/modules/snpdists/test.yml @@ -0,0 +1,9 @@ +## TODO nf-core: Please run the following command to build this file: +# nf-core modules create-test-yml snpdists +- name: snpdists + command: nextflow run ./tests/modules/snpdists -entry test_snpdists -c tests/config/nextflow.config + tags: + - snpdists + files: + - path: output/snpdists/test.bam + md5sum: e667c7caad0bc4b7ac383fd023c654fc From 0d1f97e694e578f58c03636d0aba745715753c6e Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 13 Sep 2021 20:55:29 +0200 Subject: [PATCH 2/7] baseline code [ci skip] --- modules/snpdists/main.nf | 53 ++++------------------------------ tests/modules/snpdists/main.nf | 2 +- 2 files changed, 6 insertions(+), 49 deletions(-) diff --git a/modules/snpdists/main.nf b/modules/snpdists/main.nf index 8285b507a3c..e150587600c 100644 --- a/modules/snpdists/main.nf +++ b/modules/snpdists/main.nf @@ -1,23 +1,6 @@ // 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: 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. it's ok to have a single module for bwa to output BAM instead of SAM: -// bwa mem | samtools view -B -T ref.fasta -// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, using an empty -// list (`[]`) instead of a file can be used to work around this issue. - params.options = [:] options = initOptions(params.options) @@ -28,52 +11,26 @@ process SNPDISTS { mode: params.publish_dir_mode, saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) } - // 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 ? "bioconda::snp-dists=0.8.2" : null) if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { - container "https://depot.galaxyproject.org/singularity/YOUR-TOOL-HERE" + container "https://depot.galaxyproject.org/singularity/snp-dists:0.8.2--h5bf99c6_0" } else { - container "quay.io/biocontainers/YOUR-TOOL-HERE" + container "quay.io/biocontainers/snp-dists:0.8.2--h5bf99c6_0" } input: - // 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. - tuple val(meta), path(bam) + tuple val(meta), path(alignment) output: - // TODO nf-core: Named file extensions MUST be emitted for ALL output channels tuple val(meta), path("*.bam"), emit: bam - // TODO nf-core: List additional required output channels/values here path "*.version.txt" , emit: version script: def software = getSoftwareName(task.process) def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" - // TODO nf-core: Where possible, a command MUST be provided to obtain the version number of the software e.g. 1.10 - // If the software is unable to output a version number on the command-line then it can be manually specified - // e.g. https://github.com/nf-core/modules/blob/master/software/homer/annotatepeaks/main.nf - // TODO nf-core: It MUST be possible to pass additional parameters to the tool as a command-line string via the "$options.args" variable - // TODO nf-core: If the tool supports multi-threading then you MUST provide the appropriate parameter - // using the Nextflow "task" variable e.g. "--threads $task.cpus" - // TODO nf-core: Please replace the example samtools command below with your module's command - // TODO nf-core: Please indent the command appropriately (4 spaces!!) to help with readability ;) """ - samtools \\ - sort \\ - $options.args \\ - -@ $task.cpus \\ - -o ${prefix}.bam \\ - -T $prefix \\ - $bam + snp-dists ${alignment} > ${prefix}.tsv - echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' > ${software}.version.txt + echo \$(snp-dists -v 2>&1) | sed 's/snp-dists //;' > ${software}.version.txt """ } diff --git a/tests/modules/snpdists/main.nf b/tests/modules/snpdists/main.nf index 67098965946..8a29effa617 100644 --- a/tests/modules/snpdists/main.nf +++ b/tests/modules/snpdists/main.nf @@ -7,7 +7,7 @@ include { SNPDISTS } from '../../../modules/snpdists/main.nf' addParams( options workflow test_snpdists { input = [ [ id:'test', single_end:false ], // meta map - file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) ] + file(params.test_data['sarscov2']['genome']['informative_sites_fas'], checkIfExists: true) ] SNPDISTS ( input ) } From d694767d6f791e2e65f9a46a26d0d3d570d5e54f Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 13 Sep 2021 18:58:32 +0000 Subject: [PATCH 3/7] update the test [ci skip] --- modules/snpdists/main.nf | 2 +- tests/modules/snpdists/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/snpdists/main.nf b/modules/snpdists/main.nf index e150587600c..e06efe6c777 100644 --- a/modules/snpdists/main.nf +++ b/modules/snpdists/main.nf @@ -22,7 +22,7 @@ process SNPDISTS { tuple val(meta), path(alignment) output: - tuple val(meta), path("*.bam"), emit: bam + tuple val(meta), path("*.tsv"), emit: tsv path "*.version.txt" , emit: version script: diff --git a/tests/modules/snpdists/test.yml b/tests/modules/snpdists/test.yml index c63b33bb4b7..9904c92bbbe 100644 --- a/tests/modules/snpdists/test.yml +++ b/tests/modules/snpdists/test.yml @@ -5,5 +5,5 @@ tags: - snpdists files: - - path: output/snpdists/test.bam - md5sum: e667c7caad0bc4b7ac383fd023c654fc + - path: output/snpdists/test.tsv + md5sum: 0018e5ec43990eb16abe2411fff4e47e From 21706067a974132b6729aa721739c84e92c9447e Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 13 Sep 2021 21:04:10 +0200 Subject: [PATCH 4/7] finalize the description and all tests passing --- modules/snpdists/meta.yml | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/modules/snpdists/meta.yml b/modules/snpdists/meta.yml index da000fa9b49..590d034a814 100644 --- a/modules/snpdists/meta.yml +++ b/modules/snpdists/meta.yml @@ -1,47 +1,41 @@ name: snpdists -## TODO nf-core: Add a description of the module and list keywords -description: write your description here +description: Pairwise SNP distance matrix from a FASTA sequence alignment keywords: - - sort + - snp-dists + - distance-matrix tools: - snpdists: - ## TODO nf-core: Add a description and other details for the software below description: Convert a FASTA alignment to SNP distance matrix - homepage: None - documentation: None - tool_dev_url: None + homepage: https://github.com/tseemann/snp-dists + documentation: https://github.com/tseemann/snp-dists + tool_dev_url: https://github.com/tseemann/snp-dists doi: "" licence: ['GPL v3'] -## 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 ] - ## TODO nf-core: Delete / customise this example input - - bam: + - alignment: type: file - description: BAM/CRAM/SAM file - pattern: "*.{bam,cram,sam}" + description: The input FASTA sequence alignment file + pattern: "*.{fasta,fasta.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 ] + - tsv: + type: file + description: The output TSV file containing SNP distance matrix + pattern: "*.tsv" - version: type: file description: File containing software version pattern: "*.{version.txt}" - ## TODO nf-core: Delete / customise this example output - - bam: - type: file - description: Sorted BAM/CRAM/SAM file - pattern: "*.{bam,cram,sam}" - authors: - "@abhi18av" From 609efe516d5060ef51abbeba9e785f9ad4c1fae6 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 13 Sep 2021 22:02:33 +0200 Subject: [PATCH 5/7] accomodate optional args [ci skip] --- modules/snpdists/main.nf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/snpdists/main.nf b/modules/snpdists/main.nf index e06efe6c777..773e148599d 100644 --- a/modules/snpdists/main.nf +++ b/modules/snpdists/main.nf @@ -29,7 +29,9 @@ process SNPDISTS { def software = getSoftwareName(task.process) def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" """ - snp-dists ${alignment} > ${prefix}.tsv + snp-dists \\ + $options.args \\ + ${alignment} > ${prefix}.tsv echo \$(snp-dists -v 2>&1) | sed 's/snp-dists //;' > ${software}.version.txt """ From ac28108107fba07809c8c0257cbc6b0bc3826e6b Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 15 Sep 2021 17:02:43 +0200 Subject: [PATCH 6/7] fix the leftover todo statement --- tests/modules/snpdists/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/modules/snpdists/test.yml b/tests/modules/snpdists/test.yml index 9904c92bbbe..d140ce6e235 100644 --- a/tests/modules/snpdists/test.yml +++ b/tests/modules/snpdists/test.yml @@ -1,5 +1,3 @@ -## TODO nf-core: Please run the following command to build this file: -# nf-core modules create-test-yml snpdists - name: snpdists command: nextflow run ./tests/modules/snpdists -entry test_snpdists -c tests/config/nextflow.config tags: From bb90d267ec71411b03b2c2cac1a1a1f9aa0517ed Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 15 Sep 2021 16:32:10 +0100 Subject: [PATCH 7/7] Update modules/snpdists/main.nf --- modules/snpdists/main.nf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/snpdists/main.nf b/modules/snpdists/main.nf index 773e148599d..c103bb338a5 100644 --- a/modules/snpdists/main.nf +++ b/modules/snpdists/main.nf @@ -31,7 +31,7 @@ process SNPDISTS { """ snp-dists \\ $options.args \\ - ${alignment} > ${prefix}.tsv + $alignment > ${prefix}.tsv echo \$(snp-dists -v 2>&1) | sed 's/snp-dists //;' > ${software}.version.txt """