#!/usr/bin/env python # coding: utf-8 # [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/combine-org/combine-notebooks/main?labpath=%2Fnotebooks%2Fomex.ipynb) # Open In Colab\ # # Simple OMEX example # 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). # ## 1) Including libraries # Note: Please change the `colab` flag to `True` if you are using Google Colab. # In[2]: colab = False if colab: get_ipython().system('pip install git+https://github.com/combine-org/combine-notebooks') get_ipython().system('git clone https://github.com/combine-org/combine-notebooks') get_ipython().run_line_magic('cd', '/content/combine-notebooks/notebooks') # In[38]: from pathlib import Path from pymetadata.console import console from pymetadata.omex import EntryFormat, ManifestEntry, Omex from combine_notebooks import RESULTS_DIR # ## 2) Creating a COMBINE archieve # Creating an empty archive and adding entry for SBML. # In[39]: # Create OMEX archive of resources. omex = Omex() # 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: # - hello_world_sbml.xml - a simple SBML model # - hello_world_cellml.cellml - a simple CellML model # - hello_world_sbgn.png - a diagram showing a simple reacton that has been generated using SBGN # - hello_world_sbgn.sbgn - correponding SBGN used to generate the .png file # - hello_world_sedml.sedml - a simple simulation experiment described using SED-ML # In[40]: # Path to our results results_dir = Path(RESULTS_DIR.stem) # First, lets add our simple SBML file into the COMBINE archieve. # In[41]: # Add entry for the SBML model omex.add_entry( entry=ManifestEntry( location="./sbml/hello_world_sbml.xml", format=EntryFormat.SBML_L3V2, master=False, ), entry_path=results_dir / "hello_world_sbml.xml", ) # Now we'll add our simple CellML model. # In[42]: # Add entry for the CellML model omex.add_entry( entry=ManifestEntry( location="./cellml/hello_world_cellml.cellml", format=EntryFormat.CELLML, master=False, ), entry_path=results_dir / "hello_world_cellml.cellml", ) # Next lets add entries for both our SBGN file and the png that it generated. # In[43]: # Add entry for SBGN file omex.add_entry( entry=ManifestEntry( location="./sbgn/hello_world_sbgn.sbgn", format=EntryFormat.SBGN, master=False, ), entry_path=results_dir / "hello_world_sbgn.sbgn", ) # Add entry for corresponding png file generated from the SBGN omex.add_entry( entry=ManifestEntry( location="./sbgn/hello_world_sbgn.png", format=EntryFormat.PNG, master=False, ), entry_path=results_dir / "hello_world_sbgn.png", ) # Finally, we will add a SED-ML file to the COMBINE archieve. # In[44]: # Add entry for the SEDML simulation experiment omex.add_entry( entry=ManifestEntry( location="./sedml/hello_world_sedml.sedml", format=EntryFormat.SEDML, master=False, ), entry_path=results_dir / "hello_world_sedml.sedml" ) # ## 3) Write and print the COMBINE archieve # And we're done creating the OMEX file. Now lets save it. # In[45]: RESULTS_DIR.mkdir(parents=True, exist_ok=True) omex_path = RESULTS_DIR / "combine_hello_world.omex" omex.to_omex(omex_path) # We can also use the `console.print` function to display the comtent of the OMEX file. # In[46]: console.print(omex)