Mercurial > repos > bimib > cobraxy
comparison COBRAxy/custom_data_generator.py @ 28:291721be77ad draft
Uploaded
| author | luca_milaz |
|---|---|
| date | Thu, 19 Sep 2024 08:23:25 +0000 |
| parents | 4c9ade74c4d7 |
| children |
comparison
equal
deleted
inserted
replaced
| 27:b61fc7f1b6ab | 28:291721be77ad |
|---|---|
| 145 | 145 |
| 146 | 146 |
| 147 ###############################- FILE SAVING -################################ | 147 ###############################- FILE SAVING -################################ |
| 148 def save_as_csv_filePath(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 as FilePath. |
| 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. |
| 154 file_path : the path to the .csv file. | 154 file_path : the path to the .csv file. |
| 155 fieldNames : the names of the fields (columns) in the .csv file. | 155 fieldNames : the names of the fields (columns) in the .csv file. |
| 164 for key, value in data.items(): | 164 for key, value in data.items(): |
| 165 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value }) | 165 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value }) |
| 166 | 166 |
| 167 def save_as_csv(data :dict, file_path :str, fieldNames :Tuple[str, str]) -> None: | 167 def save_as_csv(data :dict, file_path :str, fieldNames :Tuple[str, str]) -> None: |
| 168 """ | 168 """ |
| 169 Saves any dictionary-shaped data in a .csv file created at the given file_path. | 169 Saves any dictionary-shaped data in a .csv file created at the given file_path as string. |
| 170 | 170 |
| 171 Args: | 171 Args: |
| 172 data : the data to be written to the file. | 172 data : the data to be written to the file. |
| 173 file_path : the path to the .csv file. | 173 file_path : the path to the .csv file. |
| 174 fieldNames : the names of the fields (columns) in the .csv file. | 174 fieldNames : the names of the fields (columns) in the .csv file. |
| 200 | 200 |
| 201 # load custom model | 201 # load custom model |
| 202 model = load_custom_model( | 202 model = load_custom_model( |
| 203 utils.FilePath.fromStrPath(ARGS.input), utils.FilePath.fromStrPath(ARGS.name).ext) | 203 utils.FilePath.fromStrPath(ARGS.input), utils.FilePath.fromStrPath(ARGS.name).ext) |
| 204 | 204 |
| 205 # generate data | |
| 205 rules = generate_rules(model, asParsed = False) | 206 rules = generate_rules(model, asParsed = False) |
| 206 reactions = generate_reactions(model, asParsed = False) | 207 reactions = generate_reactions(model, asParsed = False) |
| 207 bounds = generate_bounds(model) | 208 bounds = generate_bounds(model) |
| 208 medium = get_medium(model) | 209 medium = get_medium(model) |
| 209 | 210 |
| 210 | 211 # save files out of collection: path coming from xml |
| 211 save_as_csv(rules, ARGS.out_rules, ("ReactionID", "Rule")) | 212 save_as_csv(rules, ARGS.out_rules, ("ReactionID", "Rule")) |
| 212 save_as_csv(reactions, ARGS.out_reactions, ("ReactionID", "Reaction")) | 213 save_as_csv(reactions, ARGS.out_reactions, ("ReactionID", "Reaction")) |
| 213 bounds.to_csv(ARGS.out_bounds, sep = '\t') | 214 bounds.to_csv(ARGS.out_bounds, sep = '\t') |
| 214 medium.to_csv(ARGS.out_medium, sep = '\t') | 215 medium.to_csv(ARGS.out_medium, sep = '\t') |
| 215 | 216 |
| 216 | |
| 217 # ^ Please if anyone works on this after updating python to 3.12 change the if/elif into a match statement!! | |
| 218 | |
| 219 if __name__ == '__main__': | 217 if __name__ == '__main__': |
| 220 main() | 218 main() |
