"max_flux": 1e6, "flux_penalty_dict": {}, "verbose": True, "flux_weight": 0.0, "label_unfeasible_penalty": 1, "flux_unfeasible_penalty": 10 } iso2flux_problem = define_isoflux_problem(label_model) optimal_solution, optimal_variables = optimize( label_model, iso2flux_problem, pop_size=pop_size, n_gen=n_gen, n_islands=number_of_processes, max_cycles_without_improvement=max_cycles_without_improvement, stop_criteria_relative=0.01, initial_archi_x=[], lb_list=[], ub_list=[], max_flux=1e6, label_problem_parameters=label_problem_parameters) label_model.best_chi2 = optimal_solution flux_sd_dict, hessian, inverse_hessian, covariance = get_std_deviation( label_model, optimal_variables, initial_step=1e-3) export_flux_results(label_model, optimal_variables, fn=output_prefix + "_fluxes.csv",
else: print "loading "+flux_penalty_file flux_penalty_dict=read_flux_penalty_dict_from_file(flux_penalty_file) iso2flux_problem=define_isoflux_problem(label_model) #Get the best fit from iso2flux model, if does not exist run a simulation to get it if relative_tolerance: if label_model.best_label_variables!=None: best_label_variables=label_model.best_label_variables a,objective_dict=objfunc(label_model,best_label_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) else: label_problem_parameters={"label_weight":1,"target_flux_dict":None,"max_chi":1e6,"max_flux":1e6,"flux_penalty_dict":{},"verbose":True,"flux_weight":0.0,"label_unfeasible_penalty":1.0,"flux_unfeasible_penalty":10} best_objective,best_label_variables=optimize(label_model,iso2flux_problem,pop_size ,n_gen ,n_islands=number_of_processes,max_evolve_cycles=999,max_cycles_without_improvement=9,stop_criteria_relative=0.0005,stop_criteria_absolute=-1e6,initial_archi_x=[],lb_list=[],ub_list=[],flux_penalty_dict=None,max_flux=None,label_problem_parameters=label_problem_parameters,min_model=None,extra_constraint_dict={}) label_model.best_label_variables=best_label_variables a,objective_dict=objfunc(label_model,best_label_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) max_chi=objective_dict["chi2_score"]+objective_tolerance else: max_chi=objective_tolerance if initial_flux_estimation==None: if label_model.best_p13cmfa_variables!=None: a,objective_dict=objfunc(label_model,label_model.best_p13cmfa_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) initial_flux_estimation=objective_dict["flux_score"] elif label_model.best_label_variables!=None: a,objective_dict=objfunc(label_model,best_label_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) initial_flux_estimation=objective_dict["flux_score"]
else: print "loading "+flux_penalty_file flux_penalty_dict=read_flux_penalty_dict_from_file(flux_penalty_file) iso2flux_problem=define_isoflux_problem(label_model) #Get the best fit from iso2flux model, if does not exist run a simulation to get it if relative_tolerance: if label_model.best_label_variables!=None: best_label_variables=label_model.best_label_variables a,objective_dict=objfunc(label_model,best_label_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) else: label_problem_parameters={"label_weight":1,"target_flux_dict":None,"max_chi":1e6,"max_flux":1e6,"flux_penalty_dict":{},"verbose":True,"flux_weight":0.0,"label_unfeasible_penalty":1.0,"flux_unfeasible_penalty":10} best_objective,best_label_variables=optimize(label_model,iso2flux_problem,pop_size ,n_gen ,n_islands=number_of_processes,max_evolve_cycles=999,max_cycles_without_improvement=9,stop_criteria_relative=0.0005,stop_criteria_absolute=-1e6,initial_archi_x=[],lb_list=[],ub_list=[],flux_penalty_dict=None,max_flux=None,label_problem_parameters=label_problem_parameters,min_model=None,extra_constraint_dict={}) label_model.best_label_variables=list(best_label_variables) a,objective_dict=objfunc(label_model,best_label_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) max_chi=objective_dict["chi2_score"]+objective_tolerance else: max_chi=objective_tolerance if initial_flux_estimation==None: if label_model.best_p13cmfa_variables!=None: a,objective_dict=objfunc(label_model,label_model.best_p13cmfa_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) initial_flux_estimation=objective_dict["flux_score"] elif label_model.best_label_variables!=None: a,objective_dict=objfunc(label_model,best_label_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1) initial_flux_estimation=objective_dict["flux_score"]
objfunc(label_model,x) #check_simulated_fractions(label_model) passed_flag=check_steady_state(label_model,only_initial_m0=True,threshold=1e-6,precision=10,fn=output_name+"_validation.txt",fn_mode="w") if passed_flag==False: "Summary saved in "+output_name+"_validation.txt" break if passed_flag==True: print "Validation passed" sys.exit(2) label_problem_parameters={"label_weight":1,"target_flux_dict":None,"max_chi":1e6,"max_flux":1e6,"flux_penalty_dict":{},"verbose":True,"flux_weight":0.0,"label_unfeasible_penalty":1,"flux_unfeasible_penalty":10} iso2flux_problem=define_isoflux_problem(label_model) optimal_solution,optimal_variables=optimize(label_model,iso2flux_problem,pop_size = pop_size,n_gen = n_gen,n_islands=number_of_processes ,max_cycles_without_improvement=max_cycles_without_improvement,stop_criteria_relative=0.01,initial_archi_x=[],lb_list=[],ub_list=[],max_flux=1e6,label_problem_parameters=label_problem_parameters) label_model.best_chi2=optimal_solution flux_sd_dict, hessian,inverse_hessian,covariance=get_std_deviation(label_model,optimal_variables,initial_step=1e-3) export_flux_results(label_model,optimal_variables,fn=output_prefix+"_fluxes.csv",flux_sd_dict=flux_sd_dict) objfunc(label_model,optimal_variables) export_label_results(label_model,fn=output_prefix+"_label.csv",show_chi=True,show_emu=False,show_fluxes=False) np.savetxt(output_prefix+"_variables.txt",optimal_variables) reference_parameters=[optimal_variables] label_model.best_label_variables=optimal_variables save_iso2flux_model(label_model,name=output_prefix+".iso2flux",write_sbml=True,ask_sbml_name=False,gui=False) if not compute_intervals: output_model=label_model.constrained_model.copy()