-
Notifications
You must be signed in to change notification settings - Fork 4
/
create-dvc-yaml.py
executable file
·70 lines (58 loc) · 1.86 KB
/
create-dvc-yaml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import yaml
import pathlib
# yaml makes me cry
# https://github.com/yaml/pyyaml/issues/98#issuecomment-436814271
# This was causing a warning of NA coercion in R because some kegg pathways were specified as "03602,034,0230"
# and were not being quoted properly by this pkg
from yaml import Dumper
def string_representer(dumper, value):
if value.startswith("0"):
return dumper.represent_scalar(TAG_STR, value, style="'")
return dumper.represent_scalar(TAG_STR, value)
TAG_STR = "tag:yaml.org,2002:str"
Dumper.add_representer(str, string_representer)
stages = dict()
for filename in (
"dvc-download.yaml",
"dvc-rnaseq.yaml",
"dvc-srna.yaml",
"dvc-proteomics.yaml",
"dvc-integration.yaml",
"dvc-wgcna.yaml",
"dvc-mofa.yaml",
"dvc-dtu.yaml",
"dvc-das.yaml",
"dvc-phosphoproteomics.yaml",
):
with pathlib.Path("dvc", filename).open() as fh:
dvc_spec = yaml.safe_load(fh)
if dvc_spec is None:
continue
cur_stage = dvc_spec.get("stages", None)
if cur_stage is None:
continue
stages.update(cur_stage)
with open("dvc.yaml", "w") as fh:
fh.write("# Autogenerated file with ./create-dvc-yaml.py. DO NOT EDIT\n")
yaml.dump({"stages": stages}, fh)
params = dict()
for filename in (
"params-rnaseq.yaml",
"params-srna.yaml",
"params-proteomics.yaml",
"params-integration.yaml",
"params-wgcna.yaml",
"params-mofa.yaml",
"params-dtu.yaml",
"params-das.yaml",
"params-phosphoproteomics.yaml",
):
with pathlib.Path("params", filename).open() as fh:
params_spec = yaml.safe_load(fh)
if params_spec is None:
continue
params.update(params_spec)
with open("params.yaml", "w") as fh:
fh.write("# Autogenerated file with ./create-dvc-yaml.py. DO NOT EDIT\n")
yaml.dump(params, fh)