Skip to content

add code for snakemake lesson #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions commands.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
files/snakemake-lesson.tar.gz: files/snakemake-lesson/*py
@rm -vf $@ && cd files && tar vczf ../$@ snakemake-lesson/*py snakemake-lesson/books/* snakemake-lesson/matplotlibrc snakemake-lesson/cluster.json snakemake-lesson/.Snakefile

files/snakemake-lesson.zip: files/snakemake-lesson/*py
@rm -vf $@ && cd files && zip ../$@ snakemake-lesson/*py snakemake-lesson/books/* snakemake-lesson/matplotlibrc snakemake-lesson/cluster.json snakemake-lesson/.Snakefile

## prep-release : compress contents of snakemake-lesson for release
prep-release: files/snakemake-lesson.zip files/snakemake-lesson.tar.gz
Binary file modified files/snakemake-lesson.tar.gz
Binary file not shown.
Binary file modified files/snakemake-lesson.zip
Binary file not shown.
61 changes: 61 additions & 0 deletions files/snakemake-lesson/.Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This is a "hidden" version of the final Snakefile if students want/need
# to run the instructor's copy.

# our zipf analysis pipeline
DATS = glob_wildcards('books/{book}.txt').book

localrules: all, clean, make_archive

rule all:
input:
'zipf_analysis.tar.gz'

# delete everything so we can re-run things
# deletes a little extra for purposes of lesson prep
rule clean:
shell:
'''
rm -rf results dats plots __pycache__
rm -f results.txt zipf_analysis.tar.gz *.out *.log *.pyc
'''

# count words in one of our "books"
rule count_words:
input:
wc='wordcount.py',
book='books/{file}.txt'
output: 'dats/{file}.dat'
threads: 4
log: 'dats/{file}.log'
shell:
'''
echo "Running {input.wc} with {threads} cores on {input.book}." &> {log} &&
python {input.wc} {input.book} {output} &>> {log}
'''

# create a plot for each book
rule make_plot:
input:
plotcount='plotcount.py',
book='dats/{file}.dat'
output: 'plots/{file}.png'
resources: gpu=1
shell: 'python {input.plotcount} {input.book} {output}'

# generate summary table
rule zipf_test:
input:
zipf='zipf_test.py',
books=expand('dats/{book}.dat', book=DATS)
output: 'results.txt'
shell: 'python {input.zipf} {input.books} > {output}'

# create an archive with all of our results
rule make_archive:
input:
expand('plots/{book}.png', book=DATS),
expand('dats/{book}.dat', book=DATS),
'results.txt'
output: 'zipf_analysis.tar.gz'
shell: 'tar -czvf {output} {input}'

338 changes: 338 additions & 0 deletions files/snakemake-lesson/books/LICENSE_TEXTS.md

Large diffs are not rendered by default.

Loading