{ "cells": [ { "cell_type": "markdown", "id": "ff3d24af", "metadata": { "lines_to_next_cell": 0 }, "source": [ "Create the repressilator step by step.\n", "\n", "See on biomodels.\n", "\n", "\n", "https://github.com/sbmlteam/libsbml" ] }, { "cell_type": "code", "execution_count": 1, "id": "49cf0c1c", "metadata": { "execution": { "iopub.execute_input": "2023-04-17T14:01:59.420716Z", "iopub.status.busy": "2023-04-17T14:01:59.420123Z", "iopub.status.idle": "2023-04-17T14:01:59.530924Z", "shell.execute_reply": "2023-04-17T14:01:59.531637Z" }, "lines_to_next_cell": 2 }, "outputs": [], "source": [ "import os\n", "from pathlib import Path\n", "\n", "import libsbml\n", "\n", "from combine_notebooks.helper_functions.utils import *\n", "from combine_notebooks.validation.validation_sbml import validate_sbml" ] }, { "cell_type": "code", "execution_count": 2, "id": "5d61bf89", "metadata": { "execution": { "iopub.execute_input": "2023-04-17T14:01:59.535386Z", "iopub.status.busy": "2023-04-17T14:01:59.534403Z", "iopub.status.idle": "2023-04-17T14:01:59.575610Z", "shell.execute_reply": "2023-04-17T14:01:59.576136Z" } }, "outputs": [], "source": [ "\n", "\n", "def create_repressilator(sbml_path: Path) -> libsbml.SBMLDocument:\n", " \"\"\"Create repressilator.\"\"\"\n", " print(\"Create SBML model\")\n", " # create a new document\n", "\n", " doc: libsbml.SBMLDocument = libsbml.SBMLDocument(3, 2)\n", " model: libsbml.Model = doc.createModel()\n", "\n", " # --- compartments ---\n", " # add compartment and set annotation\n", " c1 = add_compartment(model, \"cell\", 1.0, \"meta_cell\", \"SBO:0000290\")\n", " c1_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS,\n", " \"http://identifiers.org/GO:0005623\",\n", " )\n", " c1.addCVTerm(c1_cv)\n", "\n", " # --- species ---\n", " # add species for the 3 mRNAs and 3 Proteins and set annotations\n", " s1 = add_species(model, \"PX\", \"PX\", \"cell\", \"LacI protein\", \"SBO:0000252\", 0, True)\n", " s1_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS,\n", " \"http://identifiers.org/uniprot/P03023\",\n", " )\n", " s1.addCVTerm(s1_cv)\n", "\n", " s2 = add_species(model, \"PY\", \"PY\", \"cell\", \"TetR protein\", \"SBO:0000252\", 0, True)\n", " s2_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS,\n", " \"http://identifiers.org/uniprot/P04483\",\n", " )\n", " s2.addCVTerm(s2_cv)\n", "\n", " s3 = add_species(model, \"PZ\", \"PZ\", \"cell\", \"cI protein\", \"SBO:0000252\", 0, True)\n", " s3_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS,\n", " \"http://identifiers.org/uniprot/P03034\",\n", " )\n", " # example setting a model qualifier\n", " # s3_cv.setQualifierType(libsbml.MODEL_QUALIFIER)\n", " # s3_cv.setBiologicalQualifierType(libsbml.BQM_IS)\n", " s3.addCVTerm(s3_cv)\n", "\n", " s4 = add_species(model, \"X\", \"meta_X\", \"cell\", \"LacI mRNA\", \"SBO:0000250\", 0, True)\n", " s4_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/CHEBI:33699\",\n", " )\n", " s4_cv = add_annotation_resource(\n", " s4_cv, libsbml.BQB_IS_VERSION_OF, \"http://identifiers.org/kegg.compound/C00046\"\n", " )\n", " s4.addCVTerm(s4_cv)\n", " s4_cv = add_annotation_resource(\n", " s4_cv, libsbml.BQB_ENCODES, \"http://identifiers.org/uniprot/P03023\"\n", " )\n", " s4.addCVTerm(s4_cv)\n", "\n", " s5 = add_species(model, \"Y\", \"meta_Y\", \"cell\", \"TetR mRNA\", \"SBO:0000250\", 20, True)\n", " s5_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/CHEBI:33699\",\n", " )\n", " s5_cv = add_annotation_resource(\n", " s5_cv, libsbml.BQB_IS_VERSION_OF, \"http://identifiers.org/kegg.compound/C00046\"\n", " )\n", " s5.addCVTerm(s5_cv)\n", " s5_cv = add_annotation_resource(\n", " s5_cv, libsbml.BQB_ENCODES, \"http://identifiers.org/uniprot/P04483\"\n", " )\n", " s5.addCVTerm(s5_cv)\n", "\n", " s6 = add_species(model, \"Z\", \"meta_Z\", \"cell\", \"cl mRNA\", \"SBO:0000250\", 0, True)\n", " s6_cv = create_annotation(\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/CHEBI:33699\",\n", " )\n", " s6_cv = add_annotation_resource(\n", " s6_cv, libsbml.BQB_IS_VERSION_OF, \"http://identifiers.org/kegg.compound/C00046\"\n", " )\n", " s6.addCVTerm(s6_cv)\n", " s6_cv = add_annotation_resource(\n", " s6_cv, libsbml.BQB_ENCODES, \"http://identifiers.org/uniprot/P03034\"\n", " )\n", " s6.addCVTerm(s6_cv)\n", "\n", " # --- parameters ---\n", " # \n", " add_parameters(model, \"tau_mRNA\", \"mRNA half life\", True, value=2.0)\n", " # \n", " add_parameters(model, \"kd_mRNA\", \"kd_mRNA\", False, sbo_term=\"SBO:0000356\")\n", " # \n", " add_parameters(model, \"k_tl\", \"k_tl\", False, sbo_term=\"SBO:0000016\")\n", " # \n", " add_parameters(model, \"eff\", \"translation efficiency\", True, value=20)\n", " # \n", " add_parameters(\n", " model, \"t_ave\", \"average mRNA life time\", False, sbo_term=\"SBO:0000348\"\n", " )\n", " # \n", " add_parameters(model, \"kd_prot\", \"kd_prot\", False, sbo_term=\"SBO:0000356\")\n", " # \n", " add_parameters(model, \"tau_prot\", \"protien half life\", True, value=10)\n", " # \n", " add_parameters(model, \"a0_tr\", \"a0_tr\", False, sbo_term=\"SBO:0000485\")\n", " # \n", " add_parameters(model, \"ps_0\", \"tps_repr\", True, value=0.0005)\n", " # \n", " add_parameters(model, \"a_tr\", \"a_tr\", False, sbo_term=\"SBO:0000186\")\n", " # \n", " add_parameters(model, \"ps_a\", \"tps_active\", True, value=0.5)\n", " # \n", " add_parameters(model, \"KM\", \"KM\", True, value=40)\n", " # \n", " add_parameters(model, \"n\", \"n\", True, value=2.0)\n", "\n", " # TODO: a0_tr, a_tr, n, KM\n", "\n", " # --- rules ---\n", " add_assignment_rule(model, \"kd_mRNA\", \"ln(2) / tau_mRNA\")\n", " add_assignment_rule(model, \"t_ave\", \"tau_mRNA / ln(2)\")\n", " add_assignment_rule(model, \"k_tl\", \"eff / t_ave\")\n", " add_assignment_rule(model, \"kd_prot\", \"ln(2) / tau_prot\")\n", " add_assignment_rule(model, \"a0_tr\", \"ps_0 * 60\")\n", " add_assignment_rule(model, \"a_tr\", \"(ps_a - ps_0) * 60\")\n", "\n", " # --- reaction ---\n", " # X -> None\n", " r1 = add_reactions(\n", " model,\n", " \"Reaction1\",\n", " \"meta_Reaction1\",\n", " \"SBO:0000179\",\n", " \"degradation of LacI transcripts\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006402\",\n", " \"kd_mRNA * X\",\n", " \"SBO:0000049\",\n", " )\n", " add_reactant_to_reaction(r1, \"X\")\n", "\n", " r2 = add_reactions(\n", " model,\n", " \"Reaction2\",\n", " \"meta_Reaction2\",\n", " \"SBO:0000179\",\n", " \"degradation of TetR transcripts\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006402\",\n", " \"kd_mRNA * Y\",\n", " \"SBO:0000049\",\n", " )\n", " add_reactant_to_reaction(r2, \"Y\")\n", "\n", " r3 = add_reactions(\n", " model,\n", " \"Reaction3\",\n", " \"meta_Reaction3\",\n", " \"SBO:0000179\",\n", " \"degradation of CI transcripts\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006402\",\n", " \"kd_mRNA * Z\",\n", " \"SBO:0000049\",\n", " )\n", " add_reactant_to_reaction(r3, \"Z\")\n", "\n", " r4 = add_reactions(\n", " model,\n", " \"Reaction4\",\n", " \"meta_Reaction4\",\n", " \"SBO:0000184\",\n", " \"translation of LacI\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006412\",\n", " \"k_tl * X\",\n", " \"SBO:0000049\",\n", " )\n", " add_product_to_reaction(r4, \"PX\")\n", " add_modifier_to_reaction(r4, \"X\", \"SBO:0000461\")\n", "\n", " r5 = add_reactions(\n", " model,\n", " \"Reaction5\",\n", " \"meta_Reaction5\",\n", " \"SBO:0000184\",\n", " \"translation of TetR\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006412\",\n", " \"k_tl * Y\",\n", " \"SBO:0000049\",\n", " )\n", " add_product_to_reaction(r5, \"PY\")\n", " add_modifier_to_reaction(r5, \"Y\", \"SBO:0000461\")\n", "\n", " r6 = add_reactions(\n", " model,\n", " \"Reaction6\",\n", " \"meta_Reaction6\",\n", " \"SBO:0000184\",\n", " \"translation of CI\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006412\",\n", " \"k_tl * Z\",\n", " \"SBO:0000049\",\n", " )\n", " add_product_to_reaction(r6, \"PZ\")\n", " add_modifier_to_reaction(r6, \"Z\", \"SBO:0000461\")\n", "\n", " r7 = add_reactions(\n", " model,\n", " \"Reaction7\",\n", " \"meta_Reaction7\",\n", " \"SBO:0000179\",\n", " \"degradation of LacI\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0030163\",\n", " \"kd_prot * PX\",\n", " \"SBO:0000049\",\n", " )\n", " add_reactant_to_reaction(r7, \"PX\")\n", "\n", " r8 = add_reactions(\n", " model,\n", " \"Reaction8\",\n", " \"meta_Reaction8\",\n", " \"SBO:0000179\",\n", " \"degradation of TetR\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0030163\",\n", " \"kd_prot * PY\",\n", " \"SBO:0000049\",\n", " )\n", " add_reactant_to_reaction(r8, \"PY\")\n", "\n", " r9 = add_reactions(\n", " model,\n", " \"Reaction9\",\n", " \"meta_Reaction9\",\n", " \"SBO:0000179\",\n", " \"degradation of CI\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0030163\",\n", " \"kd_prot * PZ\",\n", " \"SBO:0000049\",\n", " )\n", " add_reactant_to_reaction(r9, \"PZ\")\n", "\n", " r10 = add_reactions(\n", " model,\n", " \"Reaction10\",\n", " \"meta_Reaction10\",\n", " \"SBO:0000183\",\n", " \"transcription of LacI\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006351\",\n", " \"a0_tr + (a_tr * power(KM, n)) / (power(KM, n) + power(PZ, n))\",\n", " None,\n", " )\n", " add_product_to_reaction(r10, \"X\")\n", " add_modifier_to_reaction(r10, \"PZ\", \"SBO:0000536\")\n", "\n", " r11 = add_reactions(\n", " model,\n", " \"Reaction11\",\n", " \"meta_Reaction11\",\n", " \"SBO:0000183\",\n", " \"transcription of TetR\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006351\",\n", " \"a0_tr + (a_tr * power(KM, n)) / (power(KM, n) + power(PX, n))\",\n", " None,\n", " )\n", " add_product_to_reaction(r11, \"Y\")\n", " add_modifier_to_reaction(r11, \"PX\", \"SBO:0000536\")\n", "\n", " r12 = add_reactions(\n", " model,\n", " \"Reaction12\",\n", " \"meta_Reaction12\",\n", " \"SBO:0000183\",\n", " \"transcription of CI\",\n", " False,\n", " libsbml.BIOLOGICAL_QUALIFIER,\n", " libsbml.BQB_IS_VERSION_OF,\n", " \"http://identifiers.org/GO:0006351\",\n", " \"a0_tr + (a_tr * power(KM, n)) / (power(KM, n) + power(PY, n))\",\n", " None,\n", " )\n", " add_product_to_reaction(r12, \"Z\")\n", " add_modifier_to_reaction(r12, \"PY\", \"SBO:0000536\")\n", "\n", " print(\"-\" * 80)\n", " print(libsbml.writeSBMLToString(doc))\n", " print(\"-\" * 80)\n", "\n", " # write to file\n", " os.makedirs(os.path.dirname(str(sbml_path)), exist_ok=True)\n", " libsbml.writeSBMLToFile(doc, str(sbml_path))\n", "\n", " # validate file\n", " validate_sbml(doc, units_consistency=False)\n", "\n", " return doc" ] }, { "cell_type": "code", "execution_count": 3, "id": "5842c5ae", "metadata": { "execution": { "iopub.execute_input": "2023-04-17T14:01:59.578337Z", "iopub.status.busy": "2023-04-17T14:01:59.577706Z", "iopub.status.idle": "2023-04-17T14:01:59.591761Z", "shell.execute_reply": "2023-04-17T14:01:59.592362Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Create SBML model\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", " \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", " \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", " 2 \n", " \n", " tau_mRNA \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " tau_mRNA \n", " \n", " \n", " 2 \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " eff \n", " t_ave \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 2 \n", " \n", " tau_prot \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " ps_0 \n", " 60 \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " ps_a \n", " ps_0 \n", " \n", " 60 \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", " kd_mRNA \n", " X \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " kd_mRNA \n", " Y \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " kd_mRNA \n", " Z \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", " k_tl \n", " X \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", " k_tl \n", " Y \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", " k_tl \n", " Z \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " kd_prot \n", " PX \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " kd_prot \n", " PY \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " kd_prot \n", " PZ \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", " a0_tr \n", " \n", " \n", " \n", " \n", " a_tr \n", " \n", " \n", " KM \n", " n \n", " \n", " \n", " \n", " \n", " \n", " \n", " KM \n", " n \n", " \n", " \n", " \n", " PZ \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", " a0_tr \n", " \n", " \n", " \n", " \n", " a_tr \n", " \n", " \n", " KM \n", " n \n", " \n", " \n", " \n", " \n", " \n", " \n", " KM \n", " n \n", " \n", " \n", " \n", " PX \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", " a0_tr \n", " \n", " \n", " \n", " \n", " a_tr \n", " \n", " \n", " KM \n", " n \n", " \n", " \n", " \n", " \n", " \n", " \n", " KM \n", " n \n", " \n", " \n", " \n", " PY \n", " n \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "--------------------------------------------------------------------------------\n", "--------------------------------------------------------------------------------\n", "validation error(s) : 0\n", "validation warning(s) : 0\n", "--------------------------------------------------------------------------------\n" ] } ], "source": [ "if __name__ == \"__main__\":\n", " from combine_notebooks import RESULTS_DIR\n", "\n", " # RESOURCES_DIR: Path = Path(__file__).parent / \"resources\"\n", " # RESULTS_DIR: Path = RESOURCES_DIR / \"results\"\n", " doc: libsbml.SBMLDocument = create_repressilator(\n", " sbml_path=RESULTS_DIR / \"repressilator_sbml_libsbml.xml\"\n", " )" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" }, "kernelspec": { "display_name": "Python 3", "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.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }