Skip to content

Instantly share code, notes, and snippets.

@pvandyken
Last active July 22, 2022 17:49
Show Gist options
  • Save pvandyken/8d0aca922ee181b514eb52361090a4ae to your computer and use it in GitHub Desktop.
Save pvandyken/8d0aca922ee181b514eb52361090a4ae to your computer and use it in GitHub Desktop.
Use an environment variable as the default resources tmpdir in a snakemake workflow
# For a local instance, use --default_resources 'tmpdir="$MYENV_VAR"'
# Everything should work properly
# For a cluster scheduling instance, use --default_resources 'tmpdir="$$MYENV_VAR"'
# The double dollar sign is needed for escaping.
# Note that you won't be able to use this tmpdir on localrules (only a concern in cluster mode)
# The `tmpdir` variable becomes available for use throughout the workflow
def eval_environ(s):
s = s.strip("'\"") if s else s
if s and len(s) > 1 and s[0] == "$":
if s[1] == "$":
return s[1:]
return os.environ.get(s[1:])
return s
tmpdir = eval_environ(workflow.default_resources._args.get("tmpdir"))
if tmpdir is not None:
workflow.default_resources.set_resource("tmpdir", tmpdir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment