Skip to content

Commit 7cfa141

Browse files
authored
Merge pull request #16 from psteinb/snakemake-lesson-code
add code for snakemake lesson
2 parents 8fcda03 + 82358a0 commit 7cfa141

14 files changed

+37876
-0
lines changed

commands.mk

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
files/snakemake-lesson.tar.gz: files/snakemake-lesson/*py
2+
@rm -vf $@ && cd files && tar vczf ../$@ snakemake-lesson/*py snakemake-lesson/books/* snakemake-lesson/matplotlibrc snakemake-lesson/cluster.json snakemake-lesson/.Snakefile
3+
4+
files/snakemake-lesson.zip: files/snakemake-lesson/*py
5+
@rm -vf $@ && cd files && zip ../$@ snakemake-lesson/*py snakemake-lesson/books/* snakemake-lesson/matplotlibrc snakemake-lesson/cluster.json snakemake-lesson/.Snakefile
6+
7+
## prep-release : compress contents of snakemake-lesson for release
8+
prep-release: files/snakemake-lesson.zip files/snakemake-lesson.tar.gz

files/snakemake-lesson.tar.gz

-928 KB
Binary file not shown.

files/snakemake-lesson.zip

-942 KB
Binary file not shown.

files/snakemake-lesson/.Snakefile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This is a "hidden" version of the final Snakefile if students want/need
2+
# to run the instructor's copy.
3+
4+
# our zipf analysis pipeline
5+
DATS = glob_wildcards('books/{book}.txt').book
6+
7+
localrules: all, clean, make_archive
8+
9+
rule all:
10+
input:
11+
'zipf_analysis.tar.gz'
12+
13+
# delete everything so we can re-run things
14+
# deletes a little extra for purposes of lesson prep
15+
rule clean:
16+
shell:
17+
'''
18+
rm -rf results dats plots __pycache__
19+
rm -f results.txt zipf_analysis.tar.gz *.out *.log *.pyc
20+
'''
21+
22+
# count words in one of our "books"
23+
rule count_words:
24+
input:
25+
wc='wordcount.py',
26+
book='books/{file}.txt'
27+
output: 'dats/{file}.dat'
28+
threads: 4
29+
log: 'dats/{file}.log'
30+
shell:
31+
'''
32+
echo "Running {input.wc} with {threads} cores on {input.book}." &> {log} &&
33+
python {input.wc} {input.book} {output} &>> {log}
34+
'''
35+
36+
# create a plot for each book
37+
rule make_plot:
38+
input:
39+
plotcount='plotcount.py',
40+
book='dats/{file}.dat'
41+
output: 'plots/{file}.png'
42+
resources: gpu=1
43+
shell: 'python {input.plotcount} {input.book} {output}'
44+
45+
# generate summary table
46+
rule zipf_test:
47+
input:
48+
zipf='zipf_test.py',
49+
books=expand('dats/{book}.dat', book=DATS)
50+
output: 'results.txt'
51+
shell: 'python {input.zipf} {input.books} > {output}'
52+
53+
# create an archive with all of our results
54+
rule make_archive:
55+
input:
56+
expand('plots/{book}.png', book=DATS),
57+
expand('dats/{book}.dat', book=DATS),
58+
'results.txt'
59+
output: 'zipf_analysis.tar.gz'
60+
shell: 'tar -czvf {output} {input}'
61+

files/snakemake-lesson/books/LICENSE_TEXTS.md

+338
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)