def test_one_variable_parallel(self): ppp = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_'], view=MultiprocessingView()) assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore) ppp = phenotypic_phase_plane(self.model, 'EX_o2_LPAREN_e_RPAREN_', view=MultiprocessingView()) assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore)
def test_one_variable_sequential(self): ppp = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_'], view=SequentialView()) assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore) ppp = phenotypic_phase_plane(self.model, 'EX_o2_LPAREN_e_RPAREN_', view=SequentialView()) assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore)
def test_one_variable_sequential_yield(self, core_model): ppp = phenotypic_phase_plane(core_model, ['EX_o2_LPAREN_e_RPAREN_'], view=SequentialView()) assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_']) ppp = phenotypic_phase_plane(core_model, 'EX_o2_LPAREN_e_RPAREN_', view=SequentialView()) assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
def plot(self, plotter, index=0, grid=None, width=None, height=None, title=None, palette=None, **kwargs): wt_production = phenotypic_phase_plane(self._model, objective=self._target, variables=[self._biomass]) with self._model: for ko in self.data_frame.loc[index, "reactions"]: swap_cofactors(self._model.reactions.get_by_id(ko), self._model, self._swap_pairs) mt_production = phenotypic_phase_plane(self._model, objective=self._target, variables=[self._biomass]) if title is None: title = "Production Envelope" dataframe = DataFrame(columns=["ub", "lb", "value", "strain"]) for _, row in wt_production.iterrows(): _df = DataFrame([[ row['objective_upper_bound'], row['objective_lower_bound'], row[self._biomass.id], "WT" ]], columns=dataframe.columns) dataframe = dataframe.append(_df) for _, row in mt_production.iterrows(): _df = DataFrame([[ row['objective_upper_bound'], row['objective_lower_bound'], row[self._biomass.id], "MT" ]], columns=dataframe.columns) dataframe = dataframe.append(_df) plot = plotter.production_envelope(dataframe, grid=grid, width=width, height=height, title=title, x_axis_label=self._biomass.id, y_axis_label=self._target.id, palette=palette) plotter.display(plot)
def _init_search_grid(self, surface_only=False, improvements_only=True): """Initialize the grid of points to be scanned within the production envelope.""" self.envelope = phenotypic_phase_plane( self.design_space_model, self.variables, objective=self.objective, points=self.points) intervals = self.envelope[['objective_lower_bound', 'objective_upper_bound']].copy() intervals['objective_lower_bound'] = float_floor(intervals.objective_lower_bound, ndecimals) intervals['objective_upper_bound'] = float_ceil(intervals.objective_upper_bound, ndecimals) max_distance = 0. max_interval = None for i, (lb, ub) in intervals.iterrows(): distance = abs(ub - lb) if distance > max_distance: max_distance = distance max_interval = (lb, ub) step_size = (max_interval[1] - max_interval[0]) / (self.points - 1) grid = list() minimal_reference_production = self.reference_flux_ranges['lower_bound'][self.objective] for i, row in self.envelope.iterrows(): variables = row[self.variables] lb = row.objective_lower_bound if improvements_only: lb = max(lb, minimal_reference_production) + step_size ub = row.objective_upper_bound if not surface_only: coordinate = lb while coordinate < ub: grid.append(list(variables.values) + [coordinate]) coordinate += step_size if improvements_only and ub <= minimal_reference_production: continue else: grid.append(list(variables.values) + [ub]) columns = self.variables + [self.objective] self.grid = DataFrame(grid, columns=columns)
def _init_search_grid(self, surface_only=False, improvements_only=True): """Initialize the grid of points to be scanned within the production envelope.""" self.envelope = phenotypic_phase_plane( self.design_space_model, self.variables, objective=self.objective, points=self.points) intervals = self.envelope[['objective_lower_bound', 'objective_upper_bound']].copy() intervals['objective_lower_bound'] = float_floor(intervals.objective_lower_bound, ndecimals) intervals['objective_upper_bound'] = float_ceil(intervals.objective_upper_bound, ndecimals) max_distance = 0. max_interval = None for i, (lb, ub) in intervals.iterrows(): distance = abs(ub - lb) if distance > max_distance: max_distance = distance max_interval = (lb, ub) step_size = (max_interval[1] - max_interval[0]) / (self.points - 1) grid = list() minimal_reference_production = self.reference_flux_ranges['lower_bound'][self.objective] for i, row in self.envelope.iterrows(): variables = row[self.variables] lb = row.objective_lower_bound if improvements_only: lb = max(lb, minimal_reference_production) + step_size ub = row.objective_upper_bound if not surface_only: coordinate = lb while coordinate < ub: grid.append(list(variables.values) + [coordinate]) coordinate += step_size if improvements_only and ub <= minimal_reference_production: continue else: grid.append(list(variables.values) + [ub]) columns = self.variables + [self.objective] self.grid = DataFrame(grid, columns=columns)
def test_two_variables_sequential(self, core_model): ppp2d = phenotypic_phase_plane( core_model, ['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'], view=SequentialView()) assert_data_frames_equal( ppp2d, REFERENCE_PPP_o2_glc_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'])
def test_ppp_plotly(model): """Test if at least it doesn't raise an exception.""" production_envelope = phenotypic_phase_plane( model, variables=[ model.reactions.Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2 ], objective=model.metabolites.succ_e, ) # pass a grid argument so that it doesn't open a browser tab production_envelope.plot(plotter, height=400, grid=[])
def plot(self, index=0, grid=None, width=None, height=None, title=None, palette=None, **kwargs): wt_production = phenotypic_phase_plane(self._model, objective=self._target, variables=[self._biomass.id]) with TimeMachine() as tm: for ko in self.data_frame.loc[index, "reactions"]: self._model.reactions.get_by_id(ko).knock_out(tm) mt_production = phenotypic_phase_plane(self._model, objective=self._target, variables=[self._biomass.id]) if title is None: title = "Production Envelope" dataframe = DataFrame(columns=["ub", "lb", "value", "strain"]) for _, row in wt_production.iterrows(): _df = DataFrame([[row['objective_upper_bound'], row['objective_lower_bound'], row[self._biomass.id], "WT"]], columns=dataframe.columns) dataframe = dataframe.append(_df) for _, row in mt_production.iterrows(): _df = DataFrame([[row['objective_upper_bound'], row['objective_lower_bound'], row[self._biomass.id], "MT"]], columns=dataframe.columns) dataframe = dataframe.append(_df) plot = plotter.production_envelope(dataframe, grid=grid, width=width, height=height, title=title, x_axis_label=self._biomass.id, y_axis_label=self._target, palette=palette) plotter.display(plot)
def test_one_variable_sequential_metabolite(self): ppp = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_'], self.model.metabolites.o2_c, view=SequentialView()) assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore)
def test_two_variables_sequential(self): ppp2d = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'], view=SequentialView()) assert_dataframes_equal(ppp2d, REFERENCE_PPP_o2_glc_EcoliCore)
def test_two_variables_parallel(self): ppp2d = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'], view=MultiprocessingView()) assert_dataframes_equal(ppp2d, REFERENCE_PPP_o2_glc_EcoliCore)
def test_one_variable_sequential_metabolite(self, core_model): ppp = phenotypic_phase_plane(core_model, ['EX_o2_LPAREN_e_RPAREN_'], core_model.metabolites.ac_c, view=SequentialView()) assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore_ac, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
def test_one_variable_parallel(self, core_model): ppp = phenotypic_phase_plane(core_model, ['EX_o2_LPAREN_e_RPAREN_'], view=MultiprocessingView()) assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_']) ppp = phenotypic_phase_plane(core_model, 'EX_o2_LPAREN_e_RPAREN_', view=MultiprocessingView()) assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
def test_one_variable_sequential_metabolite(self): ppp = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_'], self.model.metabolites.ac_c, view=SequentialView()) assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore_ac, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
def test_two_variables_parallel(self): ppp2d = phenotypic_phase_plane(self.model, ['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'], view=MultiprocessingView()) assert_data_frames_equal(ppp2d, REFERENCE_PPP_o2_glc_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'])