workflows
Before starting review/execute the useful tips.
Writing pipelines with SnakeMake
There is excellent presentation made by snakemake authors, which you should read, since the code below closely follows it. Official tutorial describes more advanced example.
First, install SnakeMake:
conda activate envname
# In case you don't have it yet
conda install snakemakeBasic example
Let's start with very basic example - sorting some files.
mkdir snake_test
cd snake_test
# Following lines create two files with numbers randomly generated
# in a range from 1 to 10
python -c $'import random\nfor i in range(5): print(random.randint(1,10))' > A.txt
python -c $'import random\nfor i in range(5): print(random.randint(1,10))' > B.txtThe content of the A.txt:
(ngschool) aln@aln-vb:~/snake_test$ cat A.txt
7
10
6
6
2Create the file names Snakefile with the following content:
If you run snakemake you should see following:
We also have new file in our folder:
Now, let's modify Snakefile, so it will process both A and B files. By default snakemake executes the first rule in the snakefile. This gives rise to pseudo-rules at the beginning of the file that can be used to define build-targets similar to GNU Make. So, in a way in the all rule we request all the output files to be present, and Snakemake recognizes automatically that these can be created by multiple applications of the rule sort:
Try to execute snakemake again, you will see following:
But what is peculiar about this output? Rule sort sorted only B file, right? That's because we already sorted A and we have A output already in our folder. We can force all tasks execution and see if the output is different:
So, now we see that sort processed both A and B files.
NB:
-fflag will force execute firth rule regardless of the output, and-Fwill force execute all the rules.
Some more useful commands:
Amazing feature of the snakemake is pipeline diagram plotting:
How about some parallelization?
Then we can start snakemake with the following parameters:
Finally, we would want to read the input list from external file as the current design is not customizable enough. First, create config file:
Then edit your Snakefile in a following way:
And last, run snakemake:
Advanced example
Run following commands:
Check fastqc html report. What can you tell about it? Closely examine rules and workflows folders. What is different about this snakemake workflow design if you compare with previous simple example?
Useful links:
Last updated