changeset 83:9074200334ca draft

Uploaded
author luca_milaz
date Fri, 19 Jul 2024 20:17:34 +0000
parents c7ef1436574e
children fd3d3516436a
files marea_2/custom_data_generator.py
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/custom_data_generator.py	Fri Jul 19 19:56:11 2024 +0000
+++ b/marea_2/custom_data_generator.py	Fri Jul 19 20:17:34 2024 +0000
@@ -119,7 +119,7 @@
     
     return reactionUtils.create_reaction_dict(unparsedReactions)
 
-def get_medium(model:cobra.Model) -> list:
+def get_medium(model:cobra.Model) -> pd.DataFrame:
     trueMedium=[]
     for r in model.reactions:
         positiveCoeff=0
@@ -133,14 +133,16 @@
     df_medium["reaction"] = trueMedium
     return df_medium
 
-def generate_bounds(model:cobra.Model) -> Dict[ReactionId, Tuple[float, float]]:
+def generate_bounds(model:cobra.Model) -> pd.DataFrame:
 
-    bounds = {
-        reaction.id : (reaction.lower_bound, reaction.upper_bound)
-        for reaction in model.reactions
-        if reaction.reaction 
-    }
+    rxns = []
+    for reaction in model.reactions:
+        rxns.append(reaction.id)
 
+    bounds = pd.DataFrame(columns = ["lower_bound", "upper_bound"], index=rxns)
+
+    for reaction in model.reactions:
+        bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound]
     return bounds
 
 
@@ -199,6 +201,8 @@
         utils.writePickle(reactionsPath, reactions)
         utils.writePickle(boundsPath, bounds)
         utils.writePickle(mediumPath, medium)
+        bounds.to_pickle(boundsPath)
+        medium.to_pickle(mediumPath)
     
     elif ARGS.output_format is utils.FileFormat.CSV:
         rules = generate_rules(model, asParsed = False)
@@ -207,8 +211,8 @@
         medium = get_medium(model)
         save_as_csv(rules,     rulesPath,     ("ReactionID", "Rule"))
         save_as_csv(reactions, reactionsPath, ("ReactionID", "Reaction"))
-        save_as_csv(bounds,     boundsPath,     ("ReactionID", "Bounds"))
-        save_as_csv(medium,     mediumPath,     ("ReactionID"))
+        bounds.to_csv(boundsPath)
+        medium.to_csv(mediumPath)
 
 
     # ^ Please if anyone works on this after updating python to 3.12 change the if/elif into a match statement!!