# HG changeset patch # User luca_milaz # Date 1721418228 0 # Node ID 705cfa161913f1fc330085c56eda7687bc93981f # Parent a7037530504362de0c8d8b5d10491c3e4dc2dc05 Uploaded diff -r a70375305043 -r 705cfa161913 marea_2/custom_data_generator.py --- a/marea_2/custom_data_generator.py Fri Jul 19 10:31:15 2024 +0000 +++ b/marea_2/custom_data_generator.py Fri Jul 19 19:43:48 2024 +0000 @@ -118,6 +118,28 @@ return reactionUtils.create_reaction_dict(unparsedReactions) +def get_medium(model:cobra.Model) -> list: + trueMedium=[] + for r in model.reactions: + positiveCoeff=0 + for m in r.metabolites: + if r.get_coefficient(m.id)>0: + positiveCoeff=1; + if (positiveCoeff==0 and r.lower_bound<0): + trueMedium.append(r) + return trueMedium + +def generate_bounds(model:cobra.Model) -> Dict[ReactionId, (float, float)]: + + bounds = { + reaction.id : (reaction.lower_bound, reaction.upper_bound) + for reaction in model.reactions + if reaction.reaction + } + + return reactionUtils.create_reaction_dict(bounds) + + ###############################- FILE SAVING -################################ def save_as_csv(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None: """ @@ -161,18 +183,29 @@ # (it should show up as a collection in the history) rulesPath = utils.FilePath("rules", ARGS.output_format, prefix = ARGS.out_dir) reactionsPath = utils.FilePath("reactions", ARGS.output_format, prefix = ARGS.out_dir) + boundsPath = utils.FilePath("bounds", ARGS.output_format, prefix = ARGS.out_dir) + mediumPath = utils.FilePath("medium", ARGS.output_format, prefix = ARGS.out_dir) if ARGS.output_format is utils.FileFormat.PICKLE: rules = generate_rules(model, asParsed = True) reactions = generate_reactions(model, asParsed = True) + bounds = generate_bounds(model) + medium = get_medium(model) utils.writePickle(rulesPath, rules) utils.writePickle(reactionsPath, reactions) + utils.writePickle(boundsPath, bounds) + utils.writePickle(mediumPath, medium) elif ARGS.output_format is utils.FileFormat.CSV: rules = generate_rules(model, asParsed = False) reactions = generate_reactions(model, asParsed = False) + bounds = generate_bounds(model) + medium = get_medium(model) save_as_csv(rules, rulesPath, ("ReactionID", "Rule")) save_as_csv(reactions, reactionsPath, ("ReactionID", "Reaction")) + save_as_csv(bounds, boundsPath, ("ReactionID", "Bounds")) + save_as_csv(medium, mediumPath, ("ReactionID")) + # ^ Please if anyone works on this after updating python to 3.12 change the if/elif into a match statement!!