# HG changeset patch # User luca_milaz # Date 1721592268 0 # Node ID 4f889150f27857884ba5da785f3c73b60eb82bf8 # Parent 2590e2f603072769848f290869b8332f7f526f07 Uploaded diff -r 2590e2f60307 -r 4f889150f278 marea_2/ras_to_bounds.py --- a/marea_2/ras_to_bounds.py Sun Jul 21 19:48:27 2024 +0000 +++ b/marea_2/ras_to_bounds.py Sun Jul 21 20:04:28 2024 +0000 @@ -111,14 +111,28 @@ for reaction in rxns_ids: model_new.reactions.get_by_id(reaction).lower_bound=float(df_FVA.loc[reaction,"minimum"]) model_new.reactions.get_by_id(reaction).upper_bound=float(df_FVA.loc[reaction,"maximum"]) - - if(ras is not None):#iterate over cells - for reaction in rxns_ids: - if reaction in ras.keys(): + + for cellName, ras in ras.iterrows(): + if(ras is not None): + for reaction in rxns_ids: + if reaction in ras.keys(): + lower_bound=model_new.reactions.get_by_id(reaction).lower_bound + upper_bound=model_new.reactions.get_by_id(reaction).upper_bound + valMax=float((upper_bound)*ras[reaction]) + valMin=float((lower_bound)*ras[reaction]) + if upper_bound!=0 and lower_bound==0: + model_new.reactions.get_by_id(reaction).upper_bound=valMax + if upper_bound==0 and lower_bound!=0: + model_new.reactions.get_by_id(reaction).lower_bound=valMin + if upper_bound!=0 and lower_bound!=0: + model_new.reactions.get_by_id(reaction).lower_bound=valMin + model_new.reactions.get_by_id(reaction).upper_bound=valMax + else: + for reaction in rxns_ids: lower_bound=model_new.reactions.get_by_id(reaction).lower_bound upper_bound=model_new.reactions.get_by_id(reaction).upper_bound - valMax=float((upper_bound)*ras[reaction]) - valMin=float((lower_bound)*ras[reaction]) + valMax = float((upper_bound)*1) + valMin=float((lower_bound)*1) if upper_bound!=0 and lower_bound==0: model_new.reactions.get_by_id(reaction).upper_bound=valMax if upper_bound==0 and lower_bound!=0: @@ -126,15 +140,11 @@ if upper_bound!=0 and lower_bound!=0: model_new.reactions.get_by_id(reaction).lower_bound=valMin model_new.reactions.get_by_id(reaction).upper_bound=valMax - rxns = [] - for reaction in model_new.reactions: - rxns.append(reaction.id) - - bounds = pd.DataFrame(columns = ["lower_bound", "upper_bound"], index=rxns) - - for reaction in model.reactions: - bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound] - return bounds + bounds = pd.DataFrame(columns = ["lower_bound", "upper_bound"], index=rxns_ids) + for reaction in model.reactions: + bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound] + bounds.to_csv(ARGS.output_folder + cellName, sep = '\t', index = False) + pass ############################# main ########################################### @@ -157,7 +167,6 @@ ARGS.input_ras, ARGS.out_log) - boundsPath = utils.FilePath("bounds", ".csv", prefix = ARGS.output_folder) mediumPath = utils.FilePath("medium", ".csv", prefix = ARGS.output_folder) if(ARGS.ras_selector == True): @@ -183,11 +192,10 @@ medium = medium[ARGS.medium_selector].to_dict() if(ARGS.ras_selector == True): - bounds = generate_bounds(model, medium, ras = ras) + generate_bounds(model, medium, ras = ras) else: - bounds = generate_bounds(model, medium) + generate_bounds(model, medium) - bounds.to_csv(boundsPath.show()) medium.to_csv(mediumPath.show()) pass