Ejemplo n.º 1
0
    def __init__(self,
                 cofactor_id_swaps=NADH_NADPH,
                 candidate_reactions=None,
                 skip_reactions=None,
                 *args,
                 **kwargs):
        super(CofactorSwapOptimization, self).__init__(*args, **kwargs)
        self._target_type = SWAP_TYPE
        swap_pairs = ([
            self.model.metabolites.get_by_id(m) for m in cofactor_id_swaps[0]
        ], [self.model.metabolites.get_by_id(m) for m in cofactor_id_swaps[1]])
        self.metadata['swap_pairs'] = swap_pairs
        self.representation = candidate_reactions or self.find_swappable_reactions(
            self.model, swap_pairs)
        if skip_reactions:
            self.representation -= skip_reactions
        self._decoder = decoders.ReactionSetDecoder(self.representation,
                                                    self.model)

        self._evaluator = evaluators.SwapEvaluator(
            model=self.model,
            decoder=self._decoder,
            objective_function=self.objective_function,
            simulation_method=self._simulation_method,
            simulation_kwargs=self._simulation_kwargs,
            swap_pair=swap_pairs)
Ejemplo n.º 2
0
    def __init__(self,
                 reactions=None,
                 essential_reactions=None,
                 use_nullspace_simplification=True,
                 *args,
                 **kwargs):
        super(ReactionKnockoutOptimization, self).__init__(*args, **kwargs)
        if reactions is None:
            self.reactions = set([r.id for r in self.model.reactions])
        else:
            self.reactions = reactions
        logger.debug("Computing essential reactions...")
        if essential_reactions is None:
            self.essential_reactions = set(
                r.id
                for r in find_essential_reactions(self.model, processes=1))
        else:
            self.essential_reactions = set([
                r.id for r in find_essential_reactions(self.model, processes=1)
            ])
            self.essential_reactions.update(essential_reactions)

        if use_nullspace_simplification:
            ns = nullspace(create_stoichiometric_array(self.model))
            dead_ends = set(find_blocked_reactions_nullspace(self.model,
                                                             ns=ns))
            exchanges = set(self.model.boundary)
            reactions = [
                r for r in self.model.reactions
                if (r not in exchanges) and (r not in dead_ends) and (
                    r.id not in self.essential_reactions)
            ]

            groups = find_coupled_reactions_nullspace(self.model, ns=ns)
            groups_keys = [
                set(group) for group in groups
                if any(r.id in reactions for r in group)
            ]
            reduced_set = reduce_reaction_set(reactions, groups_keys)
            to_keep = [r.id for r in reduced_set]

        else:
            groups = None
            to_keep = set(r.id for r in self.model.reactions)
            to_keep.difference_update(r.id for r in self.model.boundary)
            to_keep.difference_update(self.essential_reactions)
            to_keep = list(to_keep)

        self.representation = to_keep
        self._target_type = REACTION_KNOCKOUT_TYPE
        self._decoder = decoders.ReactionSetDecoder(self.representation,
                                                    self.model,
                                                    groups=groups)
        self._evaluator = evaluators.KnockoutEvaluator(
            model=self.model,
            decoder=self._decoder,
            objective_function=self.objective_function,
            simulation_method=self._simulation_method,
            simulation_kwargs=self._simulation_kwargs)
Ejemplo n.º 3
0
    def __init__(self, reactions=None, essential_reactions=None, *args, **kwargs):
        super(ReactionKnockoutOptimization, self).__init__(*args, **kwargs)
        if reactions is None:
            self.reactions = set([r.id for r in self.model.reactions])
        else:
            self.reactions = reactions
        logger.debug("Computing essential reactions...")
        if essential_reactions is None:
            self.essential_reactions = set([r.id for r in self.model.essential_reactions()])
        else:
            self.essential_reactions = set([r.id for r in self.model.essential_reactions()] + essential_reactions)

        exchange_reactions = set([r.id for r in self.model.exchanges])
        self.representation = list(self.reactions.difference(self.essential_reactions).difference(exchange_reactions))
        self._target_type = REACTION_KNOCKOUT_TYPE
        self._decoder = decoders.ReactionSetDecoder(self.representation, self.model)
        self._evaluator = evaluators.KnockoutEvaluator(model=self.model,
                                                       decoder=self._decoder,
                                                       objective_function=self.objective_function,
                                                       simulation_method=self._simulation_method,
                                                       simulation_kwargs=self._simulation_kwargs)