Convert a Snakemake rule graph into a metro map
nf-metro converts the rule graph or job DAG that Snakemake prints into a metro map.
Get the graph from Snakemake
Section titled “Get the graph from Snakemake”Snakemake prints its workflow graph without running any jobs:
snakemake --rulegraph > rules.dotnf-metro accepts all four forms of this output:
--rulegraph(one node per rule) or--dag(one node per job). A rule that runs many jobs becomes one station.- DOT (the default) or
--rulegraph mermaid-js.
Render directly
Section titled “Render directly”Convert and render in one step with the --from snakemake flag:
nf-metro render rules.dot -o workflow.svg --from snakemakeA short workflow
Section titled “A short workflow”A five-rule workflow, plus the usual all target rule:
rule all: input: "multiqc/report.html"
rule fastqc: # reads/{sample}.fq.gz -> fastqc/{sample}.ziprule trim_reads: # reads/{sample}.fq.gz -> trimmed/{sample}.fq.gzrule align: # trimmed reads + genome.fa -> aligned/{sample}.bamrule sort_bam: # aligned/{sample}.bam -> sorted/{sample}.bamrule multiqc: # every fastqc zip and sorted BAM -> multiqc/report.htmlRendered map
Each rule becomes a station, and each dependency between two rules becomes a connection.
The converter drops the all rule, because it only collects the final outputs.
It drops all only when no other rule uses its outputs.
Variant calling (diamond pattern)
Section titled “Variant calling (diamond pattern)”Two variant callers read the same alignment and meet again at BCFtools Stats:
rule bwa_mem: # reads + genome.fa -> aligned/{sample}.bamrule samtools_index: # aligned/{sample}.bam -> aligned/{sample}.bam.bairule gatk_haplotypecaller: # BAM + BAI + genome.fa -> calls/gatk/{sample}.vcfrule deepvariant: # BAM + BAI + genome.fa -> calls/deepvariant/{sample}.vcfrule bcftools_stats: # both VCFs -> stats/{sample}.txtRendered map
The main line runs from BWA through DeepVariant to MultiQC, the final rule with the most rules upstream.
The GATK branch and the FastQC route each get their own line, so the legend tells the three routes apart.
One line for everything
Section titled “One line for everything”To put every rule on a single main line instead, convert with --lines sections:
nf-metro convert rules.dot -o workflow.mmd --lines sectionsnf-metro render workflow.mmd -o workflow.svgRendered map
Limits
Section titled “Limits”Snakemake’s graph output contains rules and dependencies only:
- One section. The output has no grouping (job
group:directives do not appear in it), so every rule goes into one section. nf-metro folds a long section onto more rows. - Lines from the graph’s shape. The
mainline is the longest chain of rules into the main final rule: the one with the most rules upstream. Ties go to the rule with more direct inputs, then to the first by name. Each other chain of rules, longest first, becomes its own line, named after its first rule not already on a line, or after its last rule when every rule on it already is. Lines carry no color, so the theme’s palette colors them. Rename lines or regroup them by hand if your workflow’s routes differ, or convert with--lines sectionsfor a singlemainline. - Rule names as labels. The converter turns
bwa_meminto Bwa Mem. - No shortcut connections. When a rule reads from both an earlier rule and a rule in between, only the path through the rule in between is drawn. The longer path already shows that order, so the direct dependency would only duplicate it.
Hand-tune the output
Section titled “Hand-tune the output”Convert to a .mmd file, edit it, then render it:
nf-metro convert rules.dot -o workflow.mmd --title "My Workflow"# edit workflow.mmd: add sections, lines, and better labelsnf-metro render workflow.mmd -o workflow.svgnf-metro convert detects Snakemake input automatically.
To set the format yourself, use --from snakemake.
See the guide for the directives you can add.