annotate COBRAxy/custom_data_generator.py @ 13:73be0702f1a2 draft

Uploaded
author luca_milaz
date Wed, 18 Sep 2024 12:36:55 +0000
parents 41f35c2f0c7b
children 20c30b1a032d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
1 import os
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
2 import csv
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
3 import cobra
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
4 import pickle
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
5 import argparse
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
6 import pandas as pd
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
7 import utils.general_utils as utils
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
8 import utils.rule_parsing as rulesUtils
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
9 from typing import Optional, Tuple, Union, Dict
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
10 import utils.reaction_parsing as reactionUtils
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
11
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
12 ARGS : argparse.Namespace
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
13 def process_args() -> argparse.Namespace:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
14 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
15 Interfaces the script of a module with its frontend, making the user's choices for
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
16 various parameters available as values in code.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
17
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
18 Args:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
19 args : Always obtained (in file) from sys.argv
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
20
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
21 Returns:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
22 Namespace : An object containing the parsed arguments
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
23 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
24 parser = argparse.ArgumentParser(
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
25 usage = "%(prog)s [options]",
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
26 description = "generate custom data from a given model")
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
27
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
28 parser.add_argument("-ol", "--out_log", type = str, required = True, help = "Output log")
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
29 parser.add_argument("-id", "--input", type = str, required = True, help = "Input model")
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
30 parser.add_argument("-mn", "--name", type = str, required = True, help = "Input model name")
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
31 # ^ I need this because galaxy converts my files into .dat but I need to know what extension they were in
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
32
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
33 parser.add_argument(
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
34 "-of", "--output_format",
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
35 # vvv I have to use .fromExt because enums in python are the plague and have been implemented by a chimpanzee.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
36 type = utils.FileFormat.fromExt, default = utils.FileFormat.PICKLE,
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
37 choices = [utils.FileFormat.CSV, utils.FileFormat.PICKLE],
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
38 # ^^^ Not all variants are valid here, otherwise list(utils.FileFormat) would be best.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
39 required = True, help = "Extension of all output files")
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
40
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
41 argsNamespace = parser.parse_args()
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
42 argsNamespace.out_dir = "result"
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
43 # ^ can't get this one to work from xml, there doesn't seem to be a way to get the directory attribute from the collection
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
44
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
45 return argsNamespace
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
46
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
47 ################################- INPUT DATA LOADING -################################
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
48 def load_custom_model(file_path :utils.FilePath, ext :Optional[utils.FileFormat] = None) -> cobra.Model:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
49 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
50 Loads a custom model from a file, either in JSON or XML format.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
51
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
52 Args:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
53 file_path : The path to the file containing the custom model.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
54 ext : explicit file extension. Necessary for standard use in galaxy because of its weird behaviour.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
55
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
56 Raises:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
57 DataErr : if the file is in an invalid format or cannot be opened for whatever reason.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
58
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
59 Returns:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
60 cobra.Model : the model, if successfully opened.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
61 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
62 ext = ext if ext else file_path.ext
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
63 try:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
64 if ext is utils.FileFormat.XML:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
65 return cobra.io.read_sbml_model(file_path.show())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
66
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
67 if ext is utils.FileFormat.JSON:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
68 return cobra.io.load_json_model(file_path.show())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
69
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
70 except Exception as e: raise utils.DataErr(file_path, e.__str__())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
71 raise utils.DataErr(file_path,
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
72 f"Formato \"{file_path.ext}\" non riconosciuto, sono supportati solo file JSON e XML")
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
73
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
74 ################################- DATA GENERATION -################################
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
75 ReactionId = str
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
76 def generate_rules(model: cobra.Model, *, asParsed = True) -> Union[Dict[ReactionId, rulesUtils.OpList], Dict[ReactionId, str]]:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
77 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
78 Generates a dictionary mapping reaction ids to rules from the model.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
79
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
80 Args:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
81 model : the model to derive data from.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
82 asParsed : if True parses the rules to an optimized runtime format, otherwise leaves them as strings.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
83
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
84 Returns:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
85 Dict[ReactionId, rulesUtils.OpList] : the generated dictionary of parsed rules.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
86 Dict[ReactionId, str] : the generated dictionary of raw rules.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
87 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
88 # Is the below approach convoluted? yes
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
89 # Ok but is it inefficient? probably
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
90 # Ok but at least I don't have to repeat the check at every rule (I'm clinically insane)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
91 _ruleGetter = lambda reaction : reaction.gene_reaction_rule
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
92 ruleExtractor = (lambda reaction :
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
93 rulesUtils.parseRuleToNestedList(_ruleGetter(reaction))) if asParsed else _ruleGetter
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
94
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
95 return {
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
96 reaction.id : ruleExtractor(reaction)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
97 for reaction in model.reactions
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
98 if reaction.gene_reaction_rule }
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
99
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
100 def generate_reactions(model :cobra.Model, *, asParsed = True) -> Dict[ReactionId, str]:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
101 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
102 Generates a dictionary mapping reaction ids to reaction formulas from the model.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
103
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
104 Args:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
105 model : the model to derive data from.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
106 asParsed : if True parses the reactions to an optimized runtime format, otherwise leaves them as they are.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
107
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
108 Returns:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
109 Dict[ReactionId, str] : the generated dictionary.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
110 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
111
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
112 unparsedReactions = {
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
113 reaction.id : reaction.reaction
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
114 for reaction in model.reactions
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
115 if reaction.reaction
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
116 }
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
117
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
118 if not asParsed: return unparsedReactions
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
119
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
120 return reactionUtils.create_reaction_dict(unparsedReactions)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
121
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
122 def get_medium(model:cobra.Model) -> pd.DataFrame:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
123 trueMedium=[]
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
124 for r in model.reactions:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
125 positiveCoeff=0
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
126 for m in r.metabolites:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
127 if r.get_coefficient(m.id)>0:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
128 positiveCoeff=1;
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
129 if (positiveCoeff==0 and r.lower_bound<0):
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
130 trueMedium.append(r.id)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
131
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
132 df_medium = pd.DataFrame()
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
133 df_medium["reaction"] = trueMedium
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
134 return df_medium
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
135
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
136 def generate_bounds(model:cobra.Model) -> pd.DataFrame:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
137
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
138 rxns = []
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
139 for reaction in model.reactions:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
140 rxns.append(reaction.id)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
141
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
142 bounds = pd.DataFrame(columns = ["lower_bound", "upper_bound"], index=rxns)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
143
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
144 for reaction in model.reactions:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
145 bounds.loc[reaction.id] = [reaction.lower_bound, reaction.upper_bound]
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
146 return bounds
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
147
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
148
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
149 ###############################- FILE SAVING -################################
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
150 def save_as_csv(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
151 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
152 Saves any dictionary-shaped data in a .csv file created at the given file_path.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
153
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
154 Args:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
155 data : the data to be written to the file.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
156 file_path : the path to the .csv file.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
157 fieldNames : the names of the fields (columns) in the .csv file.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
158
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
159 Returns:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
160 None
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
161 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
162 with open(file_path.show(), 'w', newline='') as csvfile:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
163 writer = csv.DictWriter(csvfile, fieldnames = fieldNames)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
164 writer.writeheader()
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
165
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
166 for key, value in data.items():
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
167 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value })
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
168
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
169 ###############################- ENTRY POINT -################################
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
170 def main() -> None:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
171 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
172 Initializes everything and sets the program in motion based on the fronted input arguments.
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
173
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
174 Returns:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
175 None
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
176 """
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
177 # get args from frontend (related xml)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
178 global ARGS
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
179 ARGS = process_args()
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
180
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
181 # this is the worst thing I've seen so far, congrats to the former MaREA devs for suggesting this!
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
182 if os.path.isdir(ARGS.out_dir) == False: os.makedirs(ARGS.out_dir)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
183
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
184 # load custom model
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
185 model = load_custom_model(
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
186 utils.FilePath.fromStrPath(ARGS.input), utils.FilePath.fromStrPath(ARGS.name).ext)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
187
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
188 # generate data and save it in the desired format and in a location galaxy understands
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
189 # (it should show up as a collection in the history)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
190 rulesPath = utils.FilePath("rules", ARGS.output_format, prefix = ARGS.out_dir)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
191 reactionsPath = utils.FilePath("reactions", ARGS.output_format, prefix = ARGS.out_dir)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
192 boundsPath = utils.FilePath("bounds", ARGS.output_format, prefix = ARGS.out_dir)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
193 mediumPath = utils.FilePath("medium", ARGS.output_format, prefix = ARGS.out_dir)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
194
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
195 if ARGS.output_format is utils.FileFormat.PICKLE:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
196 rules = generate_rules(model, asParsed = True)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
197 reactions = generate_reactions(model, asParsed = True)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
198 bounds = generate_bounds(model)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
199 medium = get_medium(model)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
200 utils.writePickle(rulesPath, rules)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
201 utils.writePickle(reactionsPath, reactions)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
202 utils.writePickle(boundsPath, bounds)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
203 utils.writePickle(mediumPath, medium)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
204 bounds.to_pickle(boundsPath.show())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
205 medium.to_pickle(mediumPath.show())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
206
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
207 elif ARGS.output_format is utils.FileFormat.CSV:
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
208 rules = generate_rules(model, asParsed = False)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
209 reactions = generate_reactions(model, asParsed = False)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
210 bounds = generate_bounds(model)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
211 medium = get_medium(model)
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
212 save_as_csv(rules, rulesPath, ("ReactionID", "Rule"))
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
213 save_as_csv(reactions, reactionsPath, ("ReactionID", "Reaction"))
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
214 bounds.to_csv(boundsPath.show())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
215 medium.to_csv(mediumPath.show())
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
216
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
217
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
218 # ^ Please if anyone works on this after updating python to 3.12 change the if/elif into a match statement!!
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
219
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
220 if __name__ == '__main__':
41f35c2f0c7b Uploaded
luca_milaz
parents:
diff changeset
221 main()