corems.encapsulation.output.parameter_to_json
1import json 2 3import toml 4from pathlib import Path 5 6from corems.encapsulation.output import parameter_to_dict 7from corems.encapsulation.output.parameter_to_dict import get_dict_data_lcms 8 9 10def dump_all_settings_json(filename="SettingsCoreMS.json", file_path=None): 11 """ 12 Write JSON file into current directory with all the default settings for the CoreMS package. 13 14 Parameters: 15 ---------- 16 filename : str, optional 17 The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. 18 file_path : str or Path, optional 19 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 20 """ 21 22 data_dict_all = parameter_to_dict.get_dict_all_default_data() 23 24 if not file_path: 25 file_path = Path.cwd() / filename 26 27 with open( 28 file_path, 29 "w", 30 encoding="utf8", 31 ) as outfile: 32 import re 33 34 # pretty print 35 output = json.dumps( 36 data_dict_all, sort_keys=False, indent=4, separators=(",", ": ") 37 ) 38 output = re.sub(r'",\s+', '", ', output) 39 40 outfile.write(output) 41 42 43def dump_ms_settings_json(filename="SettingsCoreMS.json", file_path=None): 44 """ 45 Write JSON file into current directory with all the mass spectrum default settings for the CoreMS package. 46 47 Parameters 48 ---------- 49 filename : str, optional 50 The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. 51 file_path : str or Path, optional 52 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 53 54 """ 55 data_dict = parameter_to_dict.get_dict_ms_default_data() 56 if not file_path: 57 file_path = Path.cwd() / filename 58 59 with open( 60 file_path, 61 "w", 62 encoding="utf8", 63 ) as outfile: 64 import re 65 66 # pretty print 67 output = json.dumps( 68 data_dict, sort_keys=False, indent=4, separators=(",", ": ") 69 ) 70 output = re.sub(r'",\s+', '", ', output) 71 72 outfile.write(output) 73 74 75def dump_gcms_settings_json(filename="SettingsCoreMS.json", file_path=None): 76 """ 77 Write JSON file into current directory containing the default GCMS settings data. 78 79 Parameters 80 ---------- 81 filename : str, optional 82 The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. 83 file_path : str or Path-like object, optional 84 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 85 """ 86 87 from pathlib import Path 88 import json 89 90 data_dict = parameter_to_dict.get_dict_gcms_default_data() 91 92 if not file_path: 93 file_path = Path.cwd() / filename 94 95 with open( 96 file_path, 97 "w", 98 encoding="utf8", 99 ) as outfile: 100 import re 101 102 # pretty print 103 output = json.dumps( 104 data_dict, sort_keys=False, indent=4, separators=(",", ": ") 105 ) 106 output = re.sub(r'",\s+', '", ', output) 107 108 outfile.write(output) 109 110 111def dump_all_settings_toml(filename="SettingsCoreMS.toml", file_path=None): 112 """ 113 Write TOML file into the specified file path or the current directory with all the default settings for the CoreMS package. 114 115 Parameters 116 ---------- 117 filename : str, optional 118 The name of the TOML file. Defaults to 'SettingsCoreMS.toml'. 119 file_path : str or Path, optional 120 The path where the TOML file will be saved. If not provided, the file will be saved in the current directory. 121 122 """ 123 from pathlib import Path 124 125 data_dict_all = parameter_to_dict.get_dict_all_default_data() 126 127 if not file_path: 128 file_path = Path.cwd() / filename 129 130 with open( 131 file_path, 132 "w", 133 encoding="utf8", 134 ) as outfile: 135 import re 136 137 output = toml.dumps(data_dict_all) 138 outfile.write(output) 139 140 141def dump_ms_settings_toml(filename="SettingsCoreMS.toml", file_path=None): 142 """ 143 Write TOML file into the current directory with all the mass spectrum default settings for the CoreMS package. 144 145 Parameters 146 ---------- 147 filename : str, optional 148 The name of the TOML file to be created. Default is 'SettingsCoreMS.toml'. 149 file_path : str or Path, optional 150 The path where the TOML file should be saved. If not provided, the file will be saved in the current working directory. 151 152 """ 153 data_dict = parameter_to_dict.get_dict_ms_default_data() 154 155 if not file_path: 156 file_path = Path.cwd() / filename 157 158 with open( 159 file_path, 160 "w", 161 encoding="utf8", 162 ) as outfile: 163 import re 164 165 # pretty print 166 output = toml.dumps(data_dict) 167 outfile.write(output) 168 169 170def dump_gcms_settings_toml(filename="SettingsCoreMS.toml", file_path=None): 171 """ 172 Write TOML file into current directory containing the default GCMS settings data. 173 174 Parameters 175 ---------- 176 filename : str, optional 177 The name of the TOML file. Defaults to 'SettingsCoreMS.toml'. 178 file_path : str or Path, optional 179 The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory. 180 181 """ 182 183 data_dict = parameter_to_dict.get_dict_gcms_default_data() 184 185 if not file_path: 186 file_path = Path.cwd() / filename 187 188 with open( 189 file_path, 190 "w", 191 encoding="utf8", 192 ) as outfile: 193 output = toml.dumps(data_dict) 194 outfile.write(output) 195 196 197def dump_lcms_settings_json( 198 filename="SettingsCoreMS.json", file_path=None, lcms_obj=None 199): 200 """ 201 Write JSON file into current directory with all the LCMS settings data for the CoreMS package. 202 203 Parameters 204 ---------- 205 filename : str, optional 206 The name of the JSON file. Defaults to 'SettingsCoreMS.json'. 207 file_path : str or Path, optional 208 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 209 lcms_obj : object, optional 210 The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings. 211 212 """ 213 214 if lcms_obj is None: 215 data_dict = parameter_to_dict.get_dict_lcms_default_data() 216 else: 217 data_dict = get_dict_data_lcms(lcms_obj) 218 219 if not file_path: 220 file_path = Path.cwd() / filename 221 222 with open( 223 file_path, 224 "w", 225 encoding="utf8", 226 ) as outfile: 227 outfile.write(json.dumps(data_dict, indent=4)) 228 229 230def dump_lcms_settings_toml( 231 filename="SettingsCoreMS.toml", file_path=None, lcms_obj=None 232): 233 """ 234 Write TOML file into current directory with all the LCMS settings data for the CoreMS package. 235 236 Parameters 237 ---------- 238 filename : str, optional 239 The name of the TOML file. Defaults to 'SettingsCoreMS.toml'. 240 file_path : str or Path, optional 241 The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory. 242 lcms_obj : object, optional 243 The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings. 244 245 """ 246 247 if lcms_obj is None: 248 data_dict = parameter_to_dict.get_dict_lcms_default_data() 249 else: 250 data_dict = get_dict_data_lcms(lcms_obj) 251 252 if not file_path: 253 file_path = Path.cwd() / filename 254 255 with open( 256 file_path, 257 "w", 258 encoding="utf8", 259 ) as outfile: 260 output = toml.dumps(data_dict) 261 outfile.write(output)
11def dump_all_settings_json(filename="SettingsCoreMS.json", file_path=None): 12 """ 13 Write JSON file into current directory with all the default settings for the CoreMS package. 14 15 Parameters: 16 ---------- 17 filename : str, optional 18 The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. 19 file_path : str or Path, optional 20 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 21 """ 22 23 data_dict_all = parameter_to_dict.get_dict_all_default_data() 24 25 if not file_path: 26 file_path = Path.cwd() / filename 27 28 with open( 29 file_path, 30 "w", 31 encoding="utf8", 32 ) as outfile: 33 import re 34 35 # pretty print 36 output = json.dumps( 37 data_dict_all, sort_keys=False, indent=4, separators=(",", ": ") 38 ) 39 output = re.sub(r'",\s+', '", ', output) 40 41 outfile.write(output)
Write JSON file into current directory with all the default settings for the CoreMS package.
Parameters:
filename : str, optional The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. file_path : str or Path, optional The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
44def dump_ms_settings_json(filename="SettingsCoreMS.json", file_path=None): 45 """ 46 Write JSON file into current directory with all the mass spectrum default settings for the CoreMS package. 47 48 Parameters 49 ---------- 50 filename : str, optional 51 The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. 52 file_path : str or Path, optional 53 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 54 55 """ 56 data_dict = parameter_to_dict.get_dict_ms_default_data() 57 if not file_path: 58 file_path = Path.cwd() / filename 59 60 with open( 61 file_path, 62 "w", 63 encoding="utf8", 64 ) as outfile: 65 import re 66 67 # pretty print 68 output = json.dumps( 69 data_dict, sort_keys=False, indent=4, separators=(",", ": ") 70 ) 71 output = re.sub(r'",\s+', '", ', output) 72 73 outfile.write(output)
Write JSON file into current directory with all the mass spectrum default settings for the CoreMS package.
Parameters
- filename (str, optional): The name of the JSON file to be created. Default is 'SettingsCoreMS.json'.
- file_path (str or Path, optional): The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
76def dump_gcms_settings_json(filename="SettingsCoreMS.json", file_path=None): 77 """ 78 Write JSON file into current directory containing the default GCMS settings data. 79 80 Parameters 81 ---------- 82 filename : str, optional 83 The name of the JSON file to be created. Default is 'SettingsCoreMS.json'. 84 file_path : str or Path-like object, optional 85 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 86 """ 87 88 from pathlib import Path 89 import json 90 91 data_dict = parameter_to_dict.get_dict_gcms_default_data() 92 93 if not file_path: 94 file_path = Path.cwd() / filename 95 96 with open( 97 file_path, 98 "w", 99 encoding="utf8", 100 ) as outfile: 101 import re 102 103 # pretty print 104 output = json.dumps( 105 data_dict, sort_keys=False, indent=4, separators=(",", ": ") 106 ) 107 output = re.sub(r'",\s+', '", ', output) 108 109 outfile.write(output)
Write JSON file into current directory containing the default GCMS settings data.
Parameters
- filename (str, optional): The name of the JSON file to be created. Default is 'SettingsCoreMS.json'.
- file_path (str or Path-like object, optional): The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
112def dump_all_settings_toml(filename="SettingsCoreMS.toml", file_path=None): 113 """ 114 Write TOML file into the specified file path or the current directory with all the default settings for the CoreMS package. 115 116 Parameters 117 ---------- 118 filename : str, optional 119 The name of the TOML file. Defaults to 'SettingsCoreMS.toml'. 120 file_path : str or Path, optional 121 The path where the TOML file will be saved. If not provided, the file will be saved in the current directory. 122 123 """ 124 from pathlib import Path 125 126 data_dict_all = parameter_to_dict.get_dict_all_default_data() 127 128 if not file_path: 129 file_path = Path.cwd() / filename 130 131 with open( 132 file_path, 133 "w", 134 encoding="utf8", 135 ) as outfile: 136 import re 137 138 output = toml.dumps(data_dict_all) 139 outfile.write(output)
Write TOML file into the specified file path or the current directory with all the default settings for the CoreMS package.
Parameters
- filename (str, optional): The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
- file_path (str or Path, optional): The path where the TOML file will be saved. If not provided, the file will be saved in the current directory.
142def dump_ms_settings_toml(filename="SettingsCoreMS.toml", file_path=None): 143 """ 144 Write TOML file into the current directory with all the mass spectrum default settings for the CoreMS package. 145 146 Parameters 147 ---------- 148 filename : str, optional 149 The name of the TOML file to be created. Default is 'SettingsCoreMS.toml'. 150 file_path : str or Path, optional 151 The path where the TOML file should be saved. If not provided, the file will be saved in the current working directory. 152 153 """ 154 data_dict = parameter_to_dict.get_dict_ms_default_data() 155 156 if not file_path: 157 file_path = Path.cwd() / filename 158 159 with open( 160 file_path, 161 "w", 162 encoding="utf8", 163 ) as outfile: 164 import re 165 166 # pretty print 167 output = toml.dumps(data_dict) 168 outfile.write(output)
Write TOML file into the current directory with all the mass spectrum default settings for the CoreMS package.
Parameters
- filename (str, optional): The name of the TOML file to be created. Default is 'SettingsCoreMS.toml'.
- file_path (str or Path, optional): The path where the TOML file should be saved. If not provided, the file will be saved in the current working directory.
171def dump_gcms_settings_toml(filename="SettingsCoreMS.toml", file_path=None): 172 """ 173 Write TOML file into current directory containing the default GCMS settings data. 174 175 Parameters 176 ---------- 177 filename : str, optional 178 The name of the TOML file. Defaults to 'SettingsCoreMS.toml'. 179 file_path : str or Path, optional 180 The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory. 181 182 """ 183 184 data_dict = parameter_to_dict.get_dict_gcms_default_data() 185 186 if not file_path: 187 file_path = Path.cwd() / filename 188 189 with open( 190 file_path, 191 "w", 192 encoding="utf8", 193 ) as outfile: 194 output = toml.dumps(data_dict) 195 outfile.write(output)
Write TOML file into current directory containing the default GCMS settings data.
Parameters
- filename (str, optional): The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
- file_path (str or Path, optional): The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory.
198def dump_lcms_settings_json( 199 filename="SettingsCoreMS.json", file_path=None, lcms_obj=None 200): 201 """ 202 Write JSON file into current directory with all the LCMS settings data for the CoreMS package. 203 204 Parameters 205 ---------- 206 filename : str, optional 207 The name of the JSON file. Defaults to 'SettingsCoreMS.json'. 208 file_path : str or Path, optional 209 The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory. 210 lcms_obj : object, optional 211 The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings. 212 213 """ 214 215 if lcms_obj is None: 216 data_dict = parameter_to_dict.get_dict_lcms_default_data() 217 else: 218 data_dict = get_dict_data_lcms(lcms_obj) 219 220 if not file_path: 221 file_path = Path.cwd() / filename 222 223 with open( 224 file_path, 225 "w", 226 encoding="utf8", 227 ) as outfile: 228 outfile.write(json.dumps(data_dict, indent=4))
Write JSON file into current directory with all the LCMS settings data for the CoreMS package.
Parameters
- filename (str, optional): The name of the JSON file. Defaults to 'SettingsCoreMS.json'.
- file_path (str or Path, optional): The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
- lcms_obj (object, optional): The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings.
231def dump_lcms_settings_toml( 232 filename="SettingsCoreMS.toml", file_path=None, lcms_obj=None 233): 234 """ 235 Write TOML file into current directory with all the LCMS settings data for the CoreMS package. 236 237 Parameters 238 ---------- 239 filename : str, optional 240 The name of the TOML file. Defaults to 'SettingsCoreMS.toml'. 241 file_path : str or Path, optional 242 The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory. 243 lcms_obj : object, optional 244 The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings. 245 246 """ 247 248 if lcms_obj is None: 249 data_dict = parameter_to_dict.get_dict_lcms_default_data() 250 else: 251 data_dict = get_dict_data_lcms(lcms_obj) 252 253 if not file_path: 254 file_path = Path.cwd() / filename 255 256 with open( 257 file_path, 258 "w", 259 encoding="utf8", 260 ) as outfile: 261 output = toml.dumps(data_dict) 262 outfile.write(output)
Write TOML file into current directory with all the LCMS settings data for the CoreMS package.
Parameters
- filename (str, optional): The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
- file_path (str or Path, optional): The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory.
- lcms_obj (object, optional): The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings.