{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "bad57316", "metadata": {}, "source": [ "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/combine-org/combine-notebooks/main?labpath=%2Fnotebooks%2Fomex.ipynb)\n", "\"Open" ] }, { "attachments": {}, "cell_type": "markdown", "id": "8c0154eb", "metadata": {}, "source": [ "# Simple OMEX example" ] }, { "attachments": {}, "cell_type": "markdown", "id": "275bf1bb", "metadata": {}, "source": [ "This notebook an example for creating a COMBINE archive. A COMBINE archive is a bundled package containing all the necessary documents and relevant information for a modeling and simulation project, ensuring that all components are conveniently stored together. The archive is encoded using the Open Modeling EXchange format (OMEX)." ] }, { "attachments": {}, "cell_type": "markdown", "id": "5bb745f7", "metadata": {}, "source": [ "## 1) Including libraries" ] }, { "attachments": {}, "cell_type": "markdown", "id": "1875d29c", "metadata": {}, "source": [ "Note: Please change the `colab` flag to `True` if you are using Google Colab." ] }, { "cell_type": "code", "execution_count": 2, "id": "83f73430", "metadata": {}, "outputs": [], "source": [ "colab = False\n", "if colab:\n", " !pip install git+https://github.com/combine-org/combine-notebooks\n", " !git clone https://github.com/combine-org/combine-notebooks\n", " %cd /content/combine-notebooks/notebooks" ] }, { "cell_type": "code", "execution_count": 38, "id": "5e7c2a84", "metadata": { "collapsed": false }, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "from pymetadata.console import console\n", "from pymetadata.omex import EntryFormat, ManifestEntry, Omex\n", "\n", "from combine_notebooks import RESULTS_DIR" ] }, { "attachments": {}, "cell_type": "markdown", "id": "2e806b7a", "metadata": {}, "source": [ "## 2) Creating a COMBINE archieve" ] }, { "attachments": {}, "cell_type": "markdown", "id": "565b2c61", "metadata": {}, "source": [ "Creating an empty archive and adding entry for SBML." ] }, { "cell_type": "code", "execution_count": 39, "id": "d1a747a8", "metadata": {}, "outputs": [], "source": [ "# Create OMEX archive of resources.\n", "omex = Omex()" ] }, { "attachments": {}, "cell_type": "markdown", "id": "f7db9291", "metadata": {}, "source": [ "Get the file location of our results files. These were generated by other notebooks in this repositiory. The files we will be adding to our OMEX file include:\n", " - hello_world_sbml.xml - a simple SBML model\n", " - hello_world_cellml.cellml - a simple CellML model\n", " - hello_world_sbgn.png - a diagram showing a simple reacton that has been generated using SBGN\n", " - hello_world_sbgn.sbgn - correponding SBGN used to generate the .png file\n", " - hello_world_sedml.sedml - a simple simulation experiment described using SED-ML" ] }, { "cell_type": "code", "execution_count": 40, "id": "06cfde3a", "metadata": {}, "outputs": [], "source": [ "# Path to our results\n", "results_dir = Path(RESULTS_DIR.stem)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "518eca96", "metadata": {}, "source": [ "First, lets add our simple SBML file into the COMBINE archieve." ] }, { "cell_type": "code", "execution_count": 41, "id": "83838073", "metadata": {}, "outputs": [], "source": [ "# Add entry for the SBML model\n", "omex.add_entry(\n", " entry=ManifestEntry(\n", " location=\"./sbml/hello_world_sbml.xml\",\n", " format=EntryFormat.SBML_L3V2,\n", " master=False,\n", " ),\n", " entry_path=results_dir / \"hello_world_sbml.xml\",\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "3e5b1bd2", "metadata": {}, "source": [ "Now we'll add our simple CellML model." ] }, { "cell_type": "code", "execution_count": 42, "id": "92c65b63", "metadata": {}, "outputs": [], "source": [ "# Add entry for the CellML model\n", "omex.add_entry(\n", " entry=ManifestEntry(\n", " location=\"./cellml/hello_world_cellml.cellml\",\n", " format=EntryFormat.CELLML,\n", " master=False,\n", " ),\n", " entry_path=results_dir / \"hello_world_cellml.cellml\",\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "7b59fb69", "metadata": {}, "source": [ "Next lets add entries for both our SBGN file and the png that it generated." ] }, { "cell_type": "code", "execution_count": 43, "id": "abfad069", "metadata": {}, "outputs": [], "source": [ "# Add entry for SBGN file\n", "omex.add_entry(\n", " entry=ManifestEntry(\n", " location=\"./sbgn/hello_world_sbgn.sbgn\",\n", " format=EntryFormat.SBGN,\n", " master=False,\n", " ),\n", " entry_path=results_dir / \"hello_world_sbgn.sbgn\",\n", ")\n", "\n", "# Add entry for corresponding png file generated from the SBGN\n", "omex.add_entry(\n", " entry=ManifestEntry(\n", " location=\"./sbgn/hello_world_sbgn.png\",\n", " format=EntryFormat.PNG,\n", " master=False,\n", " ),\n", " entry_path=results_dir / \"hello_world_sbgn.png\",\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "fbf60539", "metadata": {}, "source": [ "Finally, we will add a SED-ML file to the COMBINE archieve." ] }, { "cell_type": "code", "execution_count": 44, "id": "b8796964", "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Add entry for the SEDML simulation experiment\n", "omex.add_entry(\n", " entry=ManifestEntry(\n", " location=\"./sedml/hello_world_sedml.sedml\",\n", " format=EntryFormat.SEDML,\n", " master=False,\n", " ),\n", " entry_path=results_dir / \"hello_world_sedml.sedml\"\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "f55ed397", "metadata": {}, "source": [ "## 3) Write and print the COMBINE archieve" ] }, { "attachments": {}, "cell_type": "markdown", "id": "8560c376", "metadata": {}, "source": [ "And we're done creating the OMEX file. Now lets save it." ] }, { "cell_type": "code", "execution_count": 45, "id": "02f7c609", "metadata": {}, "outputs": [], "source": [ "RESULTS_DIR.mkdir(parents=True, exist_ok=True)\n", "omex_path = RESULTS_DIR / \"combine_hello_world.omex\"\n", "omex.to_omex(omex_path)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "227ebc87", "metadata": {}, "source": [ "We can also use the `console.print` function to display the comtent of the OMEX file." ] }, { "cell_type": "code", "execution_count": 46, "id": "09eda6c2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
[   ManifestEntry(location='.', format='http://identifiers.org/combine.specifications:omex', master=False),\n",
       "    ManifestEntry(location='./manifest.xml', format='http://identifiers.org/combine.specifications:omex-manifest', \n",
       "master=False),\n",
       "    ManifestEntry(location='./sbml/hello_world_sbml.xml', \n",
       "format='http://identifiers.org/combine.specifications:sbml.level-3.version-2', master=False),\n",
       "    ManifestEntry(location='./cellml/hello_world_cellml.cellml', \n",
       "format='http://identifiers.org/combine.specifications:cellml', master=False),\n",
       "    ManifestEntry(location='./sbgn/hello_world_sbgn.sbgn', \n",
       "format='http://identifiers.org/combine.specifications:sbgn', master=False),\n",
       "    ManifestEntry(location='./sbgn/hello_world_sbgn.png', format='https://purl.org/NET/mediatypes/image/png', \n",
       "master=False),\n",
       "    ManifestEntry(location='./sedml/hello_world_sedml.sedml', \n",
       "format='http://identifiers.org/combine.specifications:sed-ml', master=False)]\n",
       "
\n" ], "text/plain": [ "\u001b[1m[\u001b[0m \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'.'\u001b[0m, \u001b[33mformat\u001b[0m=\u001b[32m'http://identifiers.org/combine.specifications:omex'\u001b[0m, \u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m,\n", " \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'./manifest.xml'\u001b[0m, \u001b[33mformat\u001b[0m=\u001b[32m'http://identifiers.org/combine.specifications:omex-manifest'\u001b[0m, \n", "\u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m,\n", " \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'./sbml/hello_world_sbml.xml'\u001b[0m, \n", "\u001b[33mformat\u001b[0m=\u001b[32m'http://identifiers.org/combine.specifications:sbml.level-3.version-2'\u001b[0m, \u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m,\n", " \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'./cellml/hello_world_cellml.cellml'\u001b[0m, \n", "\u001b[33mformat\u001b[0m=\u001b[32m'http://identifiers.org/combine.specifications:cellml'\u001b[0m, \u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m,\n", " \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'./sbgn/hello_world_sbgn.sbgn'\u001b[0m, \n", "\u001b[33mformat\u001b[0m=\u001b[32m'http://identifiers.org/combine.specifications:sbgn'\u001b[0m, \u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m,\n", " \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'./sbgn/hello_world_sbgn.png'\u001b[0m, \u001b[33mformat\u001b[0m=\u001b[32m'https://purl.org/NET/mediatypes/image/png'\u001b[0m, \n", "\u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m,\n", " \u001b[1;35mManifestEntry\u001b[0m\u001b[1m(\u001b[0m\u001b[33mlocation\u001b[0m=\u001b[32m'./sedml/hello_world_sedml.sedml'\u001b[0m, \n", "\u001b[33mformat\u001b[0m=\u001b[32m'http://identifiers.org/combine.specifications:sed-ml'\u001b[0m, \u001b[33mmaster\u001b[0m=\u001b[3;91mFalse\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "console.print(omex)" ] } ], "metadata": { "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.11.1" } }, "nbformat": 4, "nbformat_minor": 5 }