Search code examples
pythonsnakemake

Snakemake expand zip some wildcards and expand full the other


I have three lists

BASES = [A,B,C]
CONTRASTS = [1,2,3]
ALLOUTPUTS = [outs1,outs2]

I want to zip together bases and contrasts, but expand fully all options from output dir

Desired output would be something like

outs1/A-1_comparison.bed
outs1/B-2_comparison.bed
outs1/C-3_comparison.bed
outs2/A-1_comparison.bed
outs2/B-2_comparison.bed
outs2/C-3_comparison.bed

Currently this rule

ruleAll:
   input:
   expand(os.path.join("{outputdir}","{bse}-{contrast}_comparison.bed"),zip, bse = BASES,contrast = CONTRASTS,outputdir = ALLOUTPUTS)

produces

outs1/A-1_comparison.bed
outs1/B-2_comparison.bed
outs1/C-3_comparison.bed

So it is possible to generate a partial zipping?


Solution

  • It's possible, but convoluted, much easier approach is to use python to explicitly define the list of interest:

    # let's assume these are in correct python syntax
    #BASES = [A,B,C]
    #CONTRASTS = [1,2,3]
    #ALLOUTPUTS = [outs1,outs2]
    FILES_OF_INTEREST = []
    
    
    for bse, contrast in zip(BASES, CONTRASTS):
       for outputdir in ALLOUTPUTS:
           file = os.path.join("{outputdir}","{bse}-{contrast}_comparison.bed")
           FILES_OF_INTEREST.append(file)
    
    ruleAll:
       input: FILES_OF_INTEREST