Skip to content

Commit e45863a

Browse files
committed
replace output directory variable with pathvars
1 parent 76b2957 commit e45863a

20 files changed

Lines changed: 159 additions & 169 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Analysis files
55
/data/
6-
/output/
6+
/results/
77

88
# MAC
99
.DS_Store

.test/Snakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ min_version("7.19")
1010
# Workflow version
1111
__version__ = "test"
1212

13+
pathvars:
14+
dataset = config["OUTPUT_NAME"]
15+
1316
# Rules
1417
include: "../workflow/core.smk"
1518
include: "../workflow/rules/demix.smk"
@@ -19,4 +22,4 @@ include: "../workflow/rules/report.smk"
1922

2023
rule all:
2124
input:
22-
OUTDIR/f"{OUTPUT_NAME}.report.html"
25+
"<results>/<dataset>/report.html"

.test/targets.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ SAMPLES:
1010
fasta: ".test/data/fasta/sample3.fasta"
1111
METADATA:
1212
".test/data/metadata.csv"
13-
OUTPUT_DIRECTORY:
14-
".test/output"
1513
CONTEXT_FASTA:
1614
".test/data/context.fasta"
1715
OUTPUT_NAME:

build_targets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def find_file_with_extension(directory: Path, prefix: str, extensions: List[str]
9191
else:
9292
sys.exit(f"ERROR: metadata file '{args.metadata_csv}' does not exist")
9393
targets["OUTPUT_NAME"] = args.output_name
94-
targets["OUTPUT_DIRECTORY"] = "output"
9594
targets["CONTEXT_FASTA"] = None
9695
targets["MAPPING_REFERENCES_FASTA"] = None
9796

config/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ The path to these input files is set in two configuration files in YAML format:
3737
[config.yaml](/config/config.yaml) (for general workflow settings) and
3838
[targets.yaml](/config/targets.yaml) (for specific dataset-related settings).
3939
The latter must be modified by the user to point the `SAMPLES` and `METADATA`
40-
parameters to your data. The `OUTPUT_DIRECTORY` parameter should point to your
41-
desired results directory.
40+
parameters to your data.
4241

4342
The script [`build_targets.py`](/build_targets.py) simplifies the process of creating
4443
the targets configuration file. To run this script, you need to have PyYAML installed. It
@@ -62,8 +61,6 @@ SAMPLES:
6261
...
6362
METADATA:
6463
"path/to/metadata.csv"
65-
OUTPUT_DIRECTORY:
66-
"output"
6764
CONTEXT_FASTA:
6865
null
6966
MAPPING_REFERENCES_FASTA:

config/targets.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ METADATA:
3939
"data/metadata.csv"
4040
OUTPUT_NAME:
4141
"case_study"
42-
OUTPUT_DIRECTORY:
43-
"output"
4442
CONTEXT_FASTA:
45-
null
43+
data/context.fasta
4644
MAPPING_REFERENCES_FASTA:
4745
null

workflow/Snakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ containerized: "docker://ahmig/vipera:v" + __version__
1414
configfile: "config/config.yaml"
1515
configfile: "config/targets.yaml"
1616

17+
pathvars:
18+
dataset = config["OUTPUT_NAME"]
19+
1720
include: "core.smk"
1821
include: "rules/context.smk"
1922
include: "rules/demix.smk"
@@ -22,4 +25,4 @@ include: "rules/report.smk"
2225

2326
rule all:
2427
input:
25-
OUTDIR/f"{OUTPUT_NAME}.report.html"
28+
"<results>/<dataset>/report.html"

workflow/core.smk

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ BASE_PATH = Path(workflow.basedir).parent.resolve()
22

33
include: "rules/common.smk"
44

5-
# Outputs
6-
OUTPUT_NAME = config["OUTPUT_NAME"]
7-
OUTDIR = Path(config["OUTPUT_DIRECTORY"])
8-
95
# Logging
10-
LOGDIR = OUTDIR / "logs"
6+
LOGDIR = Path("<results>/<logs>")
117

128
# Report
13-
REPORT_DIR_PLOTS = Path(OUTDIR/"report/plots")
14-
REPORT_DIR_TABLES = Path(OUTDIR/"report/tables")
9+
REPORT_DIR_PLOTS = Path("<results>/<dataset>/report/plots")
10+
REPORT_DIR_TABLES = Path("<results>/<dataset>/report/tables")
1511

1612
include: "rules/fetch.smk"
1713
include: "rules/fasta.smk"

workflow/rules/asr.smk

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ rule reconstruct_ancestral_sequence:
44
params:
55
seed = 7291,
66
seqtype = "DNA",
7-
name = OUTPUT_NAME,
87
outgroup = config["ALIGNMENT_REFERENCE"],
98
model = config["TREE_MODEL"]
109
input:
11-
fasta = OUTDIR/"nextalign"/f"{OUTPUT_NAME}.aligned.masked.fasta"
10+
fasta = "<results>/<dataset>/aligned.masked.fasta"
1211
output:
13-
folder = directory(OUTDIR/"tree"),
14-
state_file = OUTDIR/"tree"/f"{OUTPUT_NAME}.state"
12+
folder = directory("<results>/<dataset>/tree"),
13+
state_file = "<results>/<dataset>/tree/asr.state"
1514
log:
1615
LOGDIR / "reconstruct_ancestral_sequence" / "log.txt"
1716
shell:
1817
"mkdir -p {output.folder} && "
1918
"iqtree2 -seed {params.seed} "
20-
"-asr "
21-
"-o {params.outgroup} -T AUTO --threads-max {threads} -s {input.fasta} "
22-
"--seqtype {params.seqtype} -m {params.model} --prefix {output.folder}/{params.name} >{log} 2>&1"
19+
"-asr "
20+
"-o {params.outgroup} -T AUTO --threads-max {threads} -s {input.fasta} "
21+
"--seqtype {params.seqtype} -m {params.model} --prefix {output.folder}/asr >{log} 2>&1"
2322

2423

2524
rule ancestor_fasta:
@@ -30,9 +29,9 @@ rule ancestor_fasta:
3029
indeterminate_char = "N",
3130
name = "case_ancestor",
3231
input:
33-
state_file = OUTDIR/"tree"/f"{OUTPUT_NAME}.state"
32+
state_file = "<results>/<dataset>/tree/asr.state"
3433
output:
35-
fasta = report(OUTDIR/f"{OUTPUT_NAME}.ancestor.fasta")
34+
fasta = report("<results>/<dataset>/ancestor.fasta")
3635
log:
3736
LOGDIR / "ancestor_fasta" / "log.txt"
3837
script:

workflow/rules/common.smk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_repo_version(base_dir: str, default: str, warn=False) -> str:
4949
def select_context_fasta():
5050
"""Set context to be fetched automatically if CONTEXT_FASTA=null"""
5151
if "CONTEXT_FASTA" not in config.keys() or config["CONTEXT_FASTA"] is None:
52-
return OUTDIR/"context"/"sequences.fasta"
52+
return "<results>/<dataset>/context/sequences.fasta"
5353
if not Path(config["GISAID"]["CREDENTIALS"]).is_file():
5454
raise FileNotFoundError(f"Tried to download a context dataset, but no GISAID credentials were found at '{config['GISAID']['CREDENTIALS']}' (see README.md).")
5555
elif Path(config["CONTEXT_FASTA"]).is_file():
@@ -61,7 +61,7 @@ def select_context_fasta():
6161
def select_mapping_references_fasta():
6262
"""Set mapping references to be fetched automatically if MAPPING_REFERENCES_FASTA=null"""
6363
if "MAPPING_REFERENCES_FASTA" not in config.keys() or config["MAPPING_REFERENCES_FASTA"] is None:
64-
return OUTDIR/"mapping_references.fasta"
64+
return "<results>/<dataset>/mapping_references.fasta"
6565
elif Path(config["MAPPING_REFERENCES_FASTA"]).is_file():
6666
return config["MAPPING_REFERENCES_FASTA"]
6767
else:
@@ -74,7 +74,7 @@ def is_url(string: str) -> bool:
7474

7575
def select_problematic_vcf():
7676
if is_url(config["PROBLEMATIC_VCF"]):
77-
return OUTDIR/"problematic_sites.vcf"
77+
return "<results>/<dataset>/problematic_sites.vcf"
7878
elif Path(config["PROBLEMATIC_VCF"]).is_file():
7979
return config["PROBLEMATIC_VCF"]
8080
else:

0 commit comments

Comments
 (0)