|
| 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 | + |
0 commit comments