示例#1
0
def find_nonzero_constrained_reactions(model):
    """Return list of reactions with non-zero, non-maximal bounds."""
    lower_bound, upper_bound = helpers.find_bounds(model)
    return [
        rxn for rxn in model.reactions if 0 > rxn.lower_bound > lower_bound
        or 0 < rxn.upper_bound < upper_bound
    ]
示例#2
0
def find_unconstrained_reactions(model):
    """Return list of reactions that are not constrained at all."""
    lower_bound, upper_bound = helpers.find_bounds(model)
    return [
        rxn for rxn in model.reactions
        if rxn.lower_bound <= lower_bound and rxn.upper_bound >= upper_bound
    ]
示例#3
0
def is_constrained_reaction(model, rxn):
    """Return whether a reaction has fixed constraints."""
    lower_bound, upper_bound = helpers.find_bounds(model)
    if rxn.reversibility:
        return rxn.lower_bound > lower_bound or rxn.upper_bound < upper_bound
    else:
        return rxn.lower_bound > 0 or rxn.upper_bound < upper_bound
示例#4
0
def is_constrained_reaction(model, rxn):
    """Return whether a reaction has fixed constraints."""
    lower_bound, upper_bound = helpers.find_bounds(model)
    if rxn.reversibility:
        return rxn.lower_bound > lower_bound or rxn.upper_bound < upper_bound
    else:
        return rxn.lower_bound > 0 or rxn.upper_bound < upper_bound
示例#5
0
def find_blocked_biomass_precursors(reaction, model):
    """
    Return a list of all biomass precursors that cannot be produced.

    Parameters
    ----------
    reaction : cobra.core.reaction.Reaction
        The biomass reaction of the model under investigation.
    model : cobra.Model
        The metabolic model under investigation.

    Returns
    -------
    list
        Metabolite objects that are reactants of the biomass reaction excluding
        ATP and H2O that cannot be produced by flux balance analysis.

    """
    LOGGER.debug("Finding blocked biomass precursors")
    precursors = find_biomass_precursors(model, reaction)
    blocked_precursors = list()
    _, ub = helpers.find_bounds(model)
    for precursor in precursors:
        with model:
            dm_rxn = model.add_boundary(precursor,
                                        type="safe-demand",
                                        reaction_id="safe_demand",
                                        lb=0,
                                        ub=ub)
            flux = helpers.run_fba(model, dm_rxn.id, direction='max')
            if np.isnan(flux) or abs(flux) < 1E-08:
                blocked_precursors.append(precursor)
    return blocked_precursors
示例#6
0
def find_blocked_biomass_precursors(reaction, model):
    """
    Return a list of all biomass precursors that cannot be produced.

    Parameters
    ----------
    reaction : cobra.core.reaction.Reaction
        The biomass reaction of the model under investigation.
    model : cobra.Model
        The metabolic model under investigation.

    Returns
    -------
    list
        Metabolite objects that are reactants of the biomass reaction excluding
        ATP and H2O that cannot be produced by flux balance analysis.

    """
    LOGGER.debug("Finding blocked biomass precursors")
    precursors = find_biomass_precursors(model, reaction)
    blocked_precursors = list()
    _, ub = helpers.find_bounds(model)
    for precursor in precursors:
        with model:
            dm_rxn = model.add_boundary(
                precursor,
                type="safe-demand",
                reaction_id="safe_demand",
                lb=0,
                ub=ub
            )
            flux = helpers.run_fba(model, dm_rxn.id, direction='max')
            if np.isnan(flux) or abs(flux) < 1E-08:
                blocked_precursors.append(precursor)
    return blocked_precursors
示例#7
0
def find_reactions_with_unbounded_flux_default_condition(model):
    """
    Return list of reactions whose flux is unbounded in the default condition.

    Parameters
    ----------
    model : cobra.Model
        The metabolic model under investigation.

    Returns
    -------
    tuple
        list
            A list of reactions that in default modeling conditions are able to
            carry flux as high/low as the systems maximal and minimal bounds.
        float
            The fraction of the amount of unbounded reactions to the amount of
            non-blocked reactions.
        list
            A list of reactions that in default modeling conditions are not able
            to carry flux at all.

    """
    try:
        fva_result = flux_variability_analysis(model, fraction_of_optimum=1.0)
    except Infeasible as err:
        LOGGER.error("Failed to find reactions with unbounded flux "
                     "because '{}'. This may be a bug.".format(err))
        raise Infeasible("It was not possible to run flux variability "
                         "analysis on the model. Make sure that the model "
                         "can be solved! Check if the constraints are not "
                         "too strict.")
    # Per reaction (row) the flux is below threshold (close to zero).
    conditionally_blocked = fva_result.loc[fva_result.abs().max(
        axis=1) < TOLERANCE_THRESHOLD].index.tolist()
    small, large = helpers.find_bounds(model)
    # Find those reactions whose flux is close to or outside of the median
    # upper or lower bound, i.e., appears unconstrained.
    unlimited_flux = fva_result.loc[
        np.isclose(fva_result["maximum"], large, atol=TOLERANCE_THRESHOLD) |
        (fva_result["maximum"] > large)
        | np.isclose(fva_result["minimum"], small, atol=TOLERANCE_THRESHOLD) |
        (fva_result["minimum"] < small)].index.tolist()
    try:
        fraction = len(unlimited_flux) / \
            (len(model.reactions) - len(conditionally_blocked))
    except ZeroDivisionError:
        LOGGER.error("Division by Zero! Failed to calculate the "
                     "fraction of unbounded reactions. Does this model "
                     "have any reactions at all?")
        raise ZeroDivisionError("It was not possible to calculate the "
                                "fraction of unbounded reactions to "
                                "un-blocked reactions. This may be because"
                                "the model doesn't have any reactions at "
                                "all or that none of the reactions can "
                                "carry a flux larger than zero!")

    return unlimited_flux, fraction, conditionally_blocked
示例#8
0
def find_unconstrained_reactions(model):
    """Return list of reactions that are not constrained at all."""
    lower_bound, upper_bound = helpers.find_bounds(model)
    return [rxn for rxn in model.reactions if
            rxn.lower_bound <= lower_bound and
            rxn.upper_bound >= upper_bound]
示例#9
0
def find_nonzero_constrained_reactions(model):
    """Return list of reactions with non-zero, non-maximal bounds."""
    lower_bound, upper_bound = helpers.find_bounds(model)
    return [rxn for rxn in model.reactions if
            0 > rxn.lower_bound > lower_bound or
            0 < rxn.upper_bound < upper_bound]