Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time

Code Club: Gentle Introduction to Snakemake

Exercises

Exercise ex1:

Write a Snakemake rule generate_data using Python language to generate two vectors of random numbers of size 100 and save each vector to a separate text file: x.txt and y.txt.

Hint 1. Import numpy library

import numpy as np

Hint 2. Define the names of the output files before the rules

file_ids = ['x', 'y']

Hint 3. Use special Snakemake function to create a list of output filenames from a pattern (for example, in the rule all)

expand("data/{file}.txt", file = file_ids)

Exercise ex2:

Write a snakemake rule subset_data using shell to create two subsets from the generated files, so that each new file will contain the value less or equal to 0.5. Save each new generated vector to a separate text file: x_subset.txt and y_subset.txt.

Hint 1. Use the awk shell command to subset the data and > to redirect the output:

awk ‘$1 <= 0.5’ {input} > {output}

Exercise ex3:

Write a snakemake rule using the custom R script (scripts/plot.R) to plot two vectors generated in the ex2.


Exercise ex4:

Combine all rules into one pipeline, delete all before generated files and run the whole pipeline again specifying the final output.