#!/usr/bin/env python # coding: utf-8 # This notebook contains an example of combining checkpoint use inside a input function in Snakemake 8.18.2. The notebook was based on a [work](https://edwards.flinders.edu.au/how-to-use-snakemake-checkpoints/) written on an outdated version of the library. # # Acknowledgments: I would like to thank [Wayne](https://stackoverflow.com/users/8508004/wayne) for his help in implementation. # In[1]: get_ipython().system(' snakemake --version') # # Case # In[1]: get_ipython().system(' cat Snakefile') # In the source code, the {SAMPLE} wildcard uses the value of the SMP variable. However, SMP is initially defined as None, which may cause the code to not work correctly. When a checkpoint is executed, the SMP variable changes and must maintain a list of file names in the OUTDIR directories. # In[3]: get_ipython().system('snakemake -c 1 --debug-dag') # The logs show that after executing make_five_files, the {SAMPLE} wildcard gets the correct values (for example, 10536, 16393, etc.). copy_files and list_all_files are selected multiple times with SAMPLE=None, which is not correct behavior. # In[5]: get_ipython().system('ls') # In[2]: get_ipython().system('ls first_directory/') # In[4]: get_ipython().system('ls second_directory/') # # Solution # Using a function that returns a list of file names from a directory. The OUTDIR directory is used as input in the all rule. # In[6]: get_ipython().system(' cat Snakefile') # In[2]: get_ipython().system(' snakemake -c 1 -F') # In[3]: get_ipython().system(' ls') # In[4]: get_ipython().system(' ls first_directory/') # Let's add the creation of files in a new directory. The directory name is specified by the SNDDIR variable at the beginning of the file. # In[7]: get_ipython().system(' cat Snakefile') # In[14]: get_ipython().system(' snakemake -c 1 -F') # In[15]: get_ipython().system(' ls') # In[16]: get_ipython().system(' ls first_directory/') # In[17]: get_ipython().system(' ls second_directory/') # In[ ]: