@@ -40,19 +40,20 @@ else:
40
40
from findCPcore import FacadeUtils
41
41
from findCPcore .utils .GrowthDependentCPConfig import GrowthDependentCPConfig
42
42
43
- TASK_SPREADSHEET = "TASK_SPREADSHEET "
43
+ TASK_CRITICAL_REACTIONS = "TASK_CRITICAL_REACTIONS "
44
44
TASK_SENSIBILITY = "TASK_SENSIBILITY"
45
45
TASK_SAVE_WITHOUT_DEM = "TASK_SAVE_WITHOUT_DEM"
46
46
TASK_SAVE_WITH_FVA = "TASK_SAVE_WITH_FVA"
47
47
TASK_SAVE_WITH_FVA_DEM = "TASK_SAVE_WITH_FVA_DEM"
48
48
49
- MSG_SUCCESFULL_SAVE = "File succesfully saved at: {}"
49
+ MSG_SUCCESFULL_SAVE = "File successfully saved at: {}"
50
50
MSG_UNKNOWN_ERROR = "Error, something went wrong: {}"
51
51
MSG_FURTHER_INFO = "run findCPcli -h for further information."
52
52
53
53
PARAM_INPUT_FILE = "<input file>"
54
54
PARAM_OUTPUT_FILE = "<output file>"
55
55
PARAM_REACTION_ID = "<reaction id>"
56
+ PARAM_FRACTION = "<fraction>"
56
57
57
58
LICENSE = """
58
59
findCPcli Copyright (C) 2020-2021 Alex Oarga <718123 at unizar dot es> (University of Zaragoza)
@@ -94,9 +95,9 @@ def check_error_save_final_model(error, facade, output_path, verbose_f):
94
95
else :
95
96
save_final_model (facade , output_path , verbose_f )
96
97
97
- def run (task , model_path , output_path , verbose , objective = None ):
98
+ def run (task , model_path , output_path , verbose , objective = None , fraction = 1.0 ):
98
99
try :
99
- if task == TASK_SPREADSHEET :
100
+ if task == TASK_CRITICAL_REACTIONS :
100
101
print ("Task: Save results spreadsheet" )
101
102
facade = Facade ()
102
103
error = facade .generate_spreadsheet (
@@ -107,6 +108,7 @@ def run(task, model_path, output_path, verbose, objective=None):
107
108
args2 = None ,
108
109
output_path = None ,
109
110
objective = objective ,
111
+ fraction = fraction
110
112
)
111
113
save_final_spreadsheet (facade , output_path , verbose_f , error )
112
114
@@ -145,6 +147,7 @@ def run(task, model_path, output_path, verbose, objective=None):
145
147
args1 = verbose ,
146
148
args2 = None ,
147
149
objective = objective ,
150
+ fraction = fraction
148
151
)
149
152
check_error_save_final_model (error , facade , output_path , verbose_f )
150
153
@@ -161,6 +164,7 @@ def run(task, model_path, output_path, verbose, objective=None):
161
164
args1 = verbose ,
162
165
args2 = None ,
163
166
objective = objective ,
167
+ fraction = fraction
164
168
)
165
169
check_error_save_final_model (error , facade , output_path , verbose_f )
166
170
@@ -192,14 +196,14 @@ def read_input():
192
196
)
193
197
parser .add_argument (
194
198
"-i" ,
195
- dest = "inputfile " ,
199
+ dest = "input_file " ,
196
200
required = True ,
197
201
metavar = PARAM_INPUT_FILE ,
198
202
help = "Input metabolic model. Allowed file formats: .xml .json .yml" ,
199
203
)
200
204
parser .add_argument (
201
205
"-o" ,
202
- dest = "outputfile " ,
206
+ dest = "output_file " ,
203
207
metavar = PARAM_OUTPUT_FILE ,
204
208
help = "Output spreadsheet file with results. Allowed file formats: .xls .xlsx .ods" ,
205
209
)
@@ -211,51 +215,52 @@ def read_input():
211
215
)
212
216
parser .add_argument (
213
217
"-swD" ,
214
- dest = "modelwodem " ,
218
+ dest = "model_remove_dem " ,
215
219
metavar = PARAM_OUTPUT_FILE ,
216
220
help = "Save output model without Dead End Metabolites. Allowed file formats: .xml .json .yml" ,
217
221
)
218
222
parser .add_argument (
219
223
"-sF" ,
220
- dest = "modelfva " ,
224
+ dest = "model_fva " ,
221
225
metavar = PARAM_OUTPUT_FILE ,
222
- help = "Save output model with reactions bounds updated with Flux Variability Analysis. Allowed file formats: .xml .json .yml" ,
226
+ help = "Save output model with reactions bounds updated with Flux Variability Analysis. Allowed file formats: "
227
+ ".xml .json .yml" ,
223
228
)
224
229
parser .add_argument (
225
230
"-swDF" ,
226
- dest = "modelfvawodem " ,
231
+ dest = "model_fva_remove_dem " ,
227
232
metavar = PARAM_OUTPUT_FILE ,
228
- help = "Save output model with reactions bounds updated with Flux Variability Analysis and without Dead End Metabolites. Allowed file formats: .xml .json .yml" ,
233
+ help = "Save output model with reactions bounds updated with Flux Variability Analysis and without Dead End "
234
+ "Metabolites. Allowed file formats: .xml .json .yml" ,
229
235
)
230
236
parser .add_argument (
231
237
"-objective" ,
232
238
dest = "objective" ,
233
239
metavar = PARAM_REACTION_ID ,
234
240
help = "Reaction id to be used as objective function with Flux Balance Analysis" ,
235
241
)
242
+ parser .add_argument (
243
+ "-fraction" ,
244
+ dest = "fraction" ,
245
+ metavar = PARAM_FRACTION ,
246
+ help = "Fraction of optimum growth to be used in Flux Balance Analysis. Value must be beetwen 0.0 and 1.0" ,
247
+ )
236
248
237
249
args = parser .parse_args ()
238
250
239
- input_file = args .inputfile
240
- output = args .outputfile
241
- cp = args .cp
242
- modelwodem = args .modelwodem
243
- modelfva = args .modelfva
244
- modelfvawodem = args .modelfvawodem
245
- objective = args .objective
246
-
247
- return (
248
- input_file ,
249
- output ,
250
- cp ,
251
- modelwodem ,
252
- modelfva ,
253
- modelfvawodem ,
254
- args .verbose ,
255
- objective ,
256
- args .license ,
257
- )
251
+ params = {}
252
+ params ["input_file" ] = args .input_file
253
+ params ["output" ] = args .output_file
254
+ params ["cp" ] = args .cp
255
+ params ["model_remove_dem" ] = args .model_remove_dem
256
+ params ["model_fva" ] = args .model_fva
257
+ params ["model_fva_remove_dem" ] = args .model_fva_remove_dem
258
+ params ["objective" ] = args .objective
259
+ params ["verbose" ] = args .verbose
260
+ params ["license" ] = args .license
261
+ params ["fraction" ] = args .fraction
258
262
263
+ return params
259
264
260
265
def __check_model_file (path ):
261
266
if path [- 4 :] != ".xml" and path [- 5 :] != ".json" and path [- 4 :] != ".yml" :
@@ -320,24 +325,38 @@ def validate_operation_selected(list_of_possible_operations):
320
325
print (MSG_FURTHER_INFO )
321
326
exit (1 )
322
327
328
+ def validate_number (parameter ):
329
+ try :
330
+ parameter = float (parameter )
331
+ except :
332
+ print ("Error: parameter 'fraction' must be a decimal number beetwen 0.0 and 1.0" )
333
+ exit (1 )
334
+ return parameter
323
335
324
336
#
325
337
# Main cli workflow
326
338
# Input is read, validated and each task executed independently
327
339
#
328
340
def main ():
329
341
# Read input
330
- (
331
- input_file ,
332
- output ,
333
- cp ,
334
- modelwodem ,
335
- modelfva ,
336
- modelfvawodem ,
337
- verbose ,
338
- objective ,
339
- license ,
340
- ) = read_input ()
342
+ params = read_input ()
343
+ input_file = params ["input_file" ]
344
+ output_file = params ["output" ]
345
+ cp = params ["cp" ]
346
+ model_remove_dem = params ["model_remove_dem" ]
347
+ model_fva = params ["model_fva" ]
348
+ model_fva_remove_dem = params ["model_fva_remove_dem" ]
349
+ objective = params ["objective" ]
350
+ verbose = params ["verbose" ]
351
+ license = params ["license" ]
352
+ fraction = params ["fraction" ]
353
+
354
+ # Default values
355
+ if fraction is None :
356
+ fraction = 1.0
357
+ fraction = validate_number (fraction )
358
+
359
+
341
360
342
361
# Operations that dont requiere validation
343
362
if license :
@@ -346,11 +365,11 @@ def main():
346
365
# Note that the following save the outputh path of each operation
347
366
# If the variable is None, no operation that operation has not been selected
348
367
NEW_MODEL_OPERATIONS = [
349
- modelwodem ,
350
- modelfva ,
351
- modelfvawodem ,
368
+ model_remove_dem ,
369
+ model_fva ,
370
+ model_fva_remove_dem ,
352
371
] # Tasks that generate new models
353
- NEW_SPREADSHEET_OPS = [output , cp ] # Tasks that generate spreadsheet files
372
+ NEW_SPREADSHEET_OPS = [output_file , cp ] # Tasks that generate spreadsheet files
354
373
355
374
# Check input file formats and task
356
375
validate_input_model (input_file )
@@ -359,30 +378,30 @@ def main():
359
378
validate_operation_selected (NEW_MODEL_OPERATIONS + NEW_SPREADSHEET_OPS )
360
379
361
380
# Run task
362
- if output is not None :
363
- task = TASK_SPREADSHEET
364
- out_path = output
365
- run (task , input_file , out_path , verbose , objective )
381
+ if output_file is not None :
382
+ task = TASK_CRITICAL_REACTIONS
383
+ out_path = output_file
384
+ run (task , input_file , out_path , verbose , objective , fraction )
366
385
367
386
if cp is not None :
368
387
task = TASK_SENSIBILITY
369
388
out_path = cp
370
- run (task , input_file , out_path , verbose , objective )
389
+ run (task , input_file , out_path , verbose , objective , fraction )
371
390
372
- if modelwodem is not None :
391
+ if model_remove_dem is not None :
373
392
task = TASK_SAVE_WITHOUT_DEM
374
- out_path = modelwodem
375
- run (task , input_file , out_path , verbose , objective )
393
+ out_path = model_remove_dem
394
+ run (task , input_file , out_path , verbose , objective , fraction )
376
395
377
- if modelfva is not None :
396
+ if model_fva is not None :
378
397
task = TASK_SAVE_WITH_FVA
379
- out_path = modelfva
380
- run (task , input_file , out_path , verbose , objective )
398
+ out_path = model_fva
399
+ run (task , input_file , out_path , verbose , objective , fraction )
381
400
382
- if modelfvawodem is not None :
401
+ if model_fva_remove_dem is not None :
383
402
task = TASK_SAVE_WITH_FVA_DEM
384
- out_path = modelfvawodem
385
- run (task , input_file , out_path , verbose , objective )
403
+ out_path = model_fva_remove_dem
404
+ run (task , input_file , out_path , verbose , objective , fraction )
386
405
387
406
388
407
if __name__ == "__main__" :
0 commit comments