Mercurial > repos > bimib > marea_2
changeset 285:7a098cb82865 draft
Uploaded
author | luca_milaz |
---|---|
date | Sun, 04 Aug 2024 18:38:30 +0000 |
parents | 90185e1784ab |
children | b501ac3585a1 |
files | marea_2/ras_to_bounds.py |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/marea_2/ras_to_bounds.py Sun Aug 04 18:38:11 2024 +0000 +++ b/marea_2/ras_to_bounds.py Sun Aug 04 18:38:30 2024 +0000 @@ -103,6 +103,17 @@ def apply_ras_bounds(model, ras_row, rxns_ids): + """ + Adjust the bounds of reactions in the model based on RAS values. + + Args: + model (cobra.Model): The metabolic model to be modified. + ras_row (pd.Series): A row from a RAS DataFrame containing scaling factors for reaction bounds. + rxns_ids (list of str): List of reaction IDs to which the scaling factors will be applied. + + Returns: + None + """ for reaction in rxns_ids: if reaction in ras_row.index and pd.notna(ras_row[reaction]): rxn = model.reactions.get_by_id(reaction) @@ -111,12 +122,37 @@ rxn.upper_bound *= scaling_factor def process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder): + """ + Process a single RAS cell, apply bounds, and save the bounds to a CSV file. + + Args: + cellName (str): The name of the RAS cell (used for naming the output file). + ras_row (pd.Series): A row from a RAS DataFrame containing scaling factors for reaction bounds. + model (cobra.Model): The metabolic model to be modified. + rxns_ids (list of str): List of reaction IDs to which the scaling factors will be applied. + output_folder (str): Folder path where the output CSV file will be saved. + + Returns: + None + """ model_new = model.copy() apply_ras_bounds(model_new, ras_row, rxns_ids) bounds = pd.DataFrame([(rxn.lower_bound, rxn.upper_bound) for rxn in model_new.reactions], index=rxns_ids, columns=["lower_bound", "upper_bound"]) bounds.to_csv(output_folder + cellName + ".csv", sep='\t', index=True) def generate_bounds(model: cobra.Model, medium: dict, ras=None, output_folder='output/') -> pd.DataFrame: + """ + Generate reaction bounds for a metabolic model based on medium conditions and optional RAS adjustments. + + Args: + model (cobra.Model): The metabolic model for which bounds will be generated. + medium (dict): A dictionary where keys are reaction IDs and values are the medium conditions. + ras (pd.DataFrame, optional): A DataFrame with RAS scaling factors for different cell types. Defaults to None. + output_folder (str, optional): Folder path where output CSV files will be saved. Defaults to 'output/'. + + Returns: + pd.DataFrame: DataFrame containing the bounds of reactions in the model. + """ rxns_ids = [rxn.id for rxn in model.reactions] # Set medium conditions