-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.py
executable file
·65 lines (53 loc) · 1.92 KB
/
config.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
#!/usr/bin/env python
import os
from ruamel.yaml import YAML
def parse_yaml(yaml_file):
yaml = YAML()
with open(yaml_file, "r") as f:
return yaml.load(f)
def update_config(yaml_file_old, yaml_file_new, yaml_content, remove=True):
yaml = YAML()
yaml.default_flow_style = False
if remove:
os.remove(yaml_file_old)
with open(yaml_file_new, "w") as f:
yaml.dump(yaml_content, f)
class metaconfig:
"""
config project directory
"""
sub_dirs = ["assay", "assay/cluster_logs", "results", "scripts", "sources", "study"]
def __init__(self, work_dir):
self.work_dir = os.path.realpath(work_dir)
self.config_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "config.yaml"
)
self.cluster_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "cluster.yaml"
)
self.snake_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "Snakefile"
)
self.new_config_file = os.path.join(self.work_dir, "config.yaml")
self.new_cluster_file = os.path.join(self.work_dir, "cluster.yaml")
def __str__(self):
message = "a metagenomics project has been created at {0}".format(self.work_dir)
return message
def create_dirs(self):
"""
create project directory
"""
if not os.path.exists(self.work_dir):
os.mkdir(self.work_dir)
for sub_dir in metaconfig.sub_dirs:
os.makedirs(os.path.join(self.work_dir, sub_dir), exist_ok=True)
def get_config(self):
"""
get default configuration
"""
config = parse_yaml(self.config_file)
cluster = parse_yaml(self.cluster_file)
config["snakefile"] = self.snake_file
config["configfile"] = self.new_config_file
config["clusterfile"] = self.new_cluster_file
return (config, cluster)