Mercurial > repos > bimib > cobraxy
diff COBRAxy/ras_to_bounds.py @ 127:d40d5d5435df draft
Uploaded
author | luca_milaz |
---|---|
date | Mon, 14 Oct 2024 08:48:54 +0000 |
parents | a9825d06cc43 |
children | dfb6a1dc6dbc |
line wrap: on
line diff
--- a/COBRAxy/ras_to_bounds.py Mon Oct 14 08:48:39 2024 +0000 +++ b/COBRAxy/ras_to_bounds.py Mon Oct 14 08:48:54 2024 +0000 @@ -111,15 +111,13 @@ return dataset -def apply_ras_bounds(model, ras_row, rxns_ids, mediumRxns_ids): +def apply_ras_bounds(model, ras_row): """ 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. - mediumRxns_ids (list of str): List of reaction IDs in the medium. Their RAS is set to zero, but they are already set in the model. Returns: None """ @@ -138,7 +136,7 @@ model.reactions.get_by_id(reaction).upper_bound=valMax pass -def process_ras_cell(cellName, ras_row, model, rxns_ids, mediumRxns_ids, output_folder): +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. @@ -147,14 +145,13 @@ 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. - mediumRxns_ids (list of str): List of reaction IDs in the medium. Their RAS is set to zero, but they are already set in the model. 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, mediumRxns_ids) + apply_ras_bounds(model_new, ras_row) 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) pass @@ -174,18 +171,15 @@ """ rxns_ids = [rxn.id for rxn in model.reactions] - #metto a zero medium engro2 + # Set all reactions to zero in the medium for rxn_id, _ in model.medium.items(): model.reactions.get_by_id(rxn_id).lower_bound = float(0.0) # Set medium conditions for reaction, value in medium.items(): if value is not None: - ## SOLO ENGRO2 - if(reaction != "EX_thbpt_e" and reaction != "EX_lac__L_e"): - model.reactions.get_by_id(reaction).lower_bound = -float(value) - if(reaction == "EX_lac__L_e"): - model.reactions.get_by_id(reaction).lower_bound = float(0.0) + model.reactions.get_by_id(reaction).lower_bound = -float(value) + mediumRxns_ids = medium.keys() @@ -200,11 +194,11 @@ if ras is not None: #Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows()) for cellName, ras_row in ras.iterrows(): - process_ras_cell(cellName, ras_row, model, rxns_ids, mediumRxns_ids, output_folder) + process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder) break #just one cell for testing else: model_new = model.copy() - apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids, mediumRxns_ids) + apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=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 + "bounds.csv", sep='\t', index=True) pass @@ -252,8 +246,6 @@ # Normalize the RAS values by max RAS ras_combined = ras_combined.div(ras_combined.max(axis=0)) ras_combined.dropna(axis=1, how='all', inplace=True) - #ras_combined = ras_combined.fillna(0) - #il ras c'è per tutti o non c'è per nessuno