Skip to content

Flux balance, flux variability, and parsimonious FBA

Flux balance analysis of a metabolic network.

  • Class: FluxBalanceSystem
  • Import: from skcomplex.systems.biology.systems_biology import FluxBalanceSystem
  • Field: biology/systems_biology
  • Topics: flux balance, linear program, metabolism, static
  • References:
    • Raman 2021
    • Orth et al. 2010

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.biology.systems_biology import FluxBalanceSystem

trajectory = FluxBalanceSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
network 'toy'
oxygen 1000.0
parsimonious False
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous, discrete, static
Space none
Laws equation
Randomness unknown
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class FluxBalanceSystem(BaseSystem):
    """Flux balance analysis of a metabolic network.

    It sets the fluxes of the network to maximise growth.

    The steady-state balances of the metabolites and the bounds of the reactions confine the fluxes, and the optimum of
    the growth flux sets them (Raman 2021, Section 8.6). The toy network of Table 8.2 reaches growth 50, set by the
    bound 1000 on `v6`. The E. coli core system needs the extra `metabolism`, and grows at 0.8739 h^-1 on glucose with
    oxygen and at 0.2117 h^-1 without.

    Args:
        network:
            `'toy'` for Raman's toy network or `'ecoli'` for the E. coli core system.

        oxygen:
            The largest oxygen uptake of the E. coli core system.

        parsimonious:
            Whether to minimise the total absolute flux after growth.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Raises:
        ValidationError:
            The network is unknown.

        MissingExtraError:
            The E. coli core system needs the extra, which is not installed.

    Examples:
        >>> from skcomplex.systems.biology.systems_biology import FluxBalanceSystem
        >>> trajectory = FluxBalanceSystem().prepare().simulate(until=0.0)
        >>> round(float(trajectory.get_values('cell.v_vbio')[0]), 6)
        50.0
    """

    field = 'biology/systems_biology'
    topics = ('flux balance', 'linear program', 'metabolism', 'static')
    references = ('Raman 2021', 'Orth et al. 2010')
    until = 0.0

    def __init__(
        self,
        network: str = 'toy',
        *,
        oxygen: float = 1000.0,
        parsimonious: bool = False,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.network = network
        self.oxygen = oxygen
        self.parsimonious = parsimonious

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of flux balance analysis of a metabolic network.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        if self.network not in NETWORKS:
            error_msg = f'Unknown network {self.network!r}. Use one of {", ".join(NETWORKS)}.'
            raise ValidationError(error_msg)
        if self.network == 'toy':
            network = ToyFluxBalanceInteraction('fba', parsimonious=self.parsimonious)
            cell = MetabolicCellElement('cell', values=network.get_values())
            self.system_ = System(self.label, elements=[cell], interactions=[network])
            return
        network = load_network('textbook', 'cell', needed_by='flux_balance').set_params(
            parsimonious=self.parsimonious,
        )
        identifier = f'lower_{network._get_identifier(OXYGEN_EXCHANGE)}'
        cell = MetabolicCellElement('cell', values=network.get_values() | {identifier: -float(self.oxygen)})
        self.system_ = System(self.label, elements=[cell], interactions=[network])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • MetabolicCellElement, from Element

Interactions:

  • ToyFluxBalanceInteraction, from Interaction
class MetabolicCellElement(Element):
    """Cell whose values hold the fluxes, the bounds, and the gene switches of a metabolic network.

    It is drawn as the linear program of its network, and `FluxBalanceInteraction.get_values` gives its values.

    Examples:
        >>> from skcomplex.systems.biology.common.metabolism import FluxBalanceInteraction, MetabolicCellElement
        >>> from skcomplex.systems.biology.common.metabolism import ReactionSpec
        >>> network = FluxBalanceInteraction('fba', reactions={'r': ReactionSpec({'A': -1.0})})
        >>> MetabolicCellElement('cell', values=network.get_values()).values['upper_r']
        1000.0
    """

    visual = VisualSpec('linear_program')

class ToyFluxBalanceInteraction(FluxBalanceInteraction):
    """Flux balance of the toy network of Table 8.2 of Raman (2021), which grows on A alone.

    Args:
        label:
            The label of the interaction.

        cell:
            The path of the cell whose values hold the fluxes, the bounds, and the switches.

        reactions:
            The reactions by name.

        objective:
            The coefficient of every reaction in the objective.

        parsimonious:
            Whether to minimise the total absolute flux after the objective.

        infeasible:
            What a run does when the balances and bounds cannot all hold.

        name:
            The name of the network.

    Examples:
        >>> from skcomplex.systems.biology.common.metabolism import ToyFluxBalanceInteraction
        >>> ToyFluxBalanceInteraction('fba').get_values()['upper_v1']
        1000.0
    """

    def __init__(
        self,
        label: str = 'fba',
        *,
        cell: Role = 'cell',
        reactions: Mapping[str, ReactionSpec] = TOY_REACTIONS,
        objective: Mapping[str, float] = TOY_OBJECTIVE,
        parsimonious: bool = False,
        infeasible: str = 'raise',
        name: str | None = 'ToyNetwork',
    ) -> None:
        super().__init__(
            label,
            cell=cell,
            reactions=reactions,
            objective=objective,
            parsimonious=parsimonious,
            infeasible=infeasible,
            name=name,
        )