# HG changeset patch # User luca_milaz # Date 1721593781 0 # Node ID 957b9f5006b0a3091ad1bfc40d13c66eb8d47744 # Parent a0cc4dd5fea1806985aa1580c6d434f81e14eac9 Uploaded diff -r a0cc4dd5fea1 -r 957b9f5006b0 marea_2/ras_to_bounds.py --- a/marea_2/ras_to_bounds.py Sun Jul 21 20:22:30 2024 +0000 +++ b/marea_2/ras_to_bounds.py Sun Jul 21 20:29:41 2024 +0000 @@ -128,6 +128,10 @@ 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 + 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) else: for reaction in rxns_ids: lower_bound=model_new.reactions.get_by_id(reaction).lower_bound @@ -141,11 +145,12 @@ 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 + 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 + "bounds", sep = '\t', index = False) - 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 @@ -159,7 +164,7 @@ """ if not os.path.exists('ras_to_bounds'): os.makedirs('ras_to_bounds') - + if not os.path.exists('ras_to_bounds_medium'): os.makedirs('ras_to_bounds_medium') @@ -197,10 +202,8 @@ else: generate_bounds(model, medium) - with open(mediumPath.show(), mode='w', newline='') as file: - writer = csv.DictWriter(file, fieldnames=medium[0].keys(), delimiter='\t') - writer.writeheader() - writer.writerows(medium) + mediumDf = pd.DataFrame.from_dict(medium, orient='index', columns=["value"]) + mediumDf.to_csv(mediumPath.show(), sep = '\t') pass ##############################################################################