Closed iromeo closed 1 month ago
Also lookup
, evaluate
, branch
, collect
, exists
See snakemake/ioutils.py
: registered with other via:
def register_in_globals(_globals):
_globals.update(
{
"lookup": lookup,
"evaluate": evaluate,
"branch": branch,
"collect": collect,
"exists": exists,
}
)
import pandas as pd
samples = pd.read_csv("samples.tsv", sep="\t")
configfile: "config.yaml"
assert lookup(dpath="does/not/exist", within=config, default=None) is None
assert lookup(dpath="does/not/exist", within=config, default=5) == 5
rule all:
input:
"results/switch~someswitch.column~sample.txt",
rule a:
output:
"a/{sample}.txt",
shell:
"echo a > {output}"
rule b:
input:
branch(evaluate("{sample} == '100'"), then="a/{sample}.txt"),
output:
"b/{sample}.txt",
shell:
"echo b > {output}"
rule c:
input:
branch(
evaluate("{sample} == '1'"),
then="a/{sample}.txt",
otherwise="b/{sample}.txt",
),
output:
"c/{sample}.txt",
shell:
"cat {input} > {output}"
rule d:
output:
"test.txt",
shell:
"echo d > {output}"
rule e:
input:
collect("c/{item.sample}.txt", item=lookup(query="{col} <= 2", within=samples)),
branch(lookup(dpath="switches/{switch}", within=config), then="test.txt"),
output:
"results/switch~{switch}.column~{col}.txt",
shell:
"cat {input} > {output}"
exists
added in 8.9.0 - https://github.com/snakemake/snakemake/commit/ee9639385cb2c9cec425800088faee4e4bf77c9a
works in 8.20.6