2
$\begingroup$

I want to pass a series of files (e.g., a, b) to a program prog like: prog a,b.

Is there a way to do this in Snakemake?

My attempt is:

rule run_prog:
  input: "a", "b"
  output: "output"
  run: "prog {input}"

But the actual command Snakemake generated is prog a b instead of prog a,b.

Any solution to pass a comma concatenated file names to Snakemake?

$\endgroup$
2
  • $\begingroup$ run: "prog {input[0]},{input[1]}" ? $\endgroup$ Apr 20, 2020 at 12:51
  • $\begingroup$ @Chris_Rands that works, is there a general solution, as there can be ~20 input files. Thanks! $\endgroup$
    – zhanxw
    Apr 20, 2020 at 15:22

1 Answer 1

1
$\begingroup$

You can use join to convert the list of input file into a string. I think this would work as expected.:

rule run_prog:
    input: "a", "b"
    output: "output"
    run: f"prog {','.join(input)}"
$\endgroup$
2
  • $\begingroup$ This works great. It works for f"prog {','.join(input.variable)}" if I define variable under input: section. Can you explain why have to use input[:] instead of input? $\endgroup$
    – zhanxw
    Apr 22, 2020 at 3:19
  • 1
    $\begingroup$ Right, using input by itself is the same ! I edited my answer. $\endgroup$
    – cmdoret
    Apr 22, 2020 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.