From 1d4909ef838ac79f8e7be9f29d76b969d358ef1b Mon Sep 17 00:00:00 2001 From: Ethan Holleman Date: Wed, 15 Jun 2022 05:59:57 -0700 Subject: [PATCH] fix: small changes to make docs checkpoint example functional (#1714) * change export_sequences -> somestep * fifix output file to match rule all * write txt files to 'my_directory' --- docs/snakefiles/rules.rst | 47 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/docs/snakefiles/rules.rst b/docs/snakefiles/rules.rst index 62de60c28..634e63654 100644 --- a/docs/snakefiles/rules.rst +++ b/docs/snakefiles/rules.rst @@ -1961,35 +1961,38 @@ Consider the following example where an arbitrary number of files is generated b .. code-block:: python # a target rule to define the desired final output - rule all: - input: - "aggregated.txt" + rule all: + input: + "aggregated.txt" - # the checkpoint that shall trigger re-evaluation of the DAG - # an number of file is created in a defined directory - checkpoint somestep: - output: - directory("my_directory/") - shell: - "mkdir my_directory/;" - "for i in 1 2 3; do touch $i.txt; done" + # the checkpoint that shall trigger re-evaluation of the DAG + # an number of file is created in a defined directory + checkpoint somestep: + output: + directory("my_directory/") + shell:''' + mkdir my_directory/ + cd my_directory + for i in 1 2 3; do touch $i.txt; done + ''' - # input function for rule aggregate, return paths to all files produced by the checkpoint 'somestep' - def aggregate_input(wildcards): - checkpoint_output = checkpoints.export_sequences.get(**wildcards).output[0] - return expand("my_directory/{i}.txt", + + # input function for rule aggregate, return paths to all files produced by the checkpoint 'somestep' + def aggregate_input(wildcards): + checkpoint_output = checkpoints.somestep.get(**wildcards).output[0] + return expand("my_directory/{i}.txt", i=glob_wildcards(os.path.join(checkpoint_output, "{i}.txt")).i) - rule aggregate: - input: - aggregate_input - output: - "aggegated.txt" - shell: - "cat {input} > {output}" + rule aggregate: + input: + aggregate_input + output: + "aggregated.txt" + shell: + "cat {input} > {output}" Because the number of output files is unknown beforehand, the checkpoint only defines an output :ref:`directory `. This time, instead of explicitly writing