Search code examples
snakemake

Accessing the --default-remote-prefix within the Snakefile


When I run snakemake on the google life sciences executor, I run something like:

snakemake  --google-lifesciences --default-remote-prefix my_bucket_name  --preemption-default 10 --use-conda

Now, my_bucket_name is going to get added to all of the input and output paths.

BUT for reasons I need to recreate the full path within the Snakefile code and therefore I want to be able to access whatever is passed to --default-remote-prefix within the code

Is there a way to do this?


Solution

  • I want to be able to access whatever is passed to --default-remote-prefix within the code

    You can use the workflow object like:

    print(workflow.default_remote_prefix) # Will print my_bucket_name in your example
    
    rule all:
        input: ...
    

    I'm not 100% sure if the workflow object is supposed to be used by the user or if it's private to snakemake and if so it could be changed in the future without warning. But I think it's ok, I use workflow.basedir all the time to get the directory where the Snakefile sits.

    Alternatively you could parse the sys.argv list but I think that this is more hacky.


    Another option:

    bucket_name=foo
    snakemake --default-remote-prefix $bucket_name --config bucket_name=$bucket_name ...
    

    then use config["bucket_name"] within the code to get the value foo. But I still prefer the workflow solution.