Mercurial > repos > bimib > cobraxy
comparison COBRAxy/flux_simulation_beta.py @ 484:1c6fcf97cabe draft
Uploaded
author | luca_milaz |
---|---|
date | Tue, 23 Sep 2025 07:19:29 +0000 |
parents | ecaf3c9852b3 |
children |
comparison
equal
deleted
inserted
replaced
483:1d1fa7e274bb | 484:1c6fcf97cabe |
---|---|
423 | 423 |
424 return df_mean, df_median, df_quantiles | 424 return df_mean, df_median, df_quantiles |
425 | 425 |
426 def fluxes_analysis(model:cobra.Model, model_name:str, output_types:List)-> List[pd.DataFrame]: | 426 def fluxes_analysis(model:cobra.Model, model_name:str, output_types:List)-> List[pd.DataFrame]: |
427 """ | 427 """ |
428 Performs flux analysis including pFBA, FVA, and sensitivity analysis. | 428 Performs flux analysis including pFBA, FVA, and sensitivity analysis. The objective function |
429 is assumed to be already set in the model. | |
429 | 430 |
430 Args: | 431 Args: |
431 model (cobra.Model): The COBRA model to analyze. | 432 model (cobra.Model): The COBRA model to analyze. |
432 model_name (str): Name of the model, used in filenames for output. | 433 model_name (str): Name of the model, used in filenames for output. |
433 output_types (List[str]): Types of analysis to perform (pFBA, FVA, sensitivity). | 434 output_types (List[str]): Types of analysis to perform (pFBA, FVA, sensitivity). |
440 df_FVA= pd.DataFrame() | 441 df_FVA= pd.DataFrame() |
441 df_sensitivity= pd.DataFrame() | 442 df_sensitivity= pd.DataFrame() |
442 | 443 |
443 for output_type in output_types: | 444 for output_type in output_types: |
444 if(output_type == "pFBA"): | 445 if(output_type == "pFBA"): |
445 model.objective = "Biomass" | |
446 solution = cobra.flux_analysis.pfba(model) | 446 solution = cobra.flux_analysis.pfba(model) |
447 fluxes = solution.fluxes | 447 fluxes = solution.fluxes |
448 df_pFBA.loc[0,[rxn.id for rxn in model.reactions]] = fluxes.tolist() | 448 df_pFBA.loc[0,[rxn.id for rxn in model.reactions]] = fluxes.tolist() |
449 df_pFBA = df_pFBA.reset_index(drop=True) | 449 df_pFBA = df_pFBA.reset_index(drop=True) |
450 df_pFBA.index = [model_name] | 450 df_pFBA.index = [model_name] |
461 df_FVA.loc[0, index_rxn+ "_max"] = fva.loc[index_rxn, "maximum"] | 461 df_FVA.loc[0, index_rxn+ "_max"] = fva.loc[index_rxn, "maximum"] |
462 df_FVA = df_FVA.reset_index(drop=True) | 462 df_FVA = df_FVA.reset_index(drop=True) |
463 df_FVA.index = [model_name] | 463 df_FVA.index = [model_name] |
464 df_FVA = df_FVA.astype(float).round(6) | 464 df_FVA = df_FVA.astype(float).round(6) |
465 elif(output_type == "sensitivity"): | 465 elif(output_type == "sensitivity"): |
466 model.objective = "Biomass" | |
467 solution_original = model.optimize().objective_value | 466 solution_original = model.optimize().objective_value |
468 reactions = model.reactions | 467 reactions = model.reactions |
469 single = cobra.flux_analysis.single_reaction_deletion(model) | 468 single = cobra.flux_analysis.single_reaction_deletion(model) |
470 newRow = [] | 469 newRow = [] |
471 df_sensitivity = pd.DataFrame(columns = [rxn.id for rxn in reactions], index = [model_name]) | 470 df_sensitivity = pd.DataFrame(columns = [rxn.id for rxn in reactions], index = [model_name]) |