{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Flux Balance Analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## FBA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "FreeFlux is capable of solving the canonical [flux balance analysis](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3108565/) (FBA) problem, which is defined as:\n", "
\n", " \n", "
\n", "where ${\\bf{S}}$ is the stoichiometric matrix, ${\\bf{v}}$ is the flux vector bounded by lower bound ${{\\bf{v}}_{lb}}$ and upper bounds ${{\\bf{v}}_{ub}}$. The objective function could be any linear combination of fluxes, which is typically, the biomass formation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we use an example of the *E. coli* metabolic network. The model file can be found [here](https://github.com/Chaowu88/freeflux/blob/main/models/ecoli/experimental_data/reactions.xlsx)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "optimizing [elapsed: 0:00:01]\n", "\n", "objective: 1.237\n", "pgi 9.746\n", "pfk 8.769\n", "fba 8.769\n", "tpi 8.769\n", "gapdh 16.778\n", "eno 14.625\n", "pk 10.808\n" ] } ], "source": [ "from freeflux import Model\n", "\n", "MODEL_FILE = 'path/to/reactions.xlsx'\n", "\n", "model = Model('ecoli')\n", "model.read_from_file(MODEL_FILE)\n", "\n", "with model.optimizer() as opt:\n", " opt.set_flux_bounds('all', bounds = [-100, 100]) \n", " opt.set_flux_bounds('glk', bounds = [10, 10])\n", " opt.prepare()\n", " res = opt.optimize(objective = {'biom': 1})\n", "\n", "print('objective:', res.opt_objective)\n", "\n", "glycolysis_enzymes = ['pgi', 'pfk','fba', 'tpi', 'gapdh', 'eno', 'pk']\n", "for enzyme in glycolysis_enzymes:\n", " print(enzyme, round(res.opt_fluxes[enzyme], 3))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## FVA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Flux variable analysis](https://pubmed.ncbi.nlm.nih.gov/20920235/) (FVA) is used to find the minimum and maximum values of a flux while maintaining the objective above some fraction of its optimized value in the original FBA problem. This is formulated as:\n", "
\n", " \n", "
\n", "where $\\gamma$ $\\in$ [0,1] controls how close the FBA objective should be to its optimal value $ob{j_{FBA}}$. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "FreeFlux provides a function for FVA that estimates the feasible range of fluxes which can provide a reasonable feasible region for fluxes and initial guesses during the least squares optimization. As an example, the flux ranges of the E. coli model can be estimated using the following code:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "estimating flux ranges [elapsed: 0:00:12]\n", "\n", "pgi [-18.946, 10.0]\n", "pfk [0.0, 10.0]\n", "fba [0.0, 10.0]\n", "tpi [0.0, 10.0]\n", "gapdh [8.055, 20.0]\n", "eno [5.951, 20.0]\n", "pk [0.0, 26.42]\n" ] } ], "source": [ "with model.optimizer() as opt:\n", " opt.set_flux_bounds('all', bounds = [-100, 100]) \n", " opt.set_flux_bounds('glk', bounds = [10, 10])\n", " opt.prepare()\n", " res = opt.estimate_fluxes_range(\n", " objective = {'biom': 1}, \n", " gamma = 0\n", " )\n", "\n", "for enzyme in glycolysis_enzymes:\n", " print(\n", " enzyme, \n", " [round(res.flux_ranges[enzyme][0], 3), \n", " round(res.flux_ranges[enzyme][1], 3)]\n", " )" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:freeflux-py37]", "language": "python", "name": "conda-env-freeflux-py37-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" } }, "nbformat": 4, "nbformat_minor": 4 }