Command line interface#
This part of the documentation describes the
snakemake executable. Snakemake
is primarily a command-line tool, so the
snakemake executable is the primary way
to execute, debug, and visualize workflows.
Important environment variables#
Snakemake caches source files for performance and reproducibility.
The location of this cache is determined by the appdirs package.
If you want to change the location on a unix/linux system, you can define an override path via the environment variable
Useful Command Line Arguments#
If called with the number of cores to use, i.e.
$ snakemake --cores 1
Snakemake tries to execute the workflow specified in a file called
Snakefile in the same directory (the Snakefile can be given via the parameter
$ snakemake -n
a dry-run can be performed. This is useful to test if the workflow is defined properly and to estimate the amount of needed computation.
Importantly, Snakemake can automatically determine which parts of the workflow can be run in parallel. By specifying more than one available core, i.e.
$ snakemake --cores 4
one can tell Snakemake to use up to 4 cores and solve a binary knapsack problem to optimize the scheduling of jobs.
If the number is omitted (i.e., only
--cores is given), the number of used cores is determined as the number of available CPU cores in the machine.
Snakemake workflows usually define the number of used threads of certain rules. Sometimes, it makes sense to overwrite the defaults given in the workflow definition.
This can be done by using the
--set-threads argument, e.g.,
$ snakemake --cores 4 --set-threads myrule=2
would overwrite whatever number of threads has been defined for the rule
myrule and use
Similarly, it is possible to overwrite other resource definitions in rules, via
$ snakemake --cores 4 --set-resources myrule:partition="foo"
Both mechanisms can be particularly handy when used in combination with non-local execution.
Non-local execution on cluster or cloud infrastructure is implemented via plugins. The Snakemake plugin catalog lists available plugins and their documentation.
Dealing with very large workflows#
If your workflow has a lot of jobs, Snakemake might need some time to infer the dependencies (the job DAG) and which jobs are actually required to run. The major bottleneck involved is the filesystem, which has to be queried for existence and modification dates of files. To overcome this issue, Snakemake allows to run large workflows in batches. This way, fewer files have to be evaluated at once, and therefore the job DAG can be inferred faster. By running
$ snakemake --cores 4 --batch myrule=1/3
you instruct to only compute the first of three batches of the inputs of the rule
To generate the second batch, run
$ snakemake --cores 4 --batch myrule=2/3
Finally, when running
$ snakemake --cores 4 --batch myrule=3/3
Snakemake will process beyond the rule
myrule, because all of its input files have been generated, and complete the workflow.
Obviously, a good choice of the rule to perform the batching is a rule that has a lot of input files and upstream jobs, for example a central aggregation step within your workflow.
We advice all workflow developers to inform potential users of the best suited batching rule.
Adapting Snakemake to a particular environment can entail many flags and options. Therefore, since Snakemake 4.1, it is possible to specify configuration profiles to be used to obtain default options. Since Snakemake 7.29, two kinds of profiles are supported:
A global profile that is defined in a system-wide or user-specific configuration directory (on Linux, this will be
/etc/xdg/snakemake, you can find the answer for your system via
A workflow specific profile (introduced in Snakemake 7.29) that is defined via a flag (
--workflow-profile) or searched in a default location (
profile/default) in the working directory or next to the Snakefile.
The workflow specific profile is meant to be used to define default options for a particular workflow, like providing constraints for certain custom resources the workflow uses (e.g.
api_calls) or overwriting the threads and resource definitions of individual rules without modifying the workflow code itself.
In contrast, the global profile is meant to be used to define default options for a particular environment, like the default cluster submission command or the default number of jobs to run in parallel.
For example, the command
$ snakemake --profile myprofile
would expect a folder
myprofile in per-user and global configuration directories (on Linux, this will be
/etc/xdg/snakemake, you can find the answer for your system via
Alternatively, an absolute or relative path to the profile folder can be given.
The default profile to use when no
--profile argument is specified can also be set via the environment variable
e.g. by specifying
export SNAKEMAKE_PROFILE=myprofile in your
~/.bashrc or the system wide shell defaults means that the
--profile flag can be omitted.
In order unset the profile defined by this environment variable for individual runs without specifying and alternative profile you can provide the special value
The profile folder is expected to contain a configuration file that file that defines default values for the Snakemake command line arguments.
The file has to be named
X denoting the minimum supported Snakemake major version (e.g.
As fallback, it is also possible to provide a version agnostic
config.yaml that matches any Snakemake version.
For example, the file
executor: slurm jobs: 100
would setup Snakemake to always submit to the SLURM cluster middleware and never use more than 100 parallel jobs in total.
The profile can be used to set a default for each option of the Snakemake command line interface.
For this, option
someoption: in the profile.
The profile folder can additionally contain auxilliary files, e.g., jobscripts, or any kind of wrappers. See https://github.com/snakemake-profiles/doc for examples.
If options accept multiple arguments these must be given as YAML list in the profile.
If options expect structured arguments (like
--set-threads RULE=VALUE, or
--set-resources RULE:RESOURCE=VALUE), those can be given as strings in the expected forms, i.e.
default-resources: mem_mb=200 set-threads: myrule=5 set-resources: myrule:mem=500MB
or as YAML maps, which is easier to read:
default-resources: mem_mb: 200 set-threads: myrule: 5 set-resources: myrule: mem: 500MB
All of these resource specifications can also be made dynamic, by using expressions and certain variables that are available.
For details of the variables you can use, refer to the callable signatures given in the
documentation sections on the specification of threads
and dynamic resources.
config.yaml entries like:
default-resources: mem_mb: max(1.5 * input.size_mb, 100) set-threads: myrule: max(input.size_mb / 5, 2) set-resources: myrule: mem_mb: attempt * 200
Setting resources or threads via the profile is of course rather a job for the workflow profile instead of the global profile (as such settings are likely workflow specific).
Values in profiles can make use of globally available environment variables, e.g. the
For example, the following would set the default prefix for storing local copies of remote storage files to a user specific directory
Any such environment variables are automatically expanded when evaluating the profile.
Under https://github.com/snakemake-profiles/doc, you can find publicly available global profiles (e.g. for cluster systems).
Feel free to contribute your own.
Workflow specific profiles are either not shared at all, or can be distributed along with the workflow itself where it makes sense.
For example, when the workflow has its Snakefile at
workflow/Snakefile, the profile config should be placed at
In Snakemake 7.30 or newer, when the profile starts with
It will be treated as a YTE template and parsed accordingly. This can be handy to e.g. define values inside of the profile that are based on environment variables. For example, admins could use this to define user-specific settings. Another application would be the uniform redefinition of resource requirements for a larger set of rules in a workflow profile (see above). However, it should be noted that templated profiles are harder to keep free of errors and the profile author has to make sure that they always work correctly for the user.
To visualize the workflow, one can use the option
This creates a representation of the DAG in the graphviz dot language which has to be postprocessed by the graphviz tool
E.g. to visualize the DAG that would be executed, you can issue:
$ snakemake --dag | dot | display
For saving this to a file, you can specify the desired format:
$ snakemake --dag | dot -Tpdf > dag.pdf
To visualize the whole DAG regardless of the eventual presence of files, the
forceall option can be used:
$ snakemake --forceall --dag | dot -Tpdf > dag.pdf
Of course the visual appearance can be modified by providing further command line arguments to
Note: The DAG is printed in DOT format straight to the standard output, along with other
dot can build a visual representation of your DAG.