{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Estimating Fluxes at Steady State" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To estimate metabolic fluxes at steady state, we use nonlinear optimization to minimize the difference between the simulated and measured labeling patterns when the system reaches a stable status, both metabolically and isotopically. The problem can be formulated as follows:\n", "\n", "\n", "\n", "Here, ${\\bf{x}}_{sim}$ and ${\\bf{v}}_{sim}$ are simulated MDVs and fluxes, respectively, both the functions of free flux $\\bf{u}$. ${\\bf{x}}_{exp}$ and ${\\bf{v}}_{exp}$ are the measured labeling patterns and fluxes, and ${\\bf{\\Sigma }}_{{{\\bf{x}}_{exp}}}^{ - 1}$ and ${\\bf{\\Sigma }}_{{{\\bf{v}}_{exp}}}^{ - 1}$ are the inverses of the covariance matrix of measurements. $\\bf{N}$ is the null space of the stoichiometric matrix of the network reactions, and $\\bf{T}$ is the matrix that transforms total fluxes to net fluxes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solving the Fluxes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will demonstrate the process using a toy model. First, we build the model by reading from the [file](https://github.com/Chaowu88/freeflux/tree/main/models/toy):" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from freeflux import Model\n", "\n", "MODEL_FILE = 'path/to/reactions.tsv'\n", "\n", "model = Model('demo')\n", "model.read_from_file(MODEL_FILE)\n", "\n", "fit = model.fitter('ss')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we specify the labeling strategy:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "fit.set_labeling_strategy(\n", " 'AcCoA', \n", " labeling_pattern = ['01', '11'], \n", " percentage = [0.25, 0.25], \n", " purity = [1, 1]\n", ") # call this method for each labeled substrate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can set the measurements using `set_measured_MDV` for MDV and `set_measured_flux` for flux (if any). To input a set of measurements, we can load from [files](https://github.com/Chaowu88/freeflux/tree/main/models/toy) using `set_measured_MDVs_from_file` and `set_measured_fluxes_from_file` methods. We assume here that the measured fluxes are net ones since total fluxes are not typically measurable:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "MEASURED_MDV_FILE = 'path/to/measured_MDVs.tsv'\n", "MEASURED_FLUX_FILE = 'path/to/measured_fluxes.tsv'\n", "\n", "fit.set_measured_MDVs_from_file(MEASURED_MDV_FILE)\n", "fit.set_measured_fluxes_from_file(MEASURED_FLUX_FILE)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can then set the lower and upper bounds of net fluxes:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "fit.set_flux_bounds(\n", " 'all', # \"all\" denotes all fluxes. use reaction ID for specific flux \n", " bounds = [-100, 100]\n", ") " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "