|
| 1 | +# Documentation for Snakemake workflow NAME HERE |
| 2 | + |
| 3 | +Describe the purpose of the workflow (the big picture) |
| 4 | + |
| 5 | +## General concepts |
| 6 | + |
| 7 | +### Folder structure |
| 8 | + |
| 9 | +By following the below guides, you will end up with a Snakemake |
| 10 | +working directory (for short: `wd`) with the following subfolders: |
| 11 | + |
| 12 | +`wd/results/`: this folder contains final results and some workflow metadata |
| 13 | +and represents the only relevant output folder from the end user perspective. |
| 14 | +Accidentally deleting this folder after a successful pipeline run means you have to |
| 15 | +restart the pipeline and Snakemake will check which result files have to be recreated. |
| 16 | + |
| 17 | +`wd/proc/`: the `processing` folder contains intermediate files |
| 18 | +and is not of interest to end users. As a design principle, deleting this |
| 19 | +folder after successful pipeline execution must not result in the loss of |
| 20 | +any relevant data. |
| 21 | + |
| 22 | +The folders `wd/log/` (log files), `wd/rsrc/` (resource/benchmark files) and both |
| 23 | +reference data folders (`wd/global_ref/` and `wd/local_ref/`) should not contain |
| 24 | +any processed sample data (clean design), and are only relevant for workflow developers. |
| 25 | + |
| 26 | +### Accounting: the file manifest |
| 27 | + |
| 28 | +If properly set up, each workflow automatically creates a result file |
| 29 | +named `manifest.tsv` (in the folder `wd/results/`). This |
| 30 | +file lists all (i) input, (ii) reference (from `wd/global_ref/`) and (iii) |
| 31 | +result files together with metadata such as file size and data checksums |
| 32 | +(both MD5 and SHA256). This file is of utmost importance to track which |
| 33 | +input files in conjunction with which reference files were used to produce |
| 34 | +a certain set of result files. Never-ever delete this file. |
| 35 | + |
| 36 | +**Important** Preparing the computation of all checksums etc. that are needed |
| 37 | +to complete the file manifest, is done during a `--dryrun` of the pipeline. If you |
| 38 | +are sure that the pipeline will run start to finish, run Snakemake with the |
| 39 | +option `--dryrun` twice before actually starting the computations. This will |
| 40 | +ensure that all metadata files (checksums etc.) will be known to Snakemake |
| 41 | +when the pipeline run starts and will be created as part of the regular flow |
| 42 | +of computations. |
| 43 | + |
| 44 | +### Rerunning the exact same workflow |
| 45 | + |
| 46 | +By default, after a successful pipeline run, a complete dump of the workflow |
| 47 | +configuration is written to a file named `run_config.yaml` (in the folder |
| 48 | +`wd/results/`). This configuration dump includes the information which user |
| 49 | +executated the workflow and which (code) version of the worklow was used. |
| 50 | +Assuming that the execution infrastructure (i.e., the compute cluster) is |
| 51 | +the same, it is possible to use just this configuration file to rerun the workflow |
| 52 | +in the exact same way. Never-ever delete this file. |
| 53 | + |
| 54 | +## Documentation for users |
| 55 | + |
| 56 | +If you want to use this workflow as a black box to process your data, |
| 57 | +simply follow the below series of steps to get things up and running. |
| 58 | + |
| 59 | +### Deploying the workflow on execution hardware |
| 60 | + |
| 61 | +1. run `./init.py` (requires Python3) |
| 62 | + - this will create an "execution" Conda environment, |
| 63 | + and a Snakemake working directory plus standard subfolders |
| 64 | + one level above the repository location |
| 65 | +2. activate the created Conda environment: `cd .. && conda activate ./exec_env` |
| 66 | +3. prepare profile and configuration files as necessary, and run Snakemake |
| 67 | + |
| 68 | + |
| 69 | +### Detailed output specification |
| 70 | + |
| 71 | +For detailed descriptions, this should be moved in a separate markdown file. |
| 72 | + |
| 73 | +## Documentation for developers |
| 74 | + |
| 75 | +### Developing the workflow locally |
| 76 | + |
| 77 | +1. run `./init.py --dev-only` (requires Python3) |
| 78 | + - this will skip creating the workflow working directory and subfolders |
| 79 | +2. activate the created Conda environment: `conda activate ./dev_env` |
| 80 | +3. write your code, and add tests to `workflow/snaketests.smk` |
| 81 | +4. run tests: |
| 82 | + - note that some tests may be expected to fail and may produce error messages |
| 83 | + - if Snakemake reports a successful pipeline run, then all tests have succeeded |
| 84 | + irrespective of log messages that look like errors |
| 85 | + - if you want to test the functions loading reference data from reference containers, |
| 86 | + you need to build the test container `test_v0.sif` and copy it into the |
| 87 | + working directory for the workflow test run. Refer to the |
| 88 | + [reference container repository](https://github.com/core-unit-bioinformatics/reference-container) |
| 89 | + for build instructions. |
| 90 | + |
| 91 | +```bash |
| 92 | +# Example: test w/o reference container |
| 93 | +# Note: execute the workflow first in |
| 94 | +# '--dryrun' mode to trigger (and test) |
| 95 | +# the complete MANIFEST creation |
| 96 | +snakemake --cores 1 \ |
| 97 | + [--dryrun] \ |
| 98 | + --config devmode=True \ |
| 99 | + --directory wd/ \ |
| 100 | + --snakefile workflow/snaketests.smk |
| 101 | + |
| 102 | +# Example: test w/ reference container; |
| 103 | +# the container 'test_v0.sif' must exist |
| 104 | +# in the working directory: 'wd/test_v0.sif' |
| 105 | +# Note: execute the workflow first in |
| 106 | +# '--dryrun' mode to trigger (and test) |
| 107 | +# the complete MANIFEST creation |
| 108 | +snakemake --cores 1 \ |
| 109 | + [--dryrun] \ |
| 110 | + --config devmode=True \ |
| 111 | + --directory wd/ \ |
| 112 | + --configfiles config/testing/params_refcon.yaml \ |
| 113 | + --snakefile workflow/snaketests.smk |
| 114 | +``` |
| 115 | + |
| 116 | +5. run the recommended code checks with the following tools: |
| 117 | + - Python scripts: |
| 118 | + - linting: `pylint <script.py>` |
| 119 | + - organize imports: `isort <script.py>` |
| 120 | + - code formatting: `black [--check] .` |
| 121 | + - Snakemake files: |
| 122 | + - linting: `snakemake --config devmode=True --lint` |
| 123 | + - code formatting: `snakefmt [--check] .` |
| 124 | +6. after checking and standardizing your code, commit and push your changes |
0 commit comments