# Snakemake

> Reproducible, scalable data analysis workflows in Python

- Category: Science & Biomedical AI / Scientific Workflow Orchestration
- Language: Python
- Repository: https://github.com/snakemake/snakemake
- Website: https://snakemake.github.io
- Canonical page: https://ai-tldr.dev/tools/snakemake/

## In short

Snakemake is a workflow management system for creating reproducible and scalable data analyses. It sits in the Scientific Workflow Orchestration category of the Science & Biomedical AI tools and is open-source, written in Python. To get started: install with Conda or Mamba.

## Overview

Snakemake is a workflow management system for creating reproducible and scalable data analyses. Workflows are described in a human-readable, Python-based language, where each step is a rule that defines how to produce output files from input files using a shell command or a script.

Snakemake works out the dependencies between steps automatically from the input and output files each rule declares, so it only runs the parts of a pipeline that need to be rebuilt. The same workflow definition can run on a single machine, a multicore server, a cluster, a grid, or the cloud without being modified.

Workflows can describe the software they require, and Snakemake will deploy it automatically to the execution environment through the Conda package manager or containers. This focus on portability and provenance makes it widely used in bioinformatics and other data-heavy scientific fields.

## What it does

- Rules written in a human-readable, Python-based language that generate output files from input files
- Dependencies between steps are determined automatically from each rule's declared input and output
- The same workflow scales from a single core to multicore, clusters, grids, and cloud without changes
- Required software can be deployed automatically through Conda environments or containers
- Scripting steps in Python, R, Julia, Rust, or Bash, plus reusable tool wrappers and modules
- Automatic, interactive reports capturing results, data provenance, and workflow transparency

## Getting started

Install Snakemake with Conda or pip, then describe your pipeline as rules and run it.

1. Install with Conda or Mamba

   Create a dedicated environment for Snakemake from the conda-forge and bioconda channels.

```bash
conda create -c conda-forge -c bioconda -c nodefaults -n snakemake snakemake
conda activate snakemake
```

2. Or install with pip

   Snakemake is also available on PyPI if you prefer to install it into an existing Python environment.

```bash
pip install snakemake
```

3. Write a rule in a Snakefile

   Each rule declares its input and output files and the command that turns one into the other. Wildcards in curly braces let a single rule apply to many files, and Snakemake connects rules automatically through their files.

```python
rule select_by_country:
  input: "data/worldcitiespop.csv"
  output: "by-country/{country}.csv"
  shell: "xsv search -s Country '{wildcards.country}' {input} > {output}"
```

4. Verify the installation

   Check that Snakemake is available in the activated environment before running your workflow.

```bash
snakemake --help
```

## When to use it

- Build reproducible bioinformatics pipelines that only rerun the steps affected by changed inputs
- Run the same data-analysis workflow on a laptop, a cluster, or the cloud without rewriting it
- Package required tools with a workflow using Conda environments or containers for portability
- Generate interactive reports that document results and data provenance for scientific work
