1

So far I used snakemake to generate individual plots with snakemake. This has worked great! Now though, I want to create a rule that creates a combined plot across the topics, without explicitly putting the name in the plot. See the combined_plot rule below.

topics=["soccer", "football"] params=[1, 2, 3, 4] rule all: input: expand("plot_p={param}_{topic}.png", topic=topics, param=params), expand("combined_p={param}_plot.png", param=params), rule plot: input: "data_p={param}_{topic}.csv" output: "plot_p={param}_{topic}.png" shell: "plot.py --input={input} --output={output}" rule combined_plot: input: # all data_p={param}_{topic}.csv files output: "combined_p={param}_plot.png" shell: "plot2.py " + # one "--input=" and one "--output" for each csv file 

Is there a simple way to do this with snakemake?

2 Answers 2

1

If I understand correctly, the code below should be more straightforward as it replaces the lambda and the glob with the expand function. It will execute the two commands:

plot2.py --input=data_p=1_soccer.csv --input=data_p=1_football.csv --output combined_p=1_plot.png plot2.py --input=data_p=2_soccer.csv --input=data_p=2_football.csv --output combined_p=2_plot.png 

topics=["soccer", "football"] params=[1, 2] rule all: input: expand("combined_p={param}_plot.png", param=params), rule combined_plot: input: csv= expand("data_p={{param}}_{topic}.csv", topic= topics) output: "combined_p={param}_plot.png", run: inputs= ['--input=' + x for x in input.csv] shell("plot2.py {inputs} --output {output}") 
Sign up to request clarification or add additional context in comments.

Comments

0

I got a working version, by using a function called 'wcs' as input (see here) and I used run instead of shell. In the run section I could first define a variable before executing the result with shell(...).

Instead of referring to the files with glob I could also have directly used the topics in the lambda function.

If anyone with more experience sees this, please tell me if this is the "right" way to do it.

from glob import glob topics=["soccer", "football"] params=[1, 2] rule all: input: expand("plot_p={param}_{topic}.png", topic=topics, param=params), expand("combined_p={param}_plot.png", param=params), rule plot: input: "data_p={param}_{topic}.csv" output: "plot_p={param}_{topic}.png" shell: "echo plot.py {input} {output}" rule combined_plot: input: lambda wcs: glob("data_p={param}_*.csv".format(**wcs)) output: "combined_p={param}_plot.png" run: inputs=" ".join(["--input " + inp for inp in input]) shell("echo plot2.py {inputs}") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.