# HG changeset patch
# User francesco_lapi
# Date 1757516016 0
# Node ID f49c951c9fe647063b5cbe31d7f9a47621aa6ee0
# Parent 0485c4b1943d77bb46a7043fc7a46eb90f5cfb8f
Uploaded
diff -r 0485c4b1943d -r f49c951c9fe6 COBRAxy/flux_simulation_beta.py
--- a/COBRAxy/flux_simulation_beta.py Wed Sep 10 13:26:03 2025 +0000
+++ b/COBRAxy/flux_simulation_beta.py Wed Sep 10 14:53:36 2025 +0000
@@ -80,6 +80,12 @@
required = True,
help = 'choose how many batches')
+ parser.add_argument('-opt', '--perc_opt',
+ type = float,
+ default=0.9,
+ required = False,
+ help = 'choose the fraction of optimality for FVA (0-1)')
+
parser.add_argument('-ot', '--output_type',
type = str,
required = True,
@@ -359,7 +365,7 @@
df_pFBA.index = [model_name]
df_pFBA = df_pFBA.astype(float).round(6)
elif(output_type == "FVA"):
- fva = cobra.flux_analysis.flux_variability_analysis(model, fraction_of_optimum=0, processes=1).round(8)
+ fva = cobra.flux_analysis.flux_variability_analysis(model, fraction_of_optimum=ARGS.perc_opt, processes=1).round(8)
columns = []
for rxn in fva.index.to_list():
columns.append(rxn + "_min")
diff -r 0485c4b1943d -r f49c951c9fe6 COBRAxy/flux_simulation_beta.xml
--- a/COBRAxy/flux_simulation_beta.xml Wed Sep 10 13:26:03 2025 +0000
+++ b/COBRAxy/flux_simulation_beta.xml Wed Sep 10 14:53:36 2025 +0000
@@ -44,8 +44,11 @@
--n_batches $n_batches
--n_samples $n_samples
--seed $seed
+ #if $output_types_analysis_cond.fva_fraction == 'FVA'
+ --perc_opt $output_types_analysis_cond.fva_fraction
+ #end if
--output_type "${",".join(map(str, $output_types))}"
- --output_type_analysis "${",".join(map(str, $output_types_analysis))}"
+ --output_type_analysis "${",".join(map(str, $output_types_analysis_cond.output_types_analysis))}"
--out_log $log
]]>
@@ -95,11 +98,22 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 0485c4b1943d -r f49c951c9fe6 COBRAxy/utils/model_utils.py
--- a/COBRAxy/utils/model_utils.py Wed Sep 10 13:26:03 2025 +0000
+++ b/COBRAxy/utils/model_utils.py Wed Sep 10 14:53:36 2025 +0000
@@ -254,9 +254,9 @@
print(f"Aggiunte {reactions_added} reazioni, saltate {reactions_skipped} reazioni")
- # Imposta l'obiettivo di biomassa
- set_biomass_objective(model)
-
+ # set objective function
+ set_objective_from_csv(model, df, obj_col="ObjectiveCoefficient")
+
# Imposta il medium
set_medium_from_data(model, df)
@@ -361,17 +361,31 @@
-def set_biomass_objective(model: cobraModel):
+def set_objective_from_csv(model: cobra.Model, df: pd.DataFrame, obj_col: str = "ObjectiveCoefficient"):
"""
- Imposta la reazione di biomassa come obiettivo.
+ Sets the model's objective function based on a column of coefficients in the CSV.
+ Can be any reaction(s), not necessarily biomass.
"""
- biomass_reactions = [r for r in model.reactions if 'biomass' in r.id.lower()]
+ obj_dict = {}
- if biomass_reactions:
- model.objective = biomass_reactions[0].id
- print(f"Obiettivo impostato su: {biomass_reactions[0].id}")
- else:
- print("Nessuna reazione di biomassa trovata")
+ for idx, row in df.iterrows():
+ reaction_id = str(row['ReactionID']).strip()
+ coeff = float(row[obj_col]) if pd.notna(row[obj_col]) else 0.0
+ if coeff != 0:
+ # Assicuriamoci che la reazione esista nel modello
+ if reaction_id in model.reactions:
+ obj_dict[model.reactions.get_by_id(reaction_id)] = coeff
+ else:
+ print(f"Warning: reaction {reaction_id} not found in model, skipping for objective.")
+
+ if not obj_dict:
+ raise ValueError("No reactions found with non-zero objective coefficient.")
+
+ # Imposta la funzione obiettivo
+ model.objective = obj_dict
+ print(f"Objective set with {len(obj_dict)} reactions.")
+
+
def set_medium_from_data(model: cobraModel, df: pd.DataFrame):