utility functions for snakemake
Project description
Snakemake Utility functions for easier working with snakemake
When debugging a script that uses snakemake to define its inputs, it is often difficult to manually set some example inputs for testing. This utility allows to directly obtain a Snakemake object from the pipeline by specifying the desired rule and wildcards.
Loading snakemake object without actually running snakemake
For obtaining a Snakemake object in python, simply paste the following preamble in your script and adjust snakefile_path, rule_name and default_wildcards.
try:
snakemake
except NameError:
import os
from snakemk_util import load_rule_args, pretty_print_snakemake
snakefile_path = os.getcwd() + "/Snakefile"
snakemake = load_rule_args(
snakefile = snakefile_path,
rule_name = 'create_prediction_target',
default_wildcards={
'ds_dir': 'all_data'
}
)
print(pretty_print_snakemake(snakemake))
Output:
Snakemake({
"threads": 64,
"resources": {
"_cores": 64,
"_nodes": 1,
"tmpdir": "<function DefaultResources.__init__.<locals>.fallback.<locals>.callable at 0x154022f799d0>",
"ntasks": 1,
"mem_mb": 250000
},
"input": {
"0": "some_input.csv"
"config": "some_config.yaml",
},
"params": {
"nb_script": "create_prediction_target.py"
},
"output": {
[...]
},
"wildcards": {
"ds_dir": "all_data"
},
"log": [],
"config": {
[...]
},
"rule": "create_prediction_target"
})
- The preamble has no effect during
snakemakeruns, so it can be kept in the script permanently. pretty_print_snakemakeknows about theNamedListthat snakemake uses and prints all non-named parameters by their index
Here the corresponding snippet for R:
if (! exists("snakemake")) {
rule = "create_prediction_target"
python = "/opt/anaconda/envs/snakemake/bin/python"
wildcards = paste(
# 'comparison=all',
sep=','
)
cmd=c(
"-m snakemk_util.main",
"--rule", rule,
"--snakefile", normalizePath(snakefile),
"--root", dirname(normalizePath(snakefile)),
"--wildcards", paste0('"', wildcards, '"'),
"--gen-preamble RScript",
"--create_dirs"
)
eval(parse(text=system2(python, cmd, stdout=TRUE, stderr="")))
}
Inspecting the rule parameters on the command line
snakemk_util also provides a command-line interface which allows to display the snakemake objects for some rule and wildcard as well as generating script preambles for different languages:
# snakemk_util --help
usage: snakemk_util [-h] --rule RULE_NAME [--gen-preamble FLAVOR] [--snakefile SNAKEFILE] [--root_dir ROOT_DIR] [--wildcards WILDCARDS] [--create_dirs]
Utility to sow Snakemake rule contents and creating script preambles without actually running Snakemake.
optional arguments:
-h, --help show this help message and exit
--rule RULE_NAME Name of the rule that should be formatted
--gen-preamble FLAVOR
Script language for which the preamble should be generated Examples: 'BashScript', 'JuliaScript', 'PythonScript', 'RMarkdown', 'RScript', 'RustScript', 'PythonJupyterNotebook', 'RJupyterNotebook'
--snakefile SNAKEFILE
path to the Snakefile
--root_dir ROOT_DIR Root directory from where you would run the `snakemake` command. By default, this is the current working directory.
--wildcards WILDCARDS
Comma-separated key-value list of wildcards which should be used to format the rule output. Example: 'wildcard0=x,wildcard1=y
--create_dirs Create the output directories for the rule
Installation
pip install snakemk_util
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snakemk_util-2.0.2.tar.gz.
File metadata
- Download URL: snakemk_util-2.0.2.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f38dda700b212ab0af69fa5aabd8fdefa7f1a9f6ca62124d2f63242e8cb8d777
|
|
| MD5 |
f09ebf71b99129fc58390c31d58b02d0
|
|
| BLAKE2b-256 |
6932d2b29862694c0a973986506e7f4715c0ae0837322a9c3919cff0d1fd53aa
|
Provenance
The following attestation bundles were made for snakemk_util-2.0.2.tar.gz:
Publisher:
publish.yml on Hoeze/snakemk_util
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snakemk_util-2.0.2.tar.gz -
Subject digest:
f38dda700b212ab0af69fa5aabd8fdefa7f1a9f6ca62124d2f63242e8cb8d777 - Sigstore transparency entry: 1475470536
- Sigstore integration time:
-
Permalink:
Hoeze/snakemk_util@0f4a72d90baa20cef4fbaf0b95ce69974ea19932 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Hoeze
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0f4a72d90baa20cef4fbaf0b95ce69974ea19932 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file snakemk_util-2.0.2-py3-none-any.whl.
File metadata
- Download URL: snakemk_util-2.0.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4d3138cce9899654d4cebb1624553d4764d19d84e4ef5363dd394fa50cacd76
|
|
| MD5 |
259feed06c4307c412f2563b3c9ee80d
|
|
| BLAKE2b-256 |
0df4bba03fe417bd4bc9021d597d3d3ef47590512a79593a9d5196315e531597
|
Provenance
The following attestation bundles were made for snakemk_util-2.0.2-py3-none-any.whl:
Publisher:
publish.yml on Hoeze/snakemk_util
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snakemk_util-2.0.2-py3-none-any.whl -
Subject digest:
d4d3138cce9899654d4cebb1624553d4764d19d84e4ef5363dd394fa50cacd76 - Sigstore transparency entry: 1475470615
- Sigstore integration time:
-
Permalink:
Hoeze/snakemk_util@0f4a72d90baa20cef4fbaf0b95ce69974ea19932 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Hoeze
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0f4a72d90baa20cef4fbaf0b95ce69974ea19932 -
Trigger Event:
workflow_dispatch
-
Statement type: