Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that onstart is recommended to be used #34

Open
nh13 opened this issue May 7, 2018 · 0 comments
Open

Document that onstart is recommended to be used #34

nh13 opened this issue May 7, 2018 · 0 comments

Comments

@nh13
Copy link
Owner

nh13 commented May 7, 2018

If there is any code prior to running the rules that creates directories, they may not have the correct paths. This is because snakeparse needs to "source" the snakefile prior to actually running it, and doing so without the parsed pipeline arguments.

For example:

from snakeparse.parser import argparser
from pathlib import Path

def snakeparser(**kwargs):
    p = argparser(**kwargs)
    p.parser.add_argument('-o', '--output-dir',        help='The output directory.', default=Path('.'), type=Path)
    return p

args = snakeparser().parse_config(config=config)

args.output_dir.mkdir(parents=True, exist_ok=True)

rule all:
   str(args.output_dir / "dummy.txt")

rule dummy:
   output: str(args.output_dir / "dummy.txt"
   shell: """echo Hi > {output}"""

This should be instead:

from snakeparse.parser import argparser
from pathlib import Path

def snakeparser(**kwargs):
    p = argparser(**kwargs)
    p.parser.add_argument('-o', '--output-dir',        help='The output directory.', default=Path('.'), type=Path)
    return p

args = snakeparser().parse_config(config=config)

onstart:
   args.output_dir.mkdir(parents=True, exist_ok=True)

rule all:
   str(args.output_dir / "dummy.txt")

rule dummy:
   output: str(args.output_dir / "dummy.txt"
   shell: """echo Hi > {output}"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant