File: decorators.rst

package info (click to toggle)
python-ruffus 2.8.4-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,008 kB
  • sloc: python: 17,438; makefile: 215; sh: 18
file content (368 lines) | stat: -rw-r--r-- 13,865 bytes parent folder | download | duplicates (4)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
.. include:: ../global.inc

.. |br| raw:: html

   <br />

#######################
Ruffus Decorators
#######################

.. seealso::
    :ref:`Indicator objects <decorators.indicator_objects>`

.. _decorators:

.. toctree::
    :maxdepth: 1
    :name: core_toc
    :caption: Core
    :hidden:

    originate.rst
    split.rst
    transform.rst
    merge.rst

.. toctree::
    :maxdepth: 1
    :name: advanced_toc
    :caption: Advanced
    :hidden:

    subdivide.rst
    transform_ex.rst
    collate.rst
    graphviz.rst
    mkdir.rst
    jobs_limit.rst
    posttask.rst
    active_if.rst
    follows.rst



.. toctree::
    :maxdepth: 1
    :name: combinatorics_toc
    :caption: Combinatorics
    :hidden:

    product.rst
    permutations.rst
    combinations.rst
    combinations_with_replacement.rst

.. toctree::
    :maxdepth: 1
    :name: esoteric_toc
    :caption: Esoteric
    :hidden:

    files_ex.rst
    check_if_uptodate.rst
    parallel.rst

.. toctree::
    :maxdepth: 1
    :name: deprecated_toc
    :caption: Deprecated
    :hidden:

    files.rst
    files_re.rst


=============================================
*Core*
=============================================
.. csv-table::
   :header: "Decorator", "Examples"
   :widths: 400, 600,1

   "**@originate** (:ref:`Summary <decorators.originate>` / :ref:`Manual <new_manual.originate>`)

    - Creates (originates) a set of starting file from scratch  (*ex nihilo*!)
    - Only called to create files which do not exist.
    - Each item in ``output`` is created by a separate job.

   ", "
   * :ref:`@originate <decorators.originate>` ( ``output``, [``extras``,...] )
           \

   ", ""
   "**@split** (:ref:`Summary <decorators.split>` / :ref:`Manual <new_manual.split>`)

   - Splits a single input into multiple output
   - Globs in ``output`` can specify an indeterminate number of files.

   ", "
   * :ref:`@split <decorators.split>` ( ``input``, ``output``, [``extras``,...] )
           \

   ", ""
   "**@transform** (:ref:`Summary <decorators.transform>` / :ref:`Manual <new_manual.transform>`)

   - | Applies the task function to
     | transform input data to output.

   ", "
   * :ref:`@transform <decorators.transform>` ( ``input``, :ref:`suffix <decorators.transform.suffix_string>`\ () , ``output``, [``extras``,...] )
              \
   * :ref:`@transform <decorators.transform>` ( ``input``, :ref:`regex <decorators.transform.matching_regex>`\ () , ``output``, [``extras``,...] )
           \
   * :ref:`@transform <decorators.transform>` ( ``input``, :ref:`formatter <decorators.transform.matching_formatter>`\ () , ``output``, [``extras``,...] )
           \

   ", ""
   "**@merge** (:ref:`Summary <decorators.merge>` / :ref:`Manual <new_manual.merge>`)

   - Merges multiple input files into a single output.

   ", "
   * :ref:`@merge <decorators.merge>` (``input``, ``output``, [``extras``,...] )
           \

          ", ""

.. _decorators.combinatorics:

=============================================
*Combinatorics*
=============================================
.. csv-table::
   :header: "Decorator", "Examples"
   :widths: 400, 600,1

   "**@product** (:ref:`Summary <decorators.product>` / :ref:`Manual <new_manual.product>`)

    - Generates the **product** between sets of input, i.e. all vs all comparisons.
   ", "
   * :ref:`@product <decorators.product>` ( ``input``, :ref:`formatter <decorators.product.matching_formatter>`\ () ,*[* ``input``, :ref:`formatter <decorators.product.matching_formatter>`\ (), ``output``, [``extras``,...] )
           \

   ", ""
   "**@permutations** (:ref:`Summary <decorators.permutations>` / :ref:`Manual <new_manual.permutations>`)

    - Generates the **permutations**, between all elements of a set of **Input**
    - Analogous to the python `itertools.permutations <http://docs.python.org/2/library/itertools.html#itertools.permutations>`__
    - permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC

   ", "
   * :ref:`@permutations <decorators.permutations>` ( ``input``, :ref:`formatter <decorators.product.matching_formatter>`\ (), ``tuple_size``, ``output``, [``extras``,...] )
           \
   ", ""
   "**@combinations** (:ref:`Summary <decorators.combinations>` / :ref:`Manual <new_manual.combinations>`)

    - Generates the **permutations**, between all elements of a set of **Input**
    - Analogous to the python `itertools.combinations <http://docs.python.org/2/library/itertools.html#itertools.permutations>`__
    - combinations('ABCD', 3) --> ABC ABD ACD BCD
    - Generates the **combinations**, between all the elements of a set of **Input**:
      i.e. r-length tuples of *input* elements with no repeated elements (**A A**)
      and where order of the tuples is irrelevant
      (either **A B** or  **B A**, not both).

   ", "
   * :ref:`@combinations <decorators.permutations>` ( ``input``, :ref:`formatter <decorators.product.matching_formatter>`\ (), ``tuple_size``, ``output``, [``extras``,...] )
           \

   ", ""
   "**@combinations_with_replacement** (:ref:`Summary <decorators.combinations_with_replacement>` / :ref:`Manual <new_manual.combinations_with_replacement>`)

    - Generates the **permutations**, between all the elements of a set of **Input**
    - Analogous to the python `itertools.permutations <http://docs.python.org/2/library/itertools.html#itertools.permutations>`__
    - combinations('ABCD', 3) --> ABC ABD ACD BCD
    - Generates the **combinations_with_replacement**,
      between all the elements of a set of **Input**:
      i.e. r-length tuples of *input* elements with no repeated elements (**A A**)
      and where order of the tuples is irrelevant
      (either **A B** or  **B A**, not both).

   ", "
   * :ref:`@combinations_with_replacement <decorators.permutations>` ( ``input``, :ref:`formatter <decorators.product.matching_formatter>`\ (), ``tuple_size``, ``output``, [``extras``,...] )
           \

   ", ""

=============================================
*Advanced*
=============================================
 .. csv-table::
   :header: "Decorator", "Examples"
   :widths: 400, 600,1

   "**@subdivide** (:ref:`Summary <decorators.subdivide>` / :ref:`Manual <new_manual.subdivide>`)

   - Subdivides each *input* into multiple *Outputs*.
   - The number of *output* can be determined at runtime using globs.
   - **Many to Even More** operator.
   - Do not use **split** as a synonym for **subdivide**.

   ", "
   * :ref:`@subdivide <decorators.subdivide>` ( ``input``, :ref:`regex <decorators.subdivide.matching_regex>`\ () , [ :ref:`inputs <decorators.inputs>` | :ref:`add_inputs <decorators.add_inputs>`\ *(*\ ``input_pattern``\ *)*\ , ] ``output``, [``extras``,...] )
           \
   * :ref:`@subdivide <decorators.subdivide>` ( ``input``, :ref:`formatter <decorators.subdivide.matching_formatter>`\ *(*\ [] *)*\ , [ :ref:`inputs <decorators.inputs>` | :ref:`add_inputs <decorators.add_inputs>`\ *(*\ ``input_pattern``\ *)*\ , ] ``output``, [``extras``,...] )
           \

   ", ""
   "**@transform** (:ref:`Summary <decorators.transform_ex>` / :ref:`Manual <new_manual.inputs>`)

   - Generates both **input** & **output** from regular expressions
   - Useful for adding additional file dependencies

   ", "
   * :ref:`@transform <decorators.transform_ex>` ( ``input``, :ref:`regex <decorators.transform.matching_regex>`\ () , [ :ref:`inputs <decorators.inputs>` | :ref:`add_inputs <decorators.add_inputs>`\ *(*\ ``input_pattern``\ *)*\ , ] ``output``, [``extras``,...] )
           \
   * :ref:`@transform <decorators.transform_ex>` ( ``input``, :ref:`formatter <decorators.transform.matching_formatter>`\ () , [ :ref:`inputs <decorators.inputs>` | :ref:`add_inputs <decorators.add_inputs>`\ *(*\ ``input_pattern``\ *)*\ , ] ``output``, [``extras``,...] )
           \

   ", ""
   "**@collate** (:ref:`Summary <decorators.collate>` / :ref:`Manual <new_manual.collate>`)

   - Groups multiple input using regular expression matching.
   - Multiple input generating identical output are collated together.

   ", "
   * :ref:`@collate <decorators.collate>` (``input``, :ref:`regex <decorators.collate.matching_regex>`\ () , ``output``, [``extras``,...] )
           \
   * :ref:`@collate <decorators.collate_ex>` (``input``, :ref:`regex <decorators.collate_ex.matching_regex>`\ () , :ref:`inputs <decorators.inputs>` | :ref:`add_inputs <decorators.add_inputs>`\ *(*\ ``input_pattern``\ *)*\ , ``output``, [``extras``,...] )
           \
   * :ref:`@collate <decorators.collate>` (``input``, :ref:`formatter <decorators.collate.matching_formatter>`\ () , ``output``, [``extras``,...] )
           \
   * :ref:`@collate <decorators.collate_ex>` (``input``, :ref:`formatter <decorators.collate_ex.matching_formatter>`\ () , :ref:`inputs <decorators.inputs>` | :ref:`add_inputs <decorators.add_inputs>`\ *(*\ ``input_pattern``\ *)*\ , ``output``, [``extras``,...] )
           \

   ", ""
   "**@follows** (:ref:`Summary <decorators.follows>` / :ref:`Manual <new_manual.follows>`)

   - Indicates task dependency
   - optional :ref:`mkdir <decorators.follows.directory_name>` prerequisite (:ref:`see Manual <new_manual.follows.mkdir>`)

   ", "
   * :ref:`@follows <decorators.follows>` ( ``task1``, ``'task2'`` ))
      \
   * :ref:`@follows <decorators.follows>` ( ``task1``,  :ref:`mkdir <decorators.follows.directory_name>`\ ( ``'my/directory/'`` ))
      \

   ", ""
   "**@posttask** (:ref:`Summary <decorators.posttask>` / :ref:`Manual <new_manual.posttask>`)

   - Calls function after task completes
   - Optional :ref:`touch_file <decorators.posttask.file_name>` indicator (:ref:`Manual <new_manual.posttask.touch_file>`)

   ", "
   * :ref:`@posttask <decorators.posttask>` ( ``completion_signal_func`` )
           \
   * :ref:`@posttask <decorators.posttask>` (:ref:`touch_file <decorators.touch_file>`\ ( ``'task1.done'`` ))
           \

   ", ""
   "**@active_if** (:ref:`Summary <decorators.active_if>` / :ref:`Manual <new_manual.active_if>`)

    - Switches tasks on and off at run time
    - Evaluated each time you call
        * :ref:`pipeline_run(...) <pipeline_functions.pipeline_run>`,
        * :ref:`pipeline_printout(...) <pipeline_functions.pipeline_printout>` or
        * :ref:`pipeline_printout_graph(...) <pipeline_functions.pipeline_printout_graph>`
    - Dormant tasks behave as if they are :
        * up to date and
        * have no output.

   ", "
   * :ref:`@active_if <decorators.active_if>` ( ``on_or_off1``, ``[on_or_off2, ...]`` )
           \

   ", ""
   "**@jobs_limit** (:ref:`Summary <decorators.jobs_limit>` / :ref:`Manual <new_manual.jobs_limit>`)

   - Limits the amount of multiprocessing for the specified task
   - Ensures that fewer than N jobs are run in parallel for this task
   - Overrides ``multiprocess`` parameter in :ref:`pipeline_run(...) <pipeline_functions.pipeline_run>`
   ", "
   * :ref:`@jobs_limit <decorators.jobs_limit>` ( ``NUMBER_OF_JOBS_RUNNING_CONCURRENTLY`` )
           \

   ", ""
   "**@mkdir** (:ref:`Summary <decorators.mkdir>` / :ref:`Manual <new_manual.mkdir>`)

   - Generates paths for `os.makedirs  <http://docs.python.org/2/library/os.html#os.makedirs>`__

   ", "
   * :ref:`@mkdir <decorators.mkdir>` ( ``input``, :ref:`suffix <decorators.mkdir.suffix_string>`\ () , ``output`` )
              \
   * :ref:`@mkdir <decorators.mkdir>` ( ``input``, :ref:`regex <decorators.mkdir.matching_regex>`\ () , ``output`` )
           \
   * :ref:`@mkdir <decorators.mkdir>` ( ``input``, :ref:`formatter <decorators.mkdir.matching_formatter>`\ () , ``output``)
           \

   ", ""
   "**@graphviz** (:ref:`Summary <decorators.graphviz>` / :ref:`Manual <new_manual.pipeline_printout_graph>`)

   - Customise the task graphics in
     flowcharts from :ref:`pipeline_printout_graph(...) <pipeline_functions.pipeline_printout_graph>`

   ", "
   * :ref:`@graphviz <decorators.graphviz>` ( ``graphviz_parameter = XXX``, ``[graphviz_parameter2 = YYY ...]``)
           \

   ", ""



=============================================
*Esoteric!*
=============================================
 .. csv-table::
   :header: "Decorator", "Examples"
   :widths: 400, 600,1

   "**@files** (:ref:`Summary <decorators.files>` / :ref:`Manual <new_manual.deprecated_files>`)

   - I/O parameters
   - skips up-to-date jobs
   - Should use :ref:`@transform <decorators.transform>` etc instead

   ", "
   * :ref:`@files <decorators.files>`\ ( ``parameter_list`` )
           \
   * :ref:`@files <decorators.files>`\ ( ``parameter_generating_function`` )
           \
   * :ref:`@files <decorators.files>` ( ``input_file``, ``output_file``, ``other_params``, ... )
           \

   ", ""
   "**@parallel** (:ref:`Summary <decorators.parallel>` / :ref:`Manual <new_manual.deprecated_parallel>`)

   - By default, does not check if jobs are up to date
   - Best used in conjuction with :ref:`@check_if_uptodate <decorators.check_if_uptodate>`

   ", "
   * :ref:`@parallel <decorators.parallel>` ( ``parameter_list`` )
           \
   * :ref:`@parallel <decorators.parallel>` ( ``parameter_generating_function`` )
           \

   ", ""
   "**@check_if_uptodate** (:ref:`Summary <decorators.check_if_uptodate>` / :ref:`Manual <new_manual.check_if_uptodate>`)

   - Custom function to determine if jobs need to be run

   ", "
   * :ref:`@check_if_uptodate <decorators.check_if_uptodate>` ( ``is_task_up_to_date_function`` )
           \

   ", ""
   ".. tip::
     The use of this is discouraged.
       **@files_re** (:ref:`Summary <decorators.files_re>`)

       - I/O file names via regular
         expressions
       - start from lists of file names
         or |glob|_ results
       - skips up-to-date jobs
   ", "
   * :ref:`@files_re <decorators.files_re>` ( ``input``, ``matching_regex``, [``input_pattern``,] ``output``, ``...`` )

   ", ""