aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--snakemake.el26
2 files changed, 31 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 1c376e9..7f1b796 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,11 @@ NEWS -- history of user-visible changes -*- mode: org; -*-
- The 'wrapper' keyword is now recognized.
+- New command ~snakemake-graph~ displays the graph of dependencies for
+ a rule. (Thanks to Endre Bakken Stovner for the idea and initial
+ implementation.)
+
+
* v0.3.0
** New features
diff --git a/snakemake.el b/snakemake.el
index 20ec2cd..f6d769b 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -350,6 +350,32 @@ targets."
(snakemake-all-rules))
" "))
+;;;###autoload
+(defun snakemake-graph (rules &optional rule-graph)
+ "Display graph for DAG of RULES.
+
+The graph will be processed by `snakemake-dot-program' and
+displayed with `image-mode'.
+
+If prefix argument RULE-GRAPH is non-nil, pass --rulegraph
+instead of --dag to snakemake.
+
+$ snakemake --{dag,rulegraph} -- RULES | display"
+ (interactive (list (or (snakemake-file-targets-at-point 'check)
+ (snakemake-rule-at-point 'target)
+ (snakemake-read-rule 'targets))
+ current-prefix-arg))
+ (let ((dir (snakemake-snakefile-directory)))
+ (with-current-buffer (get-buffer-create "*Snakemake graph*")
+ (setq default-directory dir)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (apply #'call-process snakemake-program nil t nil
+ (if rule-graph "--rulegraph" "--dag")
+ (if (listp rules) rules (list rules))))
+ (image-mode)
+ (pop-to-buffer (current-buffer)))))
+
;;; Compilation commands