Snakemake Workflow Management System

9.19.0 · active · verified Thu Apr 16

Snakemake is a Python-based workflow management system designed to create reproducible and scalable data analyses. It enables writing workflows in a Python-like DSL called Snakefile, allowing for automatic parallelization, dependency tracking, and execution on various platforms. The current version is 9.19.0, with frequent patch releases and major feature updates typically every few months.

Common errors

Warnings

Install

Imports

Quickstart

Create a `Snakefile` (the workflow definition) and then execute it using the `snakemake` command-line tool. The example generates a simple file processing workflow and shows how the workflow rules are defined. To run the workflow, execute `snakemake -c 1` in your terminal in the same directory as the Snakefile.

import os

# Create a dummy Snakefile for demonstration
snakefile_content = """
rule all:
    input: "results/final.txt"

rule prepare_data:
    output: "data/input.txt"
    shell: "mkdir -p data && echo 'Hello, Snakemake!' > {output}"

rule process_data:
    input: "data/input.txt"
    output: "results/processed.txt"
    shell: "mkdir -p results && cat {input} | tr 'A-Z' 'a-z' > {output}"

rule analyze_results:
    input: "results/processed.txt"
    output: "results/final.txt"
    shell: "echo 'Analysis complete for: ' $(cat {input}) > {output}"
"""

with open("Snakefile", "w") as f:
    f.write(snakefile_content)

print("Snakefile created. Running workflow...")

# To run this, you would typically use the command line:
# snakemake -c 1
# Or for programmatic execution (more complex, but possible):
# from snakemake.api import SnakemakeApi
# snakemake_runner = SnakemakeApi(
#    snakefile='Snakefile',
#    target_files=['results/final.txt'],
#    cores=1
# )
# success = snakemake_runner.execute()
# print(f"Workflow execution {'succeeded' if success else 'failed'}")

# Clean up example files (optional)
# import shutil
# if os.path.exists("data"): shutil.rmtree("data")
# if os.path.exists("results"): shutil.rmtree("results")
# if os.path.exists("Snakefile"): os.remove("Snakefile")

view raw JSON →