-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnakemake.py
45 lines (41 loc) · 1.6 KB
/
snakemake.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
"""
Some helper functions for snakemake.
"""
import subprocess
def get_git_revision_hash():
git_hash = subprocess.check_output(
['git', 'rev-parse', 'HEAD']
).decode('ascii').strip()
return git_hash
def nested_dict_update(default_dict, specific_dict):
"""
Updates the values of default_dict by the values in specific_dict
recursively.
"""
for key in specific_dict:
# Fully replace neuron_params_X or neuron_param_dist_X dictionaries
if isinstance(key, str) and key.startswith('neuron_param'):
print('Specified {0} dict to {1}'.format(
key, specific_dict[key]
))
default_dict[key] = specific_dict[key]
elif isinstance(specific_dict[key], dict):
nested_dict_update(default_dict[key], specific_dict[key])
else:
if key in default_dict.keys():
if isinstance(specific_dict[key], type(default_dict[key])) or default_dict[key] is None:
default_dict[key] = specific_dict[key]
else:
raise TypeError(
'Type of specific_dict[{0}]={1} and '
'default_dict[{0}]={2} dont match.'.format(
key,
specific_dict[key],
default_dict[key]
)
)
else:
print('Adding entry default_dict[{0}]={1}'.format(
key, specific_dict[key]
))
default_dict[key] = specific_dict[key]