{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. Debugging\n", "\n", "It is often observed in genome scale models that adding thermodynamic constraints make the model infeasible. This might be due to variety of reasons, like ill-formatted covariance between groups/components, lumping of reactions etc. It is always not easy to find the exact cause of the problem. But, if you are using Gurobi/Cplex, you can find the constraints that render the model infeasible. \n", "\n", "Please note that these methods give you random set of constraints that represent infeasibility. Also, a model can contain multiple infeasible sets. While modifying/removing these constraints, it is advisable to look for biological meaning.\n", "\n", "Let us demonstrate the usage by breaking the model. \n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Downloading package metadata...\n", "Fragments already downloaded\n", "Downloading package metadata...\n", "Fragments already downloaded\n", "Downloading package metadata...\n", "Fragments already downloaded\n" ] } ], "source": [ "import sys\n", "sys.path.insert(0, \"../../examples\")\n", "from paper_data_example import build_core_model" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Using license file /home/vishnu/gurobi.lic\n", "Academic license - for non-commercial use only\n", "Read LP format model from file /tmp/tmpdzvydb7y.lp\n", "Reading time = 0.00 seconds\n", ": 72 rows, 190 columns, 720 nonzeros\n" ] } ], "source": [ "tfa_model = build_core_model()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now lets change the concentration **atp** and find the objective value. Then, we set the lower bound of objective variable higher than the solution to break the model." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\n" ] } ], "source": [ "atp = tfa_model.metabolites.get_by_id('atp_c')\n", "atp.concentration_min = 2e-3\n", "atp.concentration_max = 5e-2\n", "solution = tfa_model.optimize()\n", "print(solution)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now lets adjust the biomass lower bound to 0.5 and find out the IIS set of reactions using `Gurobi`" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "biomass = tfa_model.reactions.get_by_id('BIOMASS_Ecoli_core_w_GAM')\n", "biomass.lower_bound = 0.5\n", "solution = tfa_model.optimize()\n", "tfa_model.solver.problem.computeIIS() # model.solver.problem represents the solver interface model\n", "for cons in tfa_model.solver.problem.getConstrs(): \n", " if cons.IISConstr: \n", " print(cons) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This returned us a list of constraints that can be modified to make the model status optimal. One has to choose and modify the list of constraints to manipulate based on biological meaning." ] } ], "metadata": { "kernelspec": { "name": "python3", "display_name": "Python 3.6.9 64-bit ('test_tmfa')", "metadata": { "interpreter": { "hash": "2586d49dccd52e26ba1525073a1c55b1a3ff7ebecaf4fcfc40336f28cb4872d4" } } }, "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.6.9-final" } }, "nbformat": 4, "nbformat_minor": 2 }