{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Edit Model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add a single reaction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Forward reaction" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Attempt 1:\n", "ERROR: The modelseed reaction rxn00002 is absent from the model.\n", "\n", "Attempt 2:\n", "rxn00002: cpd00001 + 3.0 cpd00067 + cpd00742 --> 2.0 cpd00011 + 2.0 cpd00013\n" ] } ], "source": [ "import modelseedpy\n", "from modelseedpy.biochem import from_local\n", "import cobra\n", "import sys\n", "\n", "# locally importing the ModelSEEDpy editor API\n", "sys.path.insert(1, 'C:\\\\Users\\\\Andrew Freiburger\\\\Dropbox\\\\My PC (DESKTOP-M302P50)\\\\Documents\\\\UVic Civil Engineering\\\\Internships\\\\Agronne\\\\ModelSEEDpy\\\\modelseedpy\\\\core')\n", "import mseditorapi\n", "\n", "# locally import a BiGG model and the ModelSEEDpy\n", "bigg_model_path = '.\\e_coli_core metabolism from BiGG.json'\n", "model = cobra.io.load_json_model(bigg_model_path)\n", "modelseed_path = '..\\..\\..\\..\\..\\..\\Biofilm growth code\\GSWL code\\ModelSEEDDatabase'\n", "modelseed = modelseedpy.biochem.from_local(modelseed_path)\n", "\n", "# demonstrating the addition of the reaction to the model \n", "example_reaction = 'rxn00002'\n", "\n", "print('Attempt 1:')\n", "try:\n", " print(model.reactions.get_by_id(example_reaction))\n", "except:\n", " print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))\n", " \n", "mseditorapi.MSEditorAPI.add_ms_reaction(model, rxn_id = example_reaction, modelseed = modelseed, compartment_equivalents = {'0':'c0', '1':'e0'}, direction = '>')\n", "\n", "print('\\nAttempt 2:')\n", "try:\n", " print(model.reactions.get_by_id(example_reaction))\n", "except:\n", " print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))\n", "\n", "# remove the reaction from the model\n", "model.reactions.get_by_id(example_reaction).remove_from_model()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Backward and reversible reactions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The directionality of the modelseed reaction may be either ``>``, ``<``, or ``=``. " ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Backward reaction:\n", "rxn00002: cpd00001 + 3.0 cpd00067 + cpd00742 <-- 2.0 cpd00011 + 2.0 cpd00013\n", "\n", "Reversible reaction:\n", "rxn00002: cpd00001 + 3.0 cpd00067 + cpd00742 <=> 2.0 cpd00011 + 2.0 cpd00013\n" ] } ], "source": [ "# add a backward reaction \n", "print('Backward reaction:')\n", "mseditorapi.MSEditorAPI.add_ms_reaction(model, rxn_id = example_reaction, modelseed = modelseed, compartment_equivalents = {'0':'c0', '1':'e0'}, direction = '<')\n", "\n", "try:\n", " print(model.reactions.get_by_id(example_reaction))\n", "except:\n", " print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))\n", " \n", "model.reactions.get_by_id(example_reaction).remove_from_model()\n", "\n", "# add a reversible reaction \n", "print('\\nReversible reaction:')\n", "mseditorapi.MSEditorAPI.add_ms_reaction(model, rxn_id = example_reaction, modelseed = modelseed, compartment_equivalents = {'0':'c0', '1':'e0'}, direction = '=')\n", "\n", "try:\n", " print(model.reactions.get_by_id(example_reaction))\n", "except:\n", " print('ERROR: The modelseed reaction {} is absent from the model.'.format(example_reaction))\n", " \n", "model.reactions.get_by_id(example_reaction).remove_from_model()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.9.12" } }, "nbformat": 4, "nbformat_minor": 4 }