diff --git a/modules/nf-core/snakemake/main.nf b/modules/nf-core/snakemake/main.nf new file mode 100644 index 00000000000..e3c42222eaf --- /dev/null +++ b/modules/nf-core/snakemake/main.nf @@ -0,0 +1,56 @@ +process SNAKEMAKE { + tag "$meta.id" + label 'process_low' + + // You will have to add all modules to this Conda definition and + // replace the container definition for one that suits your needs + conda "bioconda::snakemake=7.31.0" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/snakemake:7.31.0--hdfd78af_1' : + 'biocontainers/snakemake:7.31.0--hdfd78af_1' }" + + input: + tuple val(meta), path(inputs) + tuple val(meta2), path(snakefile) + + output: + tuple val(meta), path("**[!.snakemake]"), optional: true , emit: outputs + tuple val(meta), path(".snakemake", type: 'dir', hidden: true), emit: snakemake_dir + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def cores = task.cpus ? "--cores ${task.cpus}" : "--cores all" + """ + snakemake \\ + $args \\ + $cores \\ + --snakefile $snakefile + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + snakemake: \$(snakemake --version) + END_VERSIONS + """ + + stub: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def cores = task.cpus ? "--cores ${task.cpus}" : "--cores all" + """ + snakemake \\ + $args \\ + --snakefile $snakefile \\ + $cores \\ + --dry-run + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + snakemake: \$(snakemake --version) + END_VERSIONS + """ +} diff --git a/modules/nf-core/snakemake/meta.yml b/modules/nf-core/snakemake/meta.yml new file mode 100644 index 00000000000..03da2bfaa2f --- /dev/null +++ b/modules/nf-core/snakemake/meta.yml @@ -0,0 +1,60 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/yaml-schema.json +name: "snakemake" +description: The Snakemake workflow management system is a tool to create reproducible and scalable data analyses. This module runs a simple Snakemake pipeline based on input snakefile. Expect many limitations." +keywords: + - snakemake + - workflow + - workflow_mode +tools: + - "snakemake": + description: "A popular workflow management system aiming at full in-silico reproducibility." + homepage: "https://snakemake.readthedocs.io/en/stable/" + documentation: "https://snakemake.readthedocs.io/en/stable/" + tool_dev_url: "https://github.com/snakemake/snakemake" + doi: "10.1093/bioinformatics/bty350" + licence: "['MIT']" + +input: + # Only when we have meta + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: Any input file required by Snakemake + pattern: "*" + - meta2: + type: map + description: | + Meta information for Snakefile + e.g. [ id: 'snakefile' ] + - snakefile: + type: file + description: | + Snakefile to use with Snakemake. This is required for proper execution of Snakemake. + +output: + #Only when we have meta + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - outputs: + type: file + description: | + Any file generated by Snakemake, excluding the inputs, hidden files and Snakemake log directory (.snakemake). This is set to optional because Snakemake can be used to run arbitrary commands, and we cannot know what files will be generated. + - snakemake_dir: + type: directory + description: | + Snakemake log directory (.snakemake). Can be used to capture logs of Snakemake execution. + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@adamrtalbot" diff --git a/tests/config/nftest_modules.yml b/tests/config/nftest_modules.yml index 33e3e2046d9..ccd24bcdb45 100644 --- a/tests/config/nftest_modules.yml +++ b/tests/config/nftest_modules.yml @@ -1,3 +1,7 @@ fastqc: - modules/nf-core/fastqc/** - tests/modules/nf-core/fastqc/** + +snakemake: + - modules/nf-core/snakemake/** + - tests/modules/nf-core/snakemake/** diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 7b285ab12e0..3a12336e73e 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -3420,6 +3420,10 @@ smoove/call: - modules/nf-core/smoove/call/** - tests/modules/nf-core/smoove/call/** +snakemake: + - modules/nf-core/snakemake/** + - tests/modules/nf-core/snakemake/** + snapaligner/align: - modules/nf-core/snapaligner/align/** - tests/modules/nf-core/snapaligner/align/** diff --git a/tests/modules/nf-core/snakemake/Snakefile b/tests/modules/nf-core/snakemake/Snakefile new file mode 100644 index 00000000000..bd8c98ec850 --- /dev/null +++ b/tests/modules/nf-core/snakemake/Snakefile @@ -0,0 +1,6 @@ +rule all: + input: "hello.txt" + +rule hello_world: + output: "hello.txt" + shell: "echo Hello World > hello.txt" diff --git a/tests/modules/nf-core/snakemake/main.nf b/tests/modules/nf-core/snakemake/main.nf new file mode 100644 index 00000000000..1b65740d8d9 --- /dev/null +++ b/tests/modules/nf-core/snakemake/main.nf @@ -0,0 +1,36 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { SNAKEMAKE } from '../../../../modules/nf-core/snakemake/main.nf' + +workflow test_snakemake { + + input = [ + [ id: 'input'], + [] + ] + +// This generates a Snakefile for use with Snakemake. +// In real use, you should probably access this via a +// a file stored within the repository. + Channel.of(''' +rule all: + input: "hello.txt" + +rule hello_world: + output: "hello.txt" + shell: "echo Hello World > hello.txt" + +''' + ) + .collectFile(name: 'Snakefile') + .map { file -> + [ + [id: 'Snakefile'], + file + ]} + .set{ snakefile } + + SNAKEMAKE ( input, snakefile) +} diff --git a/tests/modules/nf-core/snakemake/main.nf.test b/tests/modules/nf-core/snakemake/main.nf.test new file mode 100644 index 00000000000..9c5f07c9fc2 --- /dev/null +++ b/tests/modules/nf-core/snakemake/main.nf.test @@ -0,0 +1,49 @@ +nextflow_process { + + name "Test Process SNAKEMAKE" + script "modules/nf-core/snakemake/main.nf" + process "SNAKEMAKE" + tag "snakemake" + + test("Should run without failures") { + + when { + process { + """ + // Input file + input[0] = [ + [ id: 'input'], + [] + ] +// Snakefile + Channel.of(''' +rule all: + input: "hello.txt" + +rule hello_world: + output: "hello.txt" + shell: "echo Hello World > hello.txt" + +''' + ) + .collectFile(name: 'Snakefile') + .map { file -> + [ + [id: 'Snakefile'], + file + ]} + .set{ snakefile } + + input[1] = snakefile + """ + } + } + + then { + assert process.success + assert snapshot(process.out.ouputs).match() + } + + } + +} diff --git a/tests/modules/nf-core/snakemake/main.nf.test.snap b/tests/modules/nf-core/snakemake/main.nf.test.snap new file mode 100644 index 00000000000..66862e7054a --- /dev/null +++ b/tests/modules/nf-core/snakemake/main.nf.test.snap @@ -0,0 +1,6 @@ +{ + "Should run without failures": { + "content": null, + "timestamp": "2023-07-31T09:50:07+0000" + } +} \ No newline at end of file diff --git a/tests/modules/nf-core/snakemake/nextflow.config b/tests/modules/nf-core/snakemake/nextflow.config new file mode 100644 index 00000000000..8730f1c4b93 --- /dev/null +++ b/tests/modules/nf-core/snakemake/nextflow.config @@ -0,0 +1,5 @@ +process { + + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + +} diff --git a/tests/modules/nf-core/snakemake/test.yml b/tests/modules/nf-core/snakemake/test.yml new file mode 100644 index 00000000000..fc6e9427fbb --- /dev/null +++ b/tests/modules/nf-core/snakemake/test.yml @@ -0,0 +1,17 @@ +- name: snakemake test_snakemake + command: nextflow run ./tests/modules/nf-core/snakemake -entry test_snakemake -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/snakemake/nextflow.config + tags: + - snakemake + files: + - path: output/snakemake/.snakemake/ + - path: output/snakemake/hello.txt + md5sum: e59ff97941044f85df5297e1c302d260 + - path: output/snakemake/versions.yml + +- name: snakemake test_snakemake_stub + command: nextflow run ./tests/modules/nf-core/snakemake -entry test_snakemake -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/snakemake/nextflow.config -stub + tags: + - snakemake + files: + - path: output/snakemake/.snakemake/ + - path: output/snakemake/versions.yml