Example #1
0
    def predict_pathways(self, product, hosts, database, aerobic=True):
        """Predict production routes for a desired product and host spectrum.
        Parameters
        ----------
        product : str or Metabolite
            The desired product.
        hosts : list
            A list of hosts (e.g. cameo.api.hosts), models, mixture thereof, or a single model or host.
        database: Model
            A model to use as database. See also: cameo.models.universal
        aerobic: bool
            If True, it will set `model.reactions.EX_o2_e.lower_bound` to 0.

        Returns
        -------
        dict
            ([Host, Model] -> PredictedPathways)
        """
        pathways = dict()
        product = self.__translate_product_to_universal_reactions_model_metabolite(
            product, database)
        for host in hosts:
            logging.debug('Processing host {}'.format(host.name))
            if isinstance(host, Model):
                host = Host(name='UNKNOWN_HOST', models=[host])
            for model in list(host.models):
                with model:
                    if not aerobic and "EX_o2_e" in model.reactions:
                        model.reactions.EX_o2_e.lower_bound = 0
                    identifier = searching()
                    logging.debug('Processing model {} for host {}'.format(
                        model.id, host.name))
                    notice(
                        'Predicting pathways for product %s in %s (using model %s).'
                        % (product.name, host, model.id))
                    logging.debug('Predicting pathways for model {}'.format(
                        model.id))
                    pathway_predictor = pathway_prediction.PathwayPredictor(
                        model, universal_model=database)
                    predicted_pathways = pathway_predictor.run(
                        product,
                        max_predictions=self.options.max_pathway_predictions,
                        timeout=self.options.pathway_prediction_timeout,
                        silent=not self.options.verbose)
                    stop_loader(identifier)
                    pathways[(host, model)] = predicted_pathways
                    self.__display_pathways_information(
                        predicted_pathways, host, model)
        return pathways
Example #2
0
    def predict_pathways(
            self,
            product,
            hosts=None,
            database=None):  # TODO: make this work with a single host or model
        """Predict production routes for a desired product and host spectrum.
        Parameters
        ----------
        product : str or Metabolite
            The desired product.
        hosts : list or Model or Host
            A list of hosts (e.g. cameo.api.hosts), models, mixture thereof, or a single model or host.

        Returns
        -------
        dict
            ...
        """
        pathways = dict()
        product = self.__translate_product_to_universal_reactions_model_metabolite(
            product, database)
        for host in hosts:
            logging.debug('Processing host {}'.format(host.name))
            if isinstance(host, Model):
                host = Host(name='UNKNOWN_HOST', models=[host])
            for model in list(host.models):
                identifier = searching()
                logging.debug('Processing model {} for host {}'.format(
                    model.id, host.name))
                notice(
                    'Predicting pathways for product %s in %s (using model %s).'
                    % (product.name, host, model.id))
                logging.debug('Predicting pathways for model {}'.format(
                    model.id))
                pathway_predictor = pathway_prediction.PathwayPredictor(
                    model,
                    universal_model=database,
                    compartment_regexp=re.compile(".*_c$"))
                # TODO adjust these numbers to something reasonable
                predicted_pathways = pathway_predictor.run(product,
                                                           max_predictions=4,
                                                           timeout=3 * 60,
                                                           silent=True)
                stop_loader(identifier)
                pathways[(host, model)] = predicted_pathways
                self.__display_pathways_information(predicted_pathways, host,
                                                    model)
        return pathways
Example #3
0
def test_api():
    mock_host = Host('core',
                     models=['e_coli_core'],
                     biomass=['BIOMASS_Ecoli_core_w_GAM'],
                     carbon_sources=['EX_glc__D_e'])

    api.design.debug = True
    pathways = api.design.predict_pathways(
        product=UNIVERSALMODEL.metabolites.ser__L_c,
        hosts=[mock_host],
        database=UNIVERSALMODEL,
        aerobic=True)
    optimization_reports = api.design.optimize_strains(pathways,
                                                       config.default_view,
                                                       aerobic=True)
    assert len(optimization_reports) > 0
Example #4
0
    def predict_pathways(self,
                         product,
                         hosts=None,
                         database=None,
                         aerobic=True):
        """Predict production routes for a desired product and host spectrum.
        Parameters
        ----------
        product : str or Metabolite
            The desired product.
        hosts : list or Model or Host
            A list of hosts (e.g. cameo.api.hosts), models, mixture thereof, or a single model or host.
        database: SolverBasedModel
            A model to use as database. See also: cameo.models.universal
        aerobic: bool
            If True, it will set `model.reactions.EX_o2_e.lower_bound` to 0.

        Returns
        -------
        dict
            ([Host, Model] -> PredictedPathways)
        """
        max_predictions = 8
        timeout = 3 * 60

        pathways = dict()
        product = self.__translate_product_to_universal_reactions_model_metabolite(
            product, database)
        for host in hosts:
            logging.debug('Processing host {}'.format(host.name))
            if isinstance(host, Model):
                host = Host(name='UNKNOWN_HOST', models=[host])
            for model in list(host.models):
                with TimeMachine() as tm:
                    if not aerobic and "EX_o2_e" in model.reactions:
                        model.reactions.EX_o2_e.change_bounds(lb=0,
                                                              time_machin=tm)
                    identifier = searching()
                    logging.debug('Processing model {} for host {}'.format(
                        model.id, host.name))
                    notice(
                        'Predicting pathways for product %s in %s (using model %s).'
                        % (product.name, host, model.id))
                    logging.debug('Predicting pathways for model {}'.format(
                        model.id))
                    pathway_predictor = pathway_prediction.PathwayPredictor(
                        model,
                        universal_model=database,
                        compartment_regexp=re.compile(".*_c$"))

                    if self.debug:
                        max_predictions = 2
                        timeout = 60

                    predicted_pathways = pathway_predictor.run(
                        product,
                        max_predictions=max_predictions,
                        timeout=timeout,
                        silent=True)
                    stop_loader(identifier)
                    pathways[(host, model)] = predicted_pathways
                    self.__display_pathways_information(
                        predicted_pathways, host, model)
        return pathways