Beispiel #1
0
 def optimize_PCR_parameters(self, seq_files, product_bounds, 
                             parameters, seq_id=None):
     self._optimized = False
     if seq_id is None: seq_id = 0
     #prepare parameters and matchers
     if not (seq_files and product_bounds and parameters): return False
     if not self._find_matches(seq_files, seq_id): return False
     self._prepare_parameters(product_bounds, parameters)
     #optimize parameters
     print ''
     optimum, _unused, info = fmin_l_bfgs_b(self._objective_function, 
                                            self._iparams,
                                            self._objective_function_grad, 
                                            approx_grad=False, 
                                            bounds=self._ibounds, factr=1e12,
                                            maxfun=self._max_steps, disp=1)
     if self._last_mixture: cleanup_file(self._last_mixture)
     #parse results
     if info['warnflag'] == 2:
         self._exit_status = info['task']
     elif info['warnflag'] == 1:
         self._exit_status = ('Number of simulations has '
                              'exceeded defined limit: %d') % info['funcalls']
     else: self._optimized = True
     #save results
     self._optimum       = optimum
     self._named_optimum = self._name_parameters(self._optimum)
     #simulate PCR at optimum
     ovc, mixture = self._prepare_simulation(self._optimum)
     if ovc is None: return False
     self._PCR_Simulation = self._new_PCR_Simulation()
     self._PCR_Simulation.add_mixture(self._seq_name, mixture)
     self._PCR_Simulation.run(WorkCounter())
     self._have_results = bool(self._PCR_Simulation)
     return self._have_results
Beispiel #2
0
 def _objective_function(self, parameters):
     self._last_parameters = parameters
     ovc, mixture = self._prepare_simulation(parameters)
     if ovc is None: return -1e32 #FIXME: end search process if aborted
     if self._last_mixture: cleanup_file(self._last_mixture)
     self._last_mixture = mixture
     self._last_OV = ovc(mixture)
     return self._last_OV
Beispiel #3
0
 def _objective_function(self, parameters):
     self._last_parameters = parameters
     ovc, mixture = self._prepare_simulation(parameters)
     if ovc is None: return -1e32  #FIXME: end search process if aborted
     if self._last_mixture: cleanup_file(self._last_mixture)
     self._last_mixture = mixture
     self._last_OV = ovc(mixture)
     return self._last_OV
Beispiel #4
0
 def optimize_PCR_parameters(self,
                             seq_files,
                             product_bounds,
                             parameters,
                             seq_id=None):
     self._optimized = False
     if seq_id is None: seq_id = 0
     #prepare parameters and matchers
     if not (seq_files and product_bounds and parameters): return False
     if not self._find_matches(seq_files, seq_id): return False
     self._prepare_parameters(product_bounds, parameters)
     #optimize parameters
     print ''
     optimum, _unused, info = fmin_l_bfgs_b(self._objective_function,
                                            self._iparams,
                                            self._objective_function_grad,
                                            approx_grad=False,
                                            bounds=self._ibounds,
                                            factr=1e12,
                                            maxfun=self._max_steps,
                                            disp=1)
     if self._last_mixture: cleanup_file(self._last_mixture)
     #parse results
     if info['warnflag'] == 2:
         self._exit_status = info['task']
     elif info['warnflag'] == 1:
         self._exit_status = (
             'Number of simulations has '
             'exceeded defined limit: %d') % info['funcalls']
     else:
         self._optimized = True
     #save results
     self._optimum = optimum
     self._named_optimum = self._name_parameters(self._optimum)
     #simulate PCR at optimum
     ovc, mixture = self._prepare_simulation(self._optimum)
     if ovc is None: return False
     self._PCR_Simulation = self._new_PCR_Simulation()
     self._PCR_Simulation.add_mixture(self._seq_name, mixture)
     self._PCR_Simulation.run(WorkCounter())
     self._have_results = bool(self._PCR_Simulation)
     return self._have_results