{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# MFA using INCA in MATLAB - now all in Python!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is an example notebook that makes use of functions that can write a MATLAB script that runs an MFA analysis using INCA. INCA is a MATLAB software. To make it easier for users, MATLAB can be run here in the notebook using an engine. See the instructions below on how to use this notebook." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### MATLAB" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get a free academic licence and install MATLAB from https://www.mathworks.com. Then, install the engine API following the guide provided [under this link](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html). In short, you will have to go to your MATLAB root folder (find your installation and open that folder) and go to \"/extern/engines/python\" and run \"python setup.py install\" from the command line." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### INCA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"INCA (Isotopomer Network Compartmental Analysis) is a MATLAB-based software package for isotopomer network modeling and metabolic flux analysis.\" You can read more about it in [Young, 2014](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3998137/pdf/btu015.pdf)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You have to get a free academic licence for INCA from [the Vanderbilt University website](http://mfa.vueinnovations.com/licensing) (the second option is the relevant one) and install it. Note the path to the base directory of your INCA installation, you will need it later." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Import customized functions for INCA utilization" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Academic license - for non-commercial use only - expires 2021-05-28\n", "Using license file /Users/matmat/gurobi.lic\n" ] } ], "source": [ "from BFAIR.INCA import INCA_script\n", "import pandas as pd\n", "import numpy as np\n", "import time\n", "import ast\n", "import matlab.engine" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Initialize the script" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "INCA_script = INCA_script()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Import the data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# measured fragments/MS data, tracers and measured fluxes should be limited to one experiment\n", "\n", "atomMappingReactions_data_I = pd.read_csv('data/MFA_modelInputsData/data_stage02_isotopomer_atomMappingReactions2.csv')\n", "modelReaction_data_I = pd.read_csv('data/MFA_modelInputsData/data_stage02_isotopomer_modelReactions.csv')\n", "atomMappingMetabolite_data_I = pd.read_csv('data/MFA_modelInputsData/data_stage02_isotopomer_atomMappingMetabolites.csv')\n", "measuredFluxes_data_I = pd.read_csv('data/MFA_modelInputsData/data_stage02_isotopomer_measuredFluxes.csv')\n", "experimentalMS_data_I = pd.read_csv('data/MFA_modelInputsData/data-1604345289079.csv')\n", "tracer_I = pd.read_csv('data/MFA_modelInputsData/data_stage02_isotopomer_tracers.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Exclude data for irreleavnt experiments and models" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# The files need to be limited by model id and mapping id, I picked \"ecoli_RL2013_02\" here\n", "atomMappingReactions_data_I = INCA_script.limit_to_one_model(atomMappingReactions_data_I, 'mapping_id', 'ecoli_RL2013_02')\n", "modelReaction_data_I = INCA_script.limit_to_one_model(modelReaction_data_I, 'model_id', 'ecoli_RL2013_02')\n", "atomMappingMetabolite_data_I = INCA_script.limit_to_one_model(atomMappingMetabolite_data_I, 'mapping_id', 'ecoli_RL2013_02')\n", "measuredFluxes_data_I = INCA_script.limit_to_one_model(measuredFluxes_data_I, 'model_id', 'ecoli_RL2013_02')\n", "\n", "# Limiting fluxes, fragments and tracers to one experiment\n", "measuredFluxes_data_I = INCA_script.limit_to_one_experiment(measuredFluxes_data_I, 'experiment_id', 'WTEColi_113C80_U13C20_01')\n", "experimentalMS_data_I = INCA_script.limit_to_one_experiment(experimentalMS_data_I, 'experiment_id', 'WTEColi_113C80_U13C20_01')\n", "tracer_I = INCA_script.limit_to_one_experiment(tracer_I, 'experiment_id', 'WTEColi_113C80_U13C20_01')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate the MATLAB script\n", "\n", "Save it in your working directory. The last argument in the script_generator function will name your future .mat file" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There is no stoichimetriy given for: ATPM\n", "There is no stoichimetriy given for: Ec_Biomass_INCA\n", "There is no stoichimetriy given for: EX_nh4_LPAREN_e_RPAREN_\n", "There is no stoichimetriy given for: EX_o2_LPAREN_e_RPAREN_\n", "There is no stoichimetriy given for: EX_so4_LPAREN_e_RPAREN_\n", "There is no stoichimetriy given for: FADR_NADH_CYTBD_HYD_ATPS4r\n", "There is no stoichimetriy given for: NADH_CYTBD_HYD_ATPS4r\n", "There is no stoichimetriy given for: NADTRHD_THD2pp\n", "There is no stoichimetriy given for: NADTRHD_THD2pp_reverse\n" ] } ], "source": [ "script = INCA_script.script_generator(\n", " modelReaction_data_I,\n", " atomMappingReactions_data_I,\n", " atomMappingMetabolite_data_I,\n", " measuredFluxes_data_I,\n", " experimentalMS_data_I,\n", " tracer_I\n", ")\n", "INCA_script.save_INCA_script(script, \"testscript\")\n", "runner = INCA_script.runner_script_generator('TestFile', 10)\n", "INCA_script.save_runner_script(runner=runner, scriptname=\"testscript\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Provide the path to you INCA installation, your working directory and the name of the previously generated MATLAB script" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "INCA_base_directory = # ADD YOUR BASE DIRECTORY HERE, e.g. \"/Users/Username/Documents/INCAv1.9\"\n", "script_folder = %pwd\n", "matlab_script = \"testscript\"\n", "runner_script = matlab_script + \"_runner\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### INCA will be started and your script run in MATLAB. This will produce the .mat file specified above" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- 270.8612148761749 seconds -\n" ] } ], "source": [ "INCA_script.run_INCA_in_MATLAB(INCA_base_directory, script_folder, matlab_script, runner_script)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "bfair", "language": "python", "name": "bfair" }, "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }