Skip to content

Instantly share code, notes, and snippets.

@akhanf
Created September 23, 2023 14:56
Show Gist options
  • Save akhanf/d287ce91cd73197b1876bebfc8ef0ea8 to your computer and use it in GitHub Desktop.
Save akhanf/d287ce91cd73197b1876bebfc8ef0ea8 to your computer and use it in GitHub Desktop.
Simple Snakefile for turning QC snapshots into GIF animations and PDF flipbooks - this example is for snakeanat but can be easily customized by changing the input paths.
subjects,=glob_wildcards('sub-{subject}/qc.html')
print(subjects)
snaps,=glob_wildcards(f'sub-{subjects[0]}/{{snap}}.png')
print(snaps)
rule all:
input:
expand('{ext}s/{snap}.{ext}',ext=['gif','pdf'],snap=snaps)
rule add_annotation:
input:
'sub-{subject}/{snap}.png'
output:
temp('annotated/sub-{subject}/{snap}.png')
shell:
"convert {input} -background black -gravity North -splice 0x40 -fill white -pointsize 30 -annotate +0+2 '{wildcards}' {output}"
rule create_gif:
input:
sorted(expand('annotated/sub-{subject}/{snap}.png',subject=subjects,allow_missing=True))
output:
'gifs/{snap}.gif'
shell:
'convert {input} {output}'
rule create_pdf:
input:
sorted(expand('annotated/sub-{subject}/{snap}.png',subject=subjects,allow_missing=True))
output:
'pdfs/{snap}.pdf'
shell:
'convert {input} {output}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment