def remove_temp_file(): removed_files = clean_temp_folder(default_temp_folder, default_temp_max_days, default_temp_max_files) if removed_files: app_logger.info( f"Remove temporary output files older than {default_temp_max_days} days..." ) for removed_file in removed_files: app_logger.info(f"File removed: {removed_file}") else: app_logger.debug(f"No outdated temporary files to be removed.")
def test_output_rule(test_file): app_logger.debug("SETUP TESTS...") app_logger.info(test_file) in_file = None if test_file: in_file = get_abs_path(test_file) if not in_file: in_file = get_abs_path( r"lynx/configurations/rules/output/LipidLynxX.json") app_logger.info(f"Test file {in_file}") rule = OutputRules(test_file) app_logger.debug(f"Got Output infile {in_file}") app_logger.debug(f"test Output rule {rule.nomenclature}") if rule.is_structure_valid is False: raise Exception(f"FAILED: test Rule {rule.nomenclature}") else: app_logger.info(f"PASSED: test Rule {rule.nomenclature}") app_logger.info( f"Supported LMSD classes: {rule.supported_lmsd_classes}") app_logger.info(f"test PASSED")
def test_input_rule(test_file): app_logger.debug("SETUP TESTS...") app_logger.info(test_file) in_file = None if test_file: in_file = get_abs_path(test_file) if not in_file: in_file = get_abs_path( r"lynx/configurations/rules/input/LipidLynxX.json") app_logger.info(f"Test file {in_file}") rule = InputRules(test_file) app_logger.debug(f"Got infile {in_file}") app_logger.debug(f"test input rule {rule.sources}") if rule.is_validated is False: raise Exception(f"FAILED: test input rule {rule.sources}") else: app_logger.info(f"PASSED: test input rule {rule.sources}") app_logger.info(f"test PASSED")
# "SPBP 18:0;O", # "SPBP 18:0;O3", # "Cer 18:1;3O/20:4", # "CoA(20:3(11Z,14Z,17Z))", # "CoA 18:2;O", # "FACoA 18:0", # "Cer 24:2", # "LMGP01010594", # "lid", # "PLPC", "SM d18:1/24:0", "DHA", ] lv = "M1" # test_out_rule = "COMP_DB" test_out_rule = "LipidLynxX" # test_out_rule = "BracketsShorthand" lynx_converter = Converter(style=test_out_rule, logger=app_logger) for t_in in t_in_lst: t1_out = lynx_converter.convert(t_in, level="M1") app_logger.info(f"Input: {t_in} -> Best Output: {t1_out}") t2_out = lynx_converter.convert(t_in_lst) app_logger.info(f"Input: {t_in_lst} -> Best Output: {t2_out}") app_logger.info(t2_out) # # t3_out = lynx_converter.convert({"1": t_in_lst}) # logger.info(f"Input: {t_in_lst} -> Best Output: {t3_out}") # logger.info("fin")
"MOD_ELEMENTS": { "H": -2 }, "MOD_MASS_SHIFT": 0, }, "5.01_OH": { "MOD_CV": "OH", "MOD_LEVEL": 5, "MOD_COUNT": 1, "MOD_SITE": ["12"], "MOD_SITE_INFO": ["R"], "MOD_ORDER": 5.01, "MOD_ELEMENTS": { "O": 1 }, "MOD_MASS_SHIFT": 16, }, }, } usr_mod_obj = Modifications(usr_mod_info) app_logger.debug(usr_mod_obj) mod_json = usr_mod_obj.to_json() usr_sum_mods_obj = merge_mods([usr_mod_obj, usr_mod_obj]) app_logger.debug(usr_sum_mods_obj) sum_mod_json = usr_sum_mods_obj.to_json() app_logger.info("FINISHED")
# "HETE", # "TG(16:0/18:2/18:2[2xDB,1xOH])", # "PC 16:0/18:2[9,12]", # "DG 16:2[9,12]_O-18:2_0:0", # "14,15-HxB3 (13R)", # "C22:5 CE", # "15-Keto-PGF2α", # "PGF2α", # "8-iso PGF2a III", # "palmitoleic acid", "FA 16:1(9Z)" ] lynx_gen = Encoder(style="ShorthandNotation") for t_in in t_in_lst: t1_out = lynx_gen.convert(t_in) app_logger.info(f"Input: {t_in} -> Best Output: {t1_out}") # t_lv = "B0" # t2_out = lynx_gen.export_level( # t_in, level=t_lv, import_rules=default_input_rules # ) # self.logger.info(f"Input: {t_in} -> Output @ Lv {t_lv}: {t2_out}") # t_lv_lst = ["B0"] # t3_out = lynx_gen.export_levels( # t_in, levels=t_lv_lst, import_rules=default_input_rules # ) # self.logger.info(f"Input: {t_in} -> Output @ Lv {t_lv_lst}: {t3_out}") t4_out = lynx_gen.export_all_levels(t_in) app_logger.info(f"Input: {t_in} -> Output @ all levels: {t4_out}") app_logger.info("fin")
if not extracted_info_dct: self.logger.error(f"Failed to decode Lipid: {lipid_name}") obs_alias_lst = list(set(obs_alias_lst)) if obs_alias_lst: self.logger.debug(f"Using alias: {lipid_name} -> {obs_alias_lst}") return extracted_info_dct if __name__ == "__main__": # LIPID MAPS # t_in = "GM3(d18:1/18:2(9Z,12Z))" # t_in = "TG (P-18:1/18:2(9Z,12Z)/20:4(5Z,8Z,11Z,14Z)(7R-OH,12S-OH))" # t_in = "TG (P-18:1/18:2(9Z,12Z)/20:4(5,8,11,14)(7R-OH,12S-OH))" # t_in = "TG (P-18:1/18:2(9Z,12Z)/20:4(5,8,11,14)(7R-OH,12S-OH))" # t_in = "TG (P-18:1/18:2(9Z,12Z)/5S,15R-DiHETE)" # MS-DIAL # t_in = "TG(16:0/18:2/20:4<OH>)" # t_in = "TG(16:0/18:2/HETE)" # RefMet t_in = "PC(36:2e)" extractor = Decoder(rules=default_input_rules) t_out = extractor.extract(t_in) app_logger.info(t_out) app_logger.info("FIN")
# r"P-20:4<{5,9,12,15},2OH{8,11},Ke{14}>", # r"P-20:4<{5Z,9E,12E,15E},2OH{8,11},Ke{14}>", # r"P-20:4<2OH{8R,11S},Ke{14}>", # r"P-20:4<{5,9,12,15},2OH{8R,11S},Ke{14}>", # r"P-20:4<{5Z,9E,12E,15E},2OH{8R,11S},Ke{14}>", ] pl_d_lst = [] pl_s_lst = [] for hg in hg_lst: for sn1 in sn1_lst: for sn2 in sn2_lst: if "-" not in sn1 and "-" not in sn2: pl_d_lst.append(f"{hg}({sn1}_{sn2})") pl_s_lst.append(f"{hg}({sn1}/{sn2})") # lipid_lst = sn1_lst + sn2_lst + pl_s_lst + pl_d_lst lipid_lst = sn1_lst counter = 0 for pl in lipid_lst: counter += 1 app_logger.info(f"Test Lipid #{counter} : {pl}") pl_obj = Lipid(lipid_code=pl) app_logger.info(f"Export JSON \n {pl_obj.to_json()}") app_logger.info( "".join([f"\n {s}: {pl_obj.linked_ids[s]}" for s in pl_obj.linked_ids]) ) app_logger.info("FINISHED")