SimpleSBML: A Python package for creating, editing, and interrogating SBML models: Version 2.0
aa r X i v : . [ q - b i o . M N ] S e p SimpleSBML: A Python package for creating, editing, andinterrogating SBML models: Verison 2.0
Herbert M. Sauro ∗ Department of Bioengineering,University of Washington, Seattle, WA 98195, USASeptember 2, 2020
Abstract
In this technical report, we describe a new version of SimpleSBML which provides an easier touse interface to python-libSBML allowing users of Python to more easily construct and inspectSBML based models. The most commonly used package for constructing SBML models in Pythonis python-libSBML based on the C/C++ library libSBML. python-libSBML is a comprehensivelibrary with a large range of options but can be difficult for new users to learn and requires longscripts to create even the simplest models. Inspecting existing SBML models can also be difficultdue to the complexity of the underlying object model. Instead, we present SimpleSBML, a packagethat allows users to add and inspect species, parameters, reactions, events, and rules to a libSBMLmodel with only one command for each. Models can be exported to SBML format, and SBMLfiles can be imported and converted to SimpleSBML commands that create each element in a newmodel. This allows users to create new models and edit existing models for use with other software.In the new version, a range of ‘get’ methods is provided that allows users to inspect existing SBMLmodels without having to understand the underlying object model used by libSBML.
Accessibility and Implementation:
SimpleSBML is publicly available and licensed under the liberal MIT open source license. It supportsSBML levels 2 and 3. Its only dependency is libSBML. It is supported on Windows and Mac OSX but should also work on Linux (untested). All code has been deposited at the GitHub site https://github.com/sys-bio/simplesbml and is available for user installation via a standard pip install simplesbml . Contact: [email protected]
Supplementary information:
Documentation and download is available at sys-bio.github.io/simplesbml as well as a pipinstall on pypi ∗ to whom correspondence should be addressed Introduction
In an earlier report [4] we described SimpleSBML, a python library that makes it much easier tocreate SBML models. In this document, we describe a new version of simpleSBML that extends thefunctionality of simpleSBML to now include a series of get methods to easily extract informationfrom an existing SBML model.Biological modeling is a key component of systems biology, and the development of Systems BiologyMarkup Language (SBML) [1], a markup language designed to describe models of biological systems,has allowed systems and synthetic biologists to develop a plethora of useful software tools that areautomatically compatible with each other through SBML document import and export. CreatingSBML models is possible with a variety of software packages, the most well-known of which islibSBML [2]. This package allows users to generate SBML documents by writing scripts in Python,C or C++. While libSBML is very useful, it can be difficult to learn for novices and even thesimplest of models using libSBML tend to be very long. SimpleSBML is a package that also allowsusers to create SBML models with Python scripting, but requires far fewer commands and is moreaccessible for beginner users. One other difference between version 1 and 2 is that the class namehas been capitalized to match common practice in Python code, hence use
SbmlModel instead of sbmlModel .SimpleSBML makes use of libSBML methods to add and isspect elements such as species, pa-rameters, reaction, events and rules to a model, and generate an SBML-formatted document fromthe resulting model object. SimpleSBML also includes two new methods that allow users to loadexisting SBML modls either from a string or file. SimpleSBML can therefore be used to editSBML-formatted models as well as create new ones.
Verison 1.0 of simplesbml is given in the previous publication [4] and the examples for creating a newSBML model will not be repeated other than giving one example for reference. The SbmlModel class,holds a SBMLDocument object and contains methods that can be used to add different elements,such as species, parameters, reactions and events. Here is an example of a simple reaction-basedmodel built with SbmlModel. import s i m p l e s b m lmodel = s i m p l e s b m l. s b m l M o d e l ();model . a d d C o m p a r t m e n t (1 e -14 , comp_id = ’ comp ’ );model . a d d S p e c i e s( ’E ’ , 5e -21 , comp = ’ comp ’ );model . a d d S p e c i e s( ’S ’ , 1e -20 , comp = ’ comp ’ );model . a d d S p e c i e s( ’P ’ , 0.0 , comp = ’ comp ’ );model . a d d S p e c i e s( ’ ES ’ , 0.0 , comp = ’ comp ’ );model . a d d R e a c t i o n ([ ’E ’ , ’S ’] , [ ’ ES ’ ] , ’ comp *( kon * E *S - koff * ES ) ’ , \l o c a l _ p a r a m s ={ ’ koff ’ : 0.2 , ’ kon ’: 1000000.0} , rxn_id = ’ veq ’ );model . a d d R e a c t i o n ([ ’ ES ’] , [ ’ E ’ , ’P ’ ] , ’ comp * kcat * ES ’ , \l o c a l _ p a r a m s ={ ’ kcat ’: 0.1} , rxn_id = ’ vcat ’ ); .1 New get API
Of more interest is the new get
API that allows an existing SBML model to be easily inspected.This section will discuss the new get
API that verison 2.0 has. The first change is to allow existingSBML models to be loaded into simpleSBML. The existing constructor
SBMLModel was modified toaccept SBML strings and file names containing SBML. To make the interface simpler to use, twoadditional methods outside the class, loadSBMLStr and loadSBMLFile are provided. For example,to load a file one can use the following code: model = simplesbml.loadSBMLFile (’mymodel.xml’)
This returns an instance of
SbmlModel . The online documentation gives a full list of methods thatare available but a comment on the naming and class structure philosophy is in order. To beginwith, the entire API is flat, that is there are no subclasses which one finds, for example, in libsbml.This means a user does not need to know the underlying object model in order to effectively usethe API. However to make this work, the names for the API methods must be clear in what theydo and can be identified using intellisense and code completion in IDEs (Integrated DevelopmentEnvironment) such as spyder ( ). For example, to obtain the list ofreaction Ids in a model requires the following code when using libsbml: n R e a c t i o n s = document . model . g e t N u m R e a c t i o n s ()for i in range ( n R e a c t i o n s ):p = document . model . g e t R e a c t i o n( i )print ( p . getId ()) where document was obtained by calling the libsbml method: document = reader.readSBMLFromString(sbmlStr) .This requires three levels of indirection as well as knowledge of the various methods to call at eachlevel. Instead, simplesbml allows a user to call a single method: print ( model . g e t L i s t O f R e a c t i o n I d s ())
The method name is qualified with the term
Ids because one could also retrieve the SBML namesrather than the Ids. The entire API is built along these lines. As an illustration, the code below willuse simplesbml to construct the stoichiometric matrix for a model. Tellurium [5] is used to convertthe reaction scheme in antimony [6] format into SBML which is then loaded into simplesbml. import t e l l u r i u m as te , simplesbml , numpy as npr = te . loada ( """S0 + S3 -> S2 ; k0 * S0 * S3 ;S3 + S2 -> S0 ; k1 * S3 * S2 ;S5 -> S2 + S4 ; k2 * S5 ;S0 + S1 -> S3 ; k3 * S0 * S1 ;S5 -> S0 + S4 ; k4 * S5 ;S0 -> S5 ; k5 * S0 ;S1 + S1 -> S5 ; k6 * S1 * S1 ;S3 + S5 -> S1 ; k7 * S3 * S5 ;S1 -> $S4 + S4 ; k8 * S1 ;S0 = 0; S1 = 0; S2 = 0; S3 = 0; S4 = 0; S5 = 0;k0 = 0; k1 = 0; k2 = 0; k3 = 0; k4 = 0 The resulting stoichiometry matrix is given by: [[ -1. 1. 0. -1. 1. -1. 0. 0. 0.][ -1. -1. 0. 1. 0. 0. 0. -1. 0.][ 1. -1. 1. 0. 0. 0. 0. 0. 0.][ 0. 0. -1. 0. -1. 1. 1. -1. 0.][ 0. 0. 0. -1. 0. 0. -2. 1. -1.]]
SimpleSBML depends on python-libSBML so that libSBML must be installed. Refer to the https://pypi.python.org/pypi/python-libsbml for details. SimpleSBML can installed using the standard pip mechanism for Python packages byusing the command: pip install simplesbml
When using more sophisticated Python environments such as Jupyter ( https://jupyter.org/ ),Spyder or PyCharm ( ), it is possible to type pip installsimplesbml at the Python console itself and the package will be installed automatically. If you’reusing a more basic Python console such as Idle, you will need to use the pip command fromthe operating system terminal. Make sure that Python and pip are on the search path if you4ake this approach. On Windows the easiest way to get simplesbml is to install the Telluriummodeling package found at http://tellurium.analogmachine.org/ . This comes ready bundledwith simplesbml.
Documentation is generated from comments in source code using sphinx and uploaded to readthe-docs. Additional documentation is provided by including text in the index.rst file.Testing was originally done using the Python unittest ( https://docs.python.org/3/library/unittest.html )package but was found to have limit capabilities. The missing functionality included an easy wayto test the API on a variety of loaded SBML models and to exercise the API more thoroughly. Such aworkflow is not supported well by unittest. Instead pyTest ( https://docs.pytest.org/en/stable/ )was tried which does support parameterized tests but the code became too verbose and unwieldy.Instead a very simple testing framework was written which was ultimately easier to add new teststo. The test file is called runTests.py and is located in the tests folder. To trun the tests, simplerun this file from Python.
SimpleSBML is intended for systems biology researchers who have limited experience with pro-gramming, or are working on simple models and prefer to use a simpler set of commands comparedto libSBML. Future additions to the software may include additional methods to deal with modelannotations.
Acknowledgments
Funding:
The authors are most grateful to generous funding from the National Institute of Gen-eral Medical Sciences of the National Institutes of Health under award R01GM-123032 as well asthe NSF award CCF-0432190. The content is solely the responsibility of the authors and does notnecessarily represent the official views of the National Institutes of Health, the National ScienceFoundation, or the University of Washington. I thank Joe Hellerstein, Lucian Smith and CiaranWelsh for useful discussions.
References [1] Hucka, M., A. Finney, H. M. Sauro, et al. (2003) The Systems Biology Markup Language(SBML): A Medium for Representation and Exchange of Biochemical Network Models.
Bioin-formatics