comparison COBRAxy/custom_data_generator.py @ 26:4c9ade74c4d7 draft

Uploaded
author luca_milaz
date Thu, 19 Sep 2024 08:13:29 +0000
parents 80bfd8743ea6
children 291721be77ad
comparison
equal deleted inserted replaced
25:80bfd8743ea6 26:4c9ade74c4d7
143 bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound] 143 bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound]
144 return bounds 144 return bounds
145 145
146 146
147 ###############################- FILE SAVING -################################ 147 ###############################- FILE SAVING -################################
148 def save_as_csv(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None: 148 def save_as_csv_filePath(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None:
149 """ 149 """
150 Saves any dictionary-shaped data in a .csv file created at the given file_path. 150 Saves any dictionary-shaped data in a .csv file created at the given file_path.
151 151
152 Args: 152 Args:
153 data : the data to be written to the file. 153 data : the data to be written to the file.
156 156
157 Returns: 157 Returns:
158 None 158 None
159 """ 159 """
160 with open(file_path.show(), 'w', newline='') as csvfile: 160 with open(file_path.show(), 'w', newline='') as csvfile:
161 writer = csv.DictWriter(csvfile, fieldnames = fieldNames, dialect="excel-tab")
162 writer.writeheader()
163
164 for key, value in data.items():
165 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value })
166
167 def save_as_csv(data :dict, file_path :str, fieldNames :Tuple[str, str]) -> None:
168 """
169 Saves any dictionary-shaped data in a .csv file created at the given file_path.
170
171 Args:
172 data : the data to be written to the file.
173 file_path : the path to the .csv file.
174 fieldNames : the names of the fields (columns) in the .csv file.
175
176 Returns:
177 None
178 """
179 with open(file_path, 'w', newline='') as csvfile:
161 writer = csv.DictWriter(csvfile, fieldnames = fieldNames, dialect="excel-tab") 180 writer = csv.DictWriter(csvfile, fieldnames = fieldNames, dialect="excel-tab")
162 writer.writeheader() 181 writer.writeheader()
163 182
164 for key, value in data.items(): 183 for key, value in data.items():
165 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value }) 184 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value })