/doc/tutorials/simple_tutorial/step4_run_pipeline_graphically_code.rst

https://code.google.com/p/ruffus/ · ReStructuredText · 104 lines · 84 code · 20 blank · 0 comment · 0 complexity · adcd2f32dca5923f637c2130840f98f6 MD5 · raw file

  1. .. include:: ../../global.inc
  2. .. _Simple_Tutorial_4th_step_graphical_code:
  3. ###################################################################
  4. Code for Step 4: Displaying the pipeline visually
  5. ###################################################################
  6. * :ref:`Simple tutorial overview <Simple_Tutorial>`
  7. * :ref:`pipeline functions <pipeline_functions>` in detail
  8. * :ref:`Back to Step 4 <Simple_Tutorial_4th_step_graphical>`
  9. ************************************
  10. Code
  11. ************************************
  12. ::
  13. from ruffus import *
  14. import time
  15. #---------------------------------------------------------------
  16. #
  17. # first task
  18. #
  19. task1_param = [
  20. [ None, 'job1.stage1'], # 1st job
  21. [ None, 'job2.stage1'], # 2nd job
  22. ]
  23. @files(task1_param)
  24. def first_task(no_input_file, output_file):
  25. open(output_file, "w")
  26. #---------------------------------------------------------------
  27. #
  28. # second task
  29. #
  30. task2_param = [
  31. [ 'job1.stage1', "job1.stage2", " 1st_job"], # 1st job
  32. [ 'job2.stage1', "job2.stage2", " 2nd_job"], # 2nd job
  33. ]
  34. @follows(first_task)
  35. @files(task2_param)
  36. def second_task(input_file, output_file, extra_parameter):
  37. open(output_file, "w")
  38. print extra_parameter
  39. #---------------------------------------------------------------
  40. #
  41. # Show flow chart and tasks before running the pipeline
  42. #
  43. print "Show flow chart and tasks before running the pipeline"
  44. pipeline_printout_graph ( open("flowchart_before.png", "w"),
  45. "png",
  46. [second_task],
  47. no_key_legend=True)
  48. #---------------------------------------------------------------
  49. #
  50. # Run
  51. #
  52. pipeline_run([second_task])
  53. # modify job1.stage1
  54. open("job1.stage1", "w").close()
  55. #---------------------------------------------------------------
  56. #
  57. # Show flow chart and tasks after running the pipeline
  58. #
  59. print "Show flow chart and tasks after running the pipeline"
  60. pipeline_printout_graph ( open("flowchart_after.png", "w"),
  61. "png",
  62. [second_task],
  63. no_key_legend=True)
  64. ************************************
  65. Resulting Flowcharts
  66. ************************************
  67. +-------------------------------------------------------------+-----------------------------------------------------------------------+
  68. | .. image:: ../../images/simple_tutorial_stage4_before.png | .. image:: ../../images/simple_tutorial_stage4_after.png |
  69. | :alt: Before running the pipeline | :alt: After running the pipeline |
  70. | :scale: 50 | :scale: 50 |
  71. | :align: center | :align: center |
  72. | | |
  73. | .. centered:: Before | .. centered:: After |
  74. | | |
  75. +-------------------------------------------------------------+-----------------------------------------------------------------------+
  76. +-------------------------------------------------------------------------------------------------------------------------------------+
  77. | .. image:: ../../images/tutorial_key.jpg |
  78. | :alt: Legend key |
  79. | :scale: 75 |
  80. | :align: center |
  81. | |
  82. | .. centered:: Legend |
  83. | |
  84. +-------------------------------------------------------------------------------------------------------------------------------------+