-
Notifications
You must be signed in to change notification settings - Fork 1
/
rulegraph.Snakefile
75 lines (65 loc) · 2.46 KB
/
rulegraph.Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os.path
import re
def get_rule(name):
return getattr(rules, name)
def is_target_rule(name):
return not get_rule(name).has_wildcards()
targets = [ 'all', 'all_rnaseq', 'all_chipseq', 'all_rnaseq_eda',
'all_rnaseq_quant', 'all_rnaseq_counts', 'all_rnaseq_diffexp',
'all_macs_callpeak', 'all_epic_callpeak', 'all_idr',
'all_idr_filtered_peaks', 'all_mofa', ]
rule all_rulegraphs:
input:
expand('rulegraphs/{graphtype}-{target}.{filetype}',
graphtype=['rulegraph',],
target=targets,
filetype=['pdf', 'png'])
rule all_dags:
input:
expand('rulegraphs/{graphtype}-{target}.{filetype}',
graphtype=['dag',],
target=targets,
filetype=['pdf', 'png'])
rule rulegraph_svg_to_png:
input: 'rulegraphs/{filename}.svg'
output: 'rulegraphs/{filename}.png'
shell: '''inkscape {input:q} --export-png={output:q} --export-dpi=300'''
rule rulegraph_svg_to_pdf:
input: 'rulegraphs/{filename}.svg'
output: 'rulegraphs/{filename}.pdf'
shell: '''inkscape {input:q} --export-pdf={output:q} --export-dpi=300'''
rule dag_svg:
input: 'Snakefile', 'rulegraph.Snakefile'
output: 'rulegraphs/dag-{target}.svg'
params: target_path=lambda wildcards: re.sub(":", os.path.sep, wildcards.target)
run:
if is_target_rule(params.target_path):
rule = get_rule(params.target_path)
if len(rule.output):
real_targets = rule.output
else:
real_targets = rule.input
else:
real_targets = [params.target_path]
shell('''
snakemake --nolock -f --dag {real_targets:q} | \
dot -Grankdir=LR -Tsvg > {output:q}
''')
rule rulegraph_svg:
input: 'Snakefile', 'rulegraph.Snakefile'
output: 'rulegraphs/rulegraph-{target}.svg'
params: target_path=lambda wildcards: re.sub(":", os.path.sep, wildcards.target)
run:
if is_target_rule(params.target_path):
rule = get_rule(params.target_path)
if len(rule.output):
real_targets = rule.output
else:
real_targets = rule.input
else:
real_targets = [params.target_path]
shell('''
snakemake --nolock -f --rulegraph {real_targets:q} | \
dot -Grankdir=LR -Tsvg > {output:q}
''')
localrules: rulegraph_svg_to_png, rulegraph_svg_to_pdf, dag_svg, rulegraph_svg