changeset 77:705cfa161913 draft

Uploaded
author luca_milaz
date Fri, 19 Jul 2024 19:43:48 +0000
parents a70375305043
children aa1f89b66721
files marea_2/custom_data_generator.py
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/custom_data_generator.py	Fri Jul 19 10:31:15 2024 +0000
+++ b/marea_2/custom_data_generator.py	Fri Jul 19 19:43:48 2024 +0000
@@ -118,6 +118,28 @@
     
     return reactionUtils.create_reaction_dict(unparsedReactions)
 
+def get_medium(model:cobra.Model) -> list:
+  trueMedium=[]
+  for r in model.reactions:
+    positiveCoeff=0
+    for m in r.metabolites:
+      if r.get_coefficient(m.id)>0:
+        positiveCoeff=1;
+    if (positiveCoeff==0 and r.lower_bound<0):
+      trueMedium.append(r)
+  return trueMedium
+
+def generate_bounds(model:cobra.Model) -> Dict[ReactionId, (float, float)]:
+
+    bounds = {
+        reaction.id : (reaction.lower_bound, reaction.upper_bound)
+        for reaction in model.reactions
+        if reaction.reaction 
+    }
+
+    return reactionUtils.create_reaction_dict(bounds)
+
+
 ###############################- FILE SAVING -################################
 def save_as_csv(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None:
     """
@@ -161,18 +183,29 @@
     # (it should show up as a collection in the history)
     rulesPath     = utils.FilePath("rules",     ARGS.output_format, prefix = ARGS.out_dir)
     reactionsPath = utils.FilePath("reactions", ARGS.output_format, prefix = ARGS.out_dir)
+    boundsPath = utils.FilePath("bounds",     ARGS.output_format, prefix = ARGS.out_dir)
+    mediumPath = utils.FilePath("medium",     ARGS.output_format, prefix = ARGS.out_dir)
 
     if ARGS.output_format is utils.FileFormat.PICKLE:
         rules = generate_rules(model, asParsed = True)
         reactions = generate_reactions(model, asParsed = True)
+        bounds = generate_bounds(model)
+        medium = get_medium(model)
         utils.writePickle(rulesPath,     rules)
         utils.writePickle(reactionsPath, reactions)
+        utils.writePickle(boundsPath, bounds)
+        utils.writePickle(mediumPath, medium)
     
     elif ARGS.output_format is utils.FileFormat.CSV:
         rules = generate_rules(model, asParsed = False)
         reactions = generate_reactions(model, asParsed = False)
+        bounds = generate_bounds(model)
+        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"))
+
 
     # ^ Please if anyone works on this after updating python to 3.12 change the if/elif into a match statement!!