Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: small changes to make docs checkpoint example functional #1714

Merged
merged 3 commits into from Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 25 additions & 22 deletions docs/snakefiles/rules.rst
Expand Up @@ -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 <snakefiles-directory_output>`.
This time, instead of explicitly writing
Expand Down