Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snakemake module #3682

Merged
merged 11 commits into from
Aug 3, 2023
56 changes: 56 additions & 0 deletions modules/nf-core/snakemake/main.nf
Original file line number Diff line number Diff line change
@@ -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
"""
}
60 changes: 60 additions & 0 deletions modules/nf-core/snakemake/meta.yml
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- bam:
- inputs:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamrtalbot you didn't fix it before you merged!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! I thought I had. Hotfix coming in...

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"
4 changes: 4 additions & 0 deletions tests/config/nftest_modules.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
fastqc:
- modules/nf-core/fastqc/**
- tests/modules/nf-core/fastqc/**

snakemake:
- modules/nf-core/snakemake/**
- tests/modules/nf-core/snakemake/**
4 changes: 4 additions & 0 deletions tests/config/pytest_modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**
Expand Down
6 changes: 6 additions & 0 deletions tests/modules/nf-core/snakemake/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rule all:
input: "hello.txt"

rule hello_world:
output: "hello.txt"
shell: "echo Hello World > hello.txt"
36 changes: 36 additions & 0 deletions tests/modules/nf-core/snakemake/main.nf
Original file line number Diff line number Diff line change
@@ -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)
}
49 changes: 49 additions & 0 deletions tests/modules/nf-core/snakemake/main.nf.test
Original file line number Diff line number Diff line change
@@ -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()
}

}

}
6 changes: 6 additions & 0 deletions tests/modules/nf-core/snakemake/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Should run without failures": {
"content": null,
"timestamp": "2023-07-31T09:50:07+0000"
}
}
5 changes: 5 additions & 0 deletions tests/modules/nf-core/snakemake/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {

publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

}
17 changes: 17 additions & 0 deletions tests/modules/nf-core/snakemake/test.yml
Original file line number Diff line number Diff line change
@@ -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
Loading