changeset 139:b00ec73b1c57 draft

Uploaded
author luca_milaz
date Sun, 21 Jul 2024 21:05:46 +0000
parents cfc088065e08
children be24e86b2487
files marea_2/ras_to_bounds.py
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/ras_to_bounds.py	Sun Jul 21 21:00:56 2024 +0000
+++ b/marea_2/ras_to_bounds.py	Sun Jul 21 21:05:46 2024 +0000
@@ -101,20 +101,20 @@
     return dataset
 
 def generate_bounds(model:cobra.Model, medium:dict, ras=None) -> pd.DataFrame:
-    model_new = model.copy()
     rxns_ids = []
     for rxn in model.reactions:
         rxns_ids.append(rxn.id)
     for reaction in medium.keys():
         if(medium[reaction] != None):
-            model_new.reactions.get_by_id(reaction).lower_bound=-float(medium[reaction])
-    df_FVA = cobra.flux_analysis.flux_variability_analysis(model_new,fraction_of_optimum=0,processes=1).round(8)
+            model.reactions.get_by_id(reaction).lower_bound=-float(medium[reaction])
+    df_FVA = cobra.flux_analysis.flux_variability_analysis(model,fraction_of_optimum=0,processes=1).round(8)
     for reaction in rxns_ids:
-        model_new.reactions.get_by_id(reaction).lower_bound=float(df_FVA.loc[reaction,"minimum"])
-        model_new.reactions.get_by_id(reaction).upper_bound=float(df_FVA.loc[reaction,"maximum"])
+        model.reactions.get_by_id(reaction).lower_bound=float(df_FVA.loc[reaction,"minimum"])
+        model.reactions.get_by_id(reaction).upper_bound=float(df_FVA.loc[reaction,"maximum"])
 
     if(ras is not  None):
         for cellName, ras in ras.iterrows():
+            model_new = model.copy()
             for reaction in rxns_ids:
                 if (reaction in ras.keys() and ras[reaction] != None and pd.notna(ras[reaction])):
                     lower_bound=model_new.reactions.get_by_id(reaction).lower_bound
@@ -129,10 +129,11 @@
                         model_new.reactions.get_by_id(reaction).lower_bound=valMin
                         model_new.reactions.get_by_id(reaction).upper_bound=valMax
             bounds = pd.DataFrame(columns = ["lower_bound", "upper_bound"], index=rxns_ids)
-            for reaction in model.reactions:
+            for reaction in model_new.reactions:
                 bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound]
             bounds.to_csv(ARGS.output_folder + cellName + ".csv", sep = '\t', index = False)
     else:
+        model_new = model.copy()
         for reaction in rxns_ids:
             lower_bound=model_new.reactions.get_by_id(reaction).lower_bound
             upper_bound=model_new.reactions.get_by_id(reaction).upper_bound
@@ -146,7 +147,7 @@
                 model_new.reactions.get_by_id(reaction).lower_bound=valMin
                 model_new.reactions.get_by_id(reaction).upper_bound=valMax
         bounds = pd.DataFrame(columns = ["lower_bound", "upper_bound"], index=rxns_ids)
-        for reaction in model.reactions:
+        for reaction in model_new.reactions:
             bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound]
         bounds.to_csv(ARGS.output_folder + "bounds.csv", sep = '\t', index = False)