Chapter 7: Python Code for Displaying the pipeline visually with pipeline_printout_graph(…)

Code

 1from ruffus import *
 2import sys
 3
 4#---------------------------------------------------------------
 5#   create initial files
 6#
 7@originate([   ['job1.a.start', 'job1.b.start'],
 8               ['job2.a.start', 'job2.b.start'],
 9               ['job3.a.start', 'job3.b.start']    ])
10def create_initial_file_pairs(output_files):
11    # create both files as necessary
12    for output_file in output_files:
13        with open(output_file, "w") as oo: pass
14
15#---------------------------------------------------------------
16#   first task
17@transform(create_initial_file_pairs, suffix(".start"), ".output.1")
18def first_task(input_files, output_file):
19    with open(output_file, "w"): pass
20
21
22#---------------------------------------------------------------
23#   second task
24@transform(first_task, suffix(".output.1"), ".output.2")
25def second_task(input_files, output_file):
26    with open(output_file, "w"): pass
27
28#  Print graph before running pipeline
29
30#---------------------------------------------------------------
31#
32#       Show flow chart and tasks before running the pipeline
33#
34print "Show flow chart and tasks before running the pipeline"
35pipeline_printout_graph ( open("simple_tutorial_stage5_before.png", "w"),
36                         "png",
37                         [second_task],
38                         minimal_key_legend=True)
39
40#---------------------------------------------------------------
41#
42#       Run
43#
44pipeline_run([second_task])
45
46
47# modify job1.stage1
48open("job1.a.output.1", "w").close()
49
50
51#  Print graph after everything apart from ``job1.a.output.1`` is update
52
53#---------------------------------------------------------------
54#
55#       Show flow chart and tasks after running the pipeline
56#
57print "Show flow chart and tasks after running the pipeline"
58pipeline_printout_graph ( open("simple_tutorial_stage5_after.png", "w"),
59                         "png",
60                         [second_task],
61                         no_key_legend=True)

Resulting Flowcharts

Before running the pipeline

Before

After running the pipeline

After

Legend key

Legend