cgat-developers/cgat-core

Variable substitution in Ruffus decorator?

Closed this issue · 3 comments

Hi,

Is it possible to perform variable substitution in the Ruffus header - I would like to set the input and output directories based on the .yml file (so that they are not local paths from the cwd).

e.g.

@transform(PARAMS["directory_input"] + "/*/matrix.mtx.gz",
           regex(PARAMS["directory_input"] + r"/(\d{2}_B\d{1})/matrix.mtx.gz"),
           PARAMS["directory_output"] + r"/results/Robjects/\1_seurat_singlet.rds")
def hto_demux(infile, outfile):
    '''Run HTO demux script for individual samples'''

This seems to work but I'm not sure if it is the best way do to it?

Best,
Lucy

Hi, yes, this should work.Parameters for inputs/outputs in ruffus are just strings (or list of strings) that can be composed any which way.

Not having tested it, but you can probably simplify a little:

@transform(PARAMS["directory_input"] + "/*/matrix.mtx.gz",
           regex(r"/(\d{2}_B\d{1})/matrix.mtx.gz"),
           PARAMS["directory_output"] + r"/results/Robjects/\1_seurat_singlet.rds")
def hto_demux(infile, outfile):
    '''Run HTO demux script for individual samples'''

Great thank you, I'll give it a go.

Thanks @AndreasHeger. Do you see any way to simplify the following?

@subdivide(tcr_by_donor,
           regex(PARAMS["working_dir"] + 
           r"/results/TCR/(\w+-?\d+)_MAIT_paired_chains.txt"), 
           [PARAMS["working_dir"] + r"/results/TCR/tmp/MAIT_\1_nt.tmp",
           PARAMS["working_dir"] + r"/results/TCR/tmp/MAIT_\1_alpha_nt.tmp",
           PARAMS["working_dir"] + r"/results/TCR/tmp/MAIT_\1_beta_nt.tmp"])