{ "cells": [ { "cell_type": "markdown", "id": "2e806b7a", "metadata": {}, "source": [ "Example for creating a COMBINE archive." ] }, { "cell_type": "code", "execution_count": 2, "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" ] }, { "cell_type": "markdown", "id": "565b2c61", "metadata": {}, "source": [ "Creating an empty archive and adding entry for SBML." ] }, { "cell_type": "code", "execution_count": 6, "id": "b8796964", "metadata": { "collapsed": false }, "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" }, { "data": { "text/html": [ "
WARNING  Existing omex is overwritten:                                                                  omex.py:680\n",
       "         '/home/vboxuser/Documents/compbiolibs/combine-notebooks/results/combine_hello_world.omex'                 \n",
       "
\n" ], "text/plain": [ "\u001b[31mWARNING \u001b[0m Existing omex is overwritten: \u001b]8;id=296905;file:///home/vboxuser/.local/lib/python3.10/site-packages/pymetadata/omex.py\u001b\\\u001b[2momex.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=280012;file:///home/vboxuser/.local/lib/python3.10/site-packages/pymetadata/omex.py#680\u001b\\\u001b[2m680\u001b[0m\u001b]8;;\u001b\\\n", " \u001b[32m'/home/vboxuser/Documents/compbiolibs/combine-notebooks/results/combine_hello_world.omex'\u001b[0m \u001b[2m \u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def create_omex(omex_path: Path, results_dir: Path) -> None:\n", " \"\"\"Create OMEX archive of resources.\"\"\"\n", " omex = Omex()\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", " )\n", "\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", " )\n", "\n", " \"\"\"omex.add_entry(\n", " entry=ManifestEntry(\n", " location=\"./biopax/repressilator_biopax.owl\",\n", " format=EntryFormat.BIOPAX,\n", " master=False,\n", " ),\n", " entry_path=results_dir / \"repressilator_biopax.owl\",\n", " )\"\"\"\n", "\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", " 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", " )\n", "\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", " # FIXME: add the model relative and test\n", " )\n", "\n", " console.print(omex)\n", " omex.to_omex(omex_path)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " from combine_notebooks import RESULTS_DIR\n", "\n", " create_omex(omex_path=RESULTS_DIR / \"combine_hello_world.omex\", results_dir=RESULTS_DIR)\n", "\n", " # " ] }, { "cell_type": "code", "execution_count": null, "id": "0cc8164b", "metadata": {}, "outputs": [], "source": [] } ], "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.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }