# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbdev_nbs/settings.ipynb.

# %% auto 0
__all__ = ['global_settings', 'model_const', 'update_settings', 'update_modifications']

# %% ../nbdev_nbs/settings.ipynb 2
import os
import collections

from alphabase.yaml_utils import load_yaml
from alphabase.constants.modification import (
    load_mod_df, keep_modloss_by_importance
)

from .constants._const import CONST_FOLDER

# %% ../nbdev_nbs/settings.ipynb 3
global_settings = load_yaml(
    os.path.join(CONST_FOLDER, 'default_settings.yaml')
)

global_settings['PEPTDEEP_HOME'] = os.path.expanduser(
    global_settings['PEPTDEEP_HOME']
)

for key, val in list(global_settings['model_mgr'][
    'instrument_group'
].items()):
    global_settings['model_mgr'][
        'instrument_group'
    ][key.upper()] = val

model_const = load_yaml(
    os.path.join(CONST_FOLDER, 'model_const.yaml')
)

def update_settings(dict_, new_dict):
    for k, v in new_dict.items():
        if isinstance(v, collections.abc.Mapping):
            dict_[k] = update_settings(dict_.get(k, {}), v)
        else:
            dict_[k] = v
    return dict_

def update_modifications(tsv:str="", 
    modloss_importance_level:bool=global_settings[
        'common']['modloss_importance_level'
    ]
):
    if os.path.isfile(tsv):
        load_mod_df(tsv, modloss_importance_level=modloss_importance_level)
        
        from peptdeep.model.featurize import get_all_mod_features

        get_all_mod_features()
    else:
        keep_modloss_by_importance(modloss_importance_level)

update_modifications()
