Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_to_bounds.py @ 102:182c710c1660 draft
Uploaded
| author | luca_milaz |
|---|---|
| date | Sun, 13 Oct 2024 13:23:12 +0000 |
| parents | 54ded7f28a60 |
| children | d1370b6bb4c5 |
comparison
equal
deleted
inserted
replaced
| 101:6cb85065b38b | 102:182c710c1660 |
|---|---|
| 126 for reaction in rxns_ids: | 126 for reaction in rxns_ids: |
| 127 if reaction in ras_row.index: | 127 if reaction in ras_row.index: |
| 128 scaling_factor = ras_row[reaction] | 128 scaling_factor = ras_row[reaction] |
| 129 lower_bound=model.reactions.get_by_id(reaction).lower_bound | 129 lower_bound=model.reactions.get_by_id(reaction).lower_bound |
| 130 upper_bound=model.reactions.get_by_id(reaction).upper_bound | 130 upper_bound=model.reactions.get_by_id(reaction).upper_bound |
| 131 #warning("Reaction: "+reaction+" Lower Bound: "+str(lower_bound)+" Upper Bound: "+str(upper_bound)+" Scaling Factor: "+str(scaling_factor)) | |
| 132 valMax=float((upper_bound)*scaling_factor) | 131 valMax=float((upper_bound)*scaling_factor) |
| 133 valMin=float((lower_bound)*scaling_factor) | 132 valMin=float((lower_bound)*scaling_factor) |
| 134 if upper_bound!=0 and lower_bound==0: | 133 if upper_bound!=0 and lower_bound==0: |
| 135 model.reactions.get_by_id(reaction).upper_bound=valMax | 134 model.reactions.get_by_id(reaction).upper_bound=valMax |
| 136 if upper_bound==0 and lower_bound!=0: | 135 if upper_bound==0 and lower_bound!=0: |
| 174 pd.DataFrame: DataFrame containing the bounds of reactions in the model. | 173 pd.DataFrame: DataFrame containing the bounds of reactions in the model. |
| 175 """ | 174 """ |
| 176 rxns_ids = [rxn.id for rxn in model.reactions] | 175 rxns_ids = [rxn.id for rxn in model.reactions] |
| 177 | 176 |
| 178 # Set medium conditions | 177 # Set medium conditions |
| 178 ''' | |
| 179 reactions_medium=model2.medium.keys() | |
| 180 for reaction in reactions_medium: | |
| 181 if(reaction != "EX_thbpt_e" and reaction != "EX_lac__L_e"): | |
| 182 model2.reactions.get_by_id(reaction).lower_bound=-float(ras_meta.loc[cell,"countmatrix_"+reaction]) | |
| 183 if(reaction == "EX_lac__L_e"): | |
| 184 model2.reactions.get_by_id(reaction).lower_bound=float(0.0) | |
| 185 ''' | |
| 179 for reaction, value in medium.items(): | 186 for reaction, value in medium.items(): |
| 180 if value is not None: | 187 if value is not None: |
| 181 model.reactions.get_by_id(reaction).lower_bound = -float(value) | 188 model.reactions.get_by_id(reaction).lower_bound = -float(value) |
| 182 | 189 |
| 183 # Perform Flux Variability Analysis (FVA) | 190 # Perform Flux Variability Analysis (FVA) |
| 184 df_FVA = cobra.flux_analysis.flux_variability_analysis(model, fraction_of_optimum=0, processes=1).round(8) | 191 df_FVA = cobra.flux_analysis.flux_variability_analysis(model, fraction_of_optimum=0, processes=1).round(8) |
| 185 | 192 |
| 186 # Set FVA bounds | 193 # Set FVA bounds |
| 187 for reaction in rxns_ids: | 194 for reaction in rxns_ids: |
| 188 rxn = model.reactions.get_by_id(reaction) | 195 model.reactions.get_by_id(reaction).lower_bound = float(df_FVA.loc[reaction, "minimum"]) |
| 189 rxn.lower_bound = float(df_FVA.loc[reaction, "minimum"]) | 196 model.reactions.get_by_id(reaction).upper_bound = float(df_FVA.loc[reaction, "maximum"]) |
| 190 rxn.upper_bound = float(df_FVA.loc[reaction, "maximum"]) | |
| 191 | 197 |
| 192 if ras is not None: | 198 if ras is not None: |
| 193 Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows()) | 199 Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows()) |
| 194 #for cellName, ras_row in ras.iterrows(): | |
| 195 #process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder) | |
| 196 else: | 200 else: |
| 197 model_new = model.copy() | 201 model_new = model.copy() |
| 198 apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids) | 202 apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids) |
| 199 bounds = pd.DataFrame([(rxn.lower_bound, rxn.upper_bound) for rxn in model_new.reactions], index=rxns_ids, columns=["lower_bound", "upper_bound"]) | 203 bounds = pd.DataFrame([(rxn.lower_bound, rxn.upper_bound) for rxn in model_new.reactions], index=rxns_ids, columns=["lower_bound", "upper_bound"]) |
| 200 bounds.to_csv(output_folder + "bounds.csv", sep='\t', index=True) | 204 bounds.to_csv(output_folder + "bounds.csv", sep='\t', index=True) |
