Skip to content

Instantly share code, notes, and snippets.

@clintval
Last active October 20, 2023 04:28
Show Gist options
  • Save clintval/69e7bd436c2d4aa9928b6a536c38740d to your computer and use it in GitHub Desktop.
Save clintval/69e7bd436c2d4aa9928b6a536c38740d to your computer and use it in GitHub Desktop.
Render Snakemake DAGs in your terminal
# Convert DOT graph data into a terminal-ready visualization
function idot {
dot \
-Tpng -Gdpi=300 \
-Efontsize=18 -Efontname=sans -Nfontname=sans \
-Gbgcolor=black -Gcolor=white -Ecolor=white -Efontcolor=white -Ncolor=white -Nfontcolor=white \
| convert -trim -bordercolor black -border 20 -transparent black -resize "60%" - - \
| imgcat # Or swap with your favorite terminal image viewer
}
# Render a visualization of the Snakemake pipeline to the terminal
function snakegraph {
local dag
local snakefile="${1:-Snakefile}"
if [ ! -f $snakefile ]; then print "USAGE: snakegraph <Snakefile>"; return 1; fi
dag=$( snakemake -s "${snakefile}" --forceall --dag ) || return 1
echo $dag | idot
}
# Inspired by: https://twitter.com/thingskatedid/status/1386077306381242371
@clintval
Copy link
Author

clintval commented Sep 4, 2023

Screenshot 2023-09-03 at 10 48 31 PM

@yfarjoun
Copy link

yfarjoun commented Sep 5, 2023

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment