summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-04-16 11:21:17 -0400
committerKyle Meyer <kyle@kyleam.com>2016-04-17 12:38:07 -0400
commitab40d5ac70e99689ffec68b1e39d99c1c7b4a654 (patch)
tree0c3b992a48987096539e0d2ab7ec2e533eb87a3a
parent6b538a9f5e2d9e9a138704b0a702ffe1237dc57b (diff)
downloadsnakemake-mode-ab40d5ac70e99689ffec68b1e39d99c1c7b4a654.tar.gz
Add snakemake-graph command
Re: #9
-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