Provide wrapper functors to allow re-use of the same function in ruffus
Closed this issue · 1 comments
AndreasHeger commented
Ruffus does not permit to use the same function twice in the same workflow. This can be annoying as you might have files of the same type produced in the workflow at different stages, but want to run the same QC function on them.
The following pattern is a start:
class EmptyRunner(object):
def __init__(self, name):
self.__name__ = name
def __call__(self, *args, **kwargs):
pass
class PassThroughRunner(object):
def __init__(self, name, f):
self.__name__ = name
self.f = f
def __call__(self, *args, **kwargs):
self.f(*args, **kwargs)
Usage:
def my_qc_fun(infile, outfile):
pass
task_qc_a = pipeline.merge(
task_func=PassThroughRunner(
name="run_qc_1",
f=my_qc_function),
input=task_build_data1,
output="a.qc")
task_qc_b = pipeline.merge(
task_func=PassThroughRunner(
name="run_qc_2",
f=my_qc_function),
input=task_build_data1,
output="b.qc")
Note how my_qc_function is reused.
Also:
task_all = pipeline.merge(
task_func=EmptyRunner(name="all"),
input=[task_plot_tests],
output="all")
which allows you to run make all
AndreasHeger commented
See pipeline/wrappers.py , 70567d3