Mercurial > repos > bimib > marea_2
changeset 125:4f889150f278 draft
Uploaded
author | luca_milaz |
---|---|
date | Sun, 21 Jul 2024 20:04:28 +0000 |
parents | 2590e2f60307 |
children | 8d50cf0c3d5f |
files | marea_2/ras_to_bounds.py |
diffstat | 1 files changed, 27 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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