# HG changeset patch # User luca_milaz # Date 1721420254 0 # Node ID 9074200334caf716b161a1570dbd6d85a638b3e7 # Parent c7ef1436574e4d8d188cce3fdd92fd81da787b34 Uploaded diff -r c7ef1436574e -r 9074200334ca marea_2/custom_data_generator.py --- a/marea_2/custom_data_generator.py Fri Jul 19 19:56:11 2024 +0000 +++ b/marea_2/custom_data_generator.py Fri Jul 19 20:17:34 2024 +0000 @@ -119,7 +119,7 @@ return reactionUtils.create_reaction_dict(unparsedReactions) -def get_medium(model:cobra.Model) -> list: +def get_medium(model:cobra.Model) -> pd.DataFrame: trueMedium=[] for r in model.reactions: positiveCoeff=0 @@ -133,14 +133,16 @@ df_medium["reaction"] = trueMedium return df_medium -def generate_bounds(model:cobra.Model) -> Dict[ReactionId, Tuple[float, float]]: +def generate_bounds(model:cobra.Model) -> pd.DataFrame: - bounds = { - reaction.id : (reaction.lower_bound, reaction.upper_bound) - for reaction in model.reactions - if reaction.reaction - } + rxns = [] + for reaction in model.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 @@ -199,6 +201,8 @@ utils.writePickle(reactionsPath, reactions) utils.writePickle(boundsPath, bounds) utils.writePickle(mediumPath, medium) + bounds.to_pickle(boundsPath) + medium.to_pickle(mediumPath) elif ARGS.output_format is utils.FileFormat.CSV: rules = generate_rules(model, asParsed = False) @@ -207,8 +211,8 @@ 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")) + bounds.to_csv(boundsPath) + medium.to_csv(mediumPath) # ^ Please if anyone works on this after updating python to 3.12 change the if/elif into a match statement!!