ask_sbml_name=False,
                        gui=False)
    #sys.exit(2)
else:
    lb_list, ub_list = get_variable_bounds(label_model,
                                           flux_penalty_dict={},
                                           max_flux=1e6)
    sampled_variables = variable_sampling(label_model,
                                          lb_list,
                                          ub_list,
                                          maximum_flux=1e6,
                                          flux_penalty_dict={},
                                          n_pop=1000,
                                          n_processes=1)
    for x in sampled_variables:
        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 = {
Пример #2
0
                        name=output_name,
                        write_sbml=True,
                        ask_sbml_name=False,
                        gui=False)
    sys.exit(2)
else:
    lb_list, ub_list = get_variable_bounds(label_model,
                                           flux_penalty_dict={},
                                           max_flux=1e6)
    sampled_variables = variable_sampling(label_model,
                                          lb_list,
                                          ub_list,
                                          maximum_flux=1e6,
                                          flux_penalty_dict={},
                                          n_pop=1000,
                                          n_processes=1)
    for x in sampled_variables:
        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:
            print "Summary saved in " + output_name + "_validation.txt"
            break
    if passed_flag == True:
        print "Validation passed"
Пример #3
0
f=open(path_to_problem,"r")
problem_script=f.read()
f.close()
exec(problem_script)
label_model.iso2flux_problem=iso2flux_problem

"""

#Get the best fit from iso2flux model, if does not exist run a simulation to get it
reference_parameters=[]

if flux_penalty_dict not in (None,{}): 
   if label_model.best_p13cmfa_variables!=None: 
      reference_parameters.append(label_model.best_p13cmfa_variables)   
      best_variables=label_model.best_p13cmfa_variables
      a,objective_dict=objfunc(label_model,label_model.best_p13cmfa_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1)
   else:
     print "Relative tolerance with flux minimization requires having done p13cmfa"
     sys.exit(2)
   if label_model.best_label_variables!=None:
      best_variables=label_model.best_label_variables
      reference_parameters.append(best_variables)
   if relative_tolerance:
      a,objective_dict=objfunc(label_model,label_model.best_p13cmfa_variables,flux_penalty_dict=flux_penalty_dict,flux_weight=1)
      #max_chi=objective_dict["chi2_score"]/objective_tolerance
      max_chi=label_model.label_tolerance
      max_flux=objective_dict["flux_score"]+objective_tolerance
   else:
      max_chi=label_model.label_tolerance
      max_flux=objective_tolerance
else:
Пример #4
0
   except:
     raise Exception("Flux penalty for "+file_name+" "+default_name_flux_dict+" not found" )
     
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"]
Пример #5
0
if null_matrix==None:
   fname=output_name+"_nullmatrix.txt" #TODO allow to name it
   compute_nullmatrix(label_model,remove_inactive_reactions=True)
   #np.savetxt(fname, label_model.flux_solver_nullmnp)
else:
   compute_nullmatrix(label_model,remove_inactive_reactions=True,fname=null_matrix) 
   #label_model.flux_solver_nullmnp=np.loadtxt("nullmatrix.txt")

build_flux_solver_variables(label_model)

get_variables(label_model)

if not validate:
   flux_penalty_dict=build_flux_penalty_dict(label_model,base_penalty=1,fn=output_name+"_flux_penalty.csv")
   label_model.best_label_variables=None
   save_iso2flux_model(label_model,name=output_name,write_sbml=True,ask_sbml_name=False,gui=False)
   sys.exit(2)
else:
   lb_list,ub_list=get_variable_bounds(label_model,flux_penalty_dict={},max_flux=1e6)
   sampled_variables=variable_sampling(label_model,lb_list,ub_list,maximum_flux=1e6,flux_penalty_dict={},n_pop=1000,n_processes=1)
   for x in sampled_variables:
       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:
          print "Summary saved in "+output_name+"_validation.txt"
          break
   if passed_flag==True:
      print "Validation passed"

   #label_model.flux_solver_nullmnp=np.loadtxt("nullmatrix.txt")

build_flux_solver_variables(label_model)

get_variables(label_model)

if not validate:
   flux_penalty_dict=build_flux_penalty_dict(label_model,base_penalty=1,fn=output_name+"_flux_penalty.csv")
   label_model.best_label_variables=None
   save_iso2flux_model(label_model,name=output_name,write_sbml=True,ask_sbml_name=False,gui=False)
   #sys.exit(2)
else:
   lb_list,ub_list=get_variable_bounds(label_model,flux_penalty_dict={},max_flux=1e6)
   sampled_variables=variable_sampling(label_model,lb_list,ub_list,maximum_flux=1e6,flux_penalty_dict={},n_pop=1000,n_processes=1)
   for x in sampled_variables:
       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)