Commit 82e52112 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Added default configuration for modules and rewrote the profiles collection

parent e3fece82
......@@ -42,20 +42,17 @@ def generate_execution(config, args):
execution['fasta'] = os.path.abspath(args.fasta)
execution['output'] = os.path.abspath(args.output)
execution['directory'] = 'tmp' # TODO replace by random tmp directory or make it configurable (cli option)
modules = generate_execution_modules_for_profile(config, args.profile)
execution['modules'] = modules
execution['modules'] = generate_execution_modules_for_profile(config, args.profile)
return execution
def generate_execution_modules_for_profile(config, profile):
# find profile by name
p = [x for x in config['profiles'] if x['name'] == profile][0]
# find all modules for profile from modules config section
m = [x for x in config['modules'] if x['name'] in p['modules']]
modules = copy.deepcopy(m)
modules = copy.deepcopy(p['modules'])
# generate unique ids for each module
for module in modules:
module['id'] = module['name']
module['params'] = generate_params_string(p['modules'][module['name']])
module['params'] = generate_params_string(module['parameters'])
return modules
def generate_params_string(options):
......
import os
import yaml
import copy
def get_install_location():
"""Finds the location directory of the tool"""
......@@ -40,16 +41,45 @@ def create_app_config():
return config
def load_modules():
modules = []
modules = {}
for manifest in get_module_manifests():
with (open(manifest)) as f:
modules.append(yaml.load(f))
module = yaml.load(f)
modules[module['name']] = module
if 'parameters' not in module:
module['parameters'] = {}
return modules
def normalize_profiles(profiles):
"""take care that all keys of the profile map exist"""
for profile in profiles:
if 'modules' not in profile:
profile['modules'] = []
for module in profile['modules']:
if profile['modules'][module] is None:
profile['modules'][module] = {}
def merge_modules_in_profiles(config):
"""Merge the module configuration and the profile configuration. Profile has precedence over module."""
profiles = config['profiles']
modules = config['modules']
for profile in profiles:
resolved_modules = []
for module_name in profile['modules']:
profile_module_config = profile['modules'][module_name]
resolved_module = modules[module_name]
copied_module = copy.deepcopy(resolved_module)
resolved_modules.append(copied_module)
for c in profile_module_config:
copied_module[c] = profile_module_config[c]
profile['modules'] = resolved_modules
def load_config():
config = load_config_file()
config['modules'] = load_modules()
config['app'] = create_app_config()
normalize_profiles(config['profiles'])
merge_modules_in_profiles(config)
return config
if __name__ == "__main__":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment