def __init__(self, rules: Union[str, dict], logger=app_logger): if isinstance(rules, dict): pass elif isinstance(rules, str): rules = get_json(rules) else: raise TypeError self.logger = logger self.raw_rules = rules self.sources = self.raw_rules["SOURCES"] self.date = self.raw_rules.get("_DATE", 20200214) self.authors = self.raw_rules.get("_AUTHORS", ["*****@*****.**"]) mods = self.raw_rules.get("MODS", {}) if mods: self.supported_mods = list(mods.keys()) else: self.supported_mods = [] self.supported_residues = list(self.raw_rules["RESIDUES"].keys()) self.supported_classes = list(self.raw_rules["LIPID_CLASSES"].keys()) self.supported_keys = (self.supported_mods + self.supported_residues + self.supported_classes) self.separators = self.raw_rules["SEPARATORS"] self.rules = {} self.is_structure_valid = self.__check__() if self.is_structure_valid: pass else: raise ValueError( "Cannot find valid sections for key [SOURCE, RESIDUES, LIPID_CLASSES]" ) self.rules = self.build() self.is_validated = self.validate()
def __init__(self, rules: Union[str, dict]): if isinstance(rules, dict): pass elif isinstance(rules, str): rules = get_json(rules) else: raise TypeError self.raw_rules = rules self.date = self.raw_rules.get("_DATE", 20200214) self.authors = self.raw_rules.get("_AUTHORS", ["*****@*****.**"]) self.nomenclature = self.raw_rules.get("NOMENCLATURE", "LipidLynxX") self.supported_lmsd_classes = list( self.raw_rules["LMSD_CLASSES"].keys()) self.separators = self.raw_rules["SEPARATORS"] self.mods = self.raw_rules.get("MODS", {}) self.residues = self.raw_rules.get("RESIDUES", {}) self.rules = self.build() self.is_structure_valid = self.__check__()
def __load_raw__(self) -> dict: raw_cv_info = {} raw_cv_dct = get_json(self.cv_file) for raw_cv in raw_cv_dct: order = raw_cv.get("order", None) cv = raw_cv.get("cv", None) level = raw_cv.get("level", 0) elements_dct = raw_cv.get("elements", {}) alias_lst = raw_cv.get("alias", []) if cv: if cv not in alias_lst: alias_lst.append(cv) alias_lst = list(set(alias_lst)) raw_cv_info[cv] = { "ORDER": order, "ALIAS": alias_lst, "LEVEL": level, "ELEMENTS": elements_dct, } return raw_cv_info
def __load__(self) -> dict: cv_info = {} raw_cv_info = get_json(self.cv_file) for raw_cv in raw_cv_info: order = raw_cv.get("order", None) cv = raw_cv.get("cv", None) level = raw_cv.get("level", 0) elements_dct = raw_cv.get("elements", {}) alias_lst = raw_cv.get("alias", []) if cv: if cv not in alias_lst: alias_lst.append(cv) alias_lst = list(set(alias_lst)) for alias in alias_lst: cv_info[alias] = { "MATCH": re.compile("^" + alias + "$"), "ORDER": order, "CV": cv, "LEVEL": level, "ELEMENTS": elements_dct, } return cv_info
def __load_raw__(self) -> dict: if not self._raw_cv: return get_json(self.alias_file) else: return self._raw_cv