Hi all,
I'm writing a workflow that depends on user's input. For example, if the user choses analysis A, the scripts 1,2,3 will run while chosing B will run the scripts 2,5,7.
My idea is first to create a python script in which I import argparse
to provide the options needed. the script will then write the config file for snakemake. I think this way it is very clean, no interwine between different parts (I've seen other posts), and it is scalable.
The only part that I don't know how to implement is how to call snakemake from within this script? the user should not notice that these are two different steps.
my example is
def inputArgs():
parser = argparse.ArgumentParser()
parser.add_argumnt("--analysis", help = "enter the name of analysis", type = str, default = True)
return parser.parse_args()
if __name__ == '__main__':
# write args into file
config_file = open("config.yaml", "w")
args = inputArgs()
for a in args.__dict__:
config_file.write(a + ":" + str(args.__dict__[a]))
# call snakemake
???
Thanks for the help
Not sure what you're looking for when you mention "the user should not notice that these are two different steps." Are you saying you don't want your users to know what rules were invoked to generate the outputs?
Btw, you can do it natively within snakemake using
--config
. If you run the following withsnakemake -j1 --config analysis=A
, it'll trigger rulesscript1
andscript2
, whereasB
->script2
andscript5
.thanks for the answer, no that is not my intention! the user are presented with some options, these are generic and analysis-related, in the background these options will determin how the scripts will behave. The options are not related to snakemake directly, that is why the options provided by snakemake can't help me here. The idea is that the user calls for one script provides the options that are meaningful to him and that is it, rather than changing the config file everytime. This is for example very helpful if your input changes so you want to provide different path. Maybe I'm missing something, but these kind of parameters I typically write them in the config file; the option config in snakemake requires that you write the options as dictionary which contradict my intention