def read_config_options(configuration_file, gvanno_dir, logger):
## read default options
gvanno_config_options = {}
gvanno_configuration_file_default = os.path.join(gvanno_dir,'data','gvanno_configuration_default.toml')
if not os.path.exists(gvanno_configuration_file_default):
err_msg = "Default gvanno configuration file " + str(gvanno_configuration_file_default) + " does not exist - exiting"
gvanno_error_message(err_msg,logger)
try:
gvanno_config_options = toml.load(gvanno_configuration_file_default)
except IndexError,TypeError:
err_msg = 'Configuration file ' + str(configuration_file) + ' is not formatted correctly'
gvanno_error_message(err_msg, logger)
## override with options set by the users
try:
toml_options = toml.load(configuration_file)
except IndexError,TypeError:
err_msg = 'Configuration file ' + str(configuration_file) + ' is not formatted correctly'
gvanno_error_message(err_msg, logger)
#float_tags = ['maf_onekg_eur','maf_onekg_amr','maf_onekg_afr','maf_onekg_sas','maf_onekg_eas','maf_onekg_global','maf_gnomad_nfe','maf_gnomad_amr','maf_gnomad_fin','maf_gnomad_oth','maf_gnomad_afr','maf_gnomad_sas','maf_gnomad_eas','maf_gnomad_global']
boolean_tags = ['vep_skip_intergenic']
integer_tags = ['n_vcfanno_proc','n_vep_forks']
for section in ['other']:
if toml_options.has_key(section):
# for t in float_tags:
# if toml_options[section].has_key(t):
# if not isinstance(toml_options[section][t],float) and not isinstance(toml_options[section][t],int):
# err_msg = 'Configuration value ' + str(toml_options[section][t]) + ' for ' + str(t) + ' cannot be parsed properly (expecting float)'
# gvanno_error_message(err_msg, logger)
# gvanno_config_options[section][t] = toml_options[section][t]
for t in boolean_tags:
if toml_options[section].has_key(t):
if not isinstance(toml_options[section][t],bool):
err_msg = 'Configuration value ' + str(toml_options[section][t]) + ' for ' + str(t) + ' cannot be parsed properly (expecting true/false)'
gvanno_error_message(err_msg, logger)
gvanno_config_options[section][t] = int(toml_options[section][t])
for t in integer_tags:
if toml_options[section].has_key(t):
if not isinstance(toml_options[section][t],int):
err_msg = 'Configuration value ' + str(toml_options[section][t]) + ' for ' + str(t) + ' cannot be parsed properly (expecting integer)'
gvanno_error_message(err_msg, logger)
gvanno_config_options[section][t] = toml_options[section][t]
# for t in float_tags:
# if t.startswith('maf_'):
# if gvanno_config_options['variant_filter'][t] < 0 or gvanno_config_options['variant_filter'][t] > 1:
# err_msg = "MAF value: " + str(t) + " must be within the [0,1] range, current value is " + str(gvanno_config_options['variant_filter'][t]) + ")"
# gvanno_error_message(err_msg,logger)
return gvanno_config_options
评论列表
文章目录