libSBML C++ API  5.20.2
qual_example1.cpp

An example of creating a model using SBML Level 3 Qualitative Models.

/**
* @file example1.cpp
* @brief SBML Qual example
* @author Sarah Keating
*
* <!--------------------------------------------------------------------------
* This sample program is distributed under a different license than the rest
* of libSBML. This program uses the open-source MIT license, as follows:
*
* Copyright (c) 2013-2018 by the California Institute of Technology
* (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
* and the University of Heidelberg (Germany), with support from the National
* Institutes of Health (USA) under grant R01GM070923. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Neither the name of the California Institute of Technology (Caltech), nor
* of the European Bioinformatics Institute (EMBL-EBI), nor of the University
* of Heidelberg, nor the names of any contributors, may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* ------------------------------------------------------------------------ -->
*/
#include <iostream>
#include "sbml/SBMLTypes.h"
LIBSBML_CPP_NAMESPACE_USE
int main(int argc,char** argv)
{
if (argc != 2)
{
std::cout << "Usage: example1\n";
return 1;
}
//
// Creates an SBMLNamespaces object with the given SBML level, version
// package name, package version.
//
// (NOTE) By defualt, the name of package (i.e. "qual") will be used
// if the arugment for the prefix is missing or empty. Thus the argument
// for the prefix can be added as follows:
//
// SBMLNamespaces sbmlns(3,1,"qual",1,"QUAL");
//
SBMLNamespaces sbmlns(3,1,"qual",1);
//
// (NOTES) The above code creating an SBMLNamespaces object can be replaced
// with one of the following other styles.
//
// (1) Creates an SBMLNamespace object with a SBML core namespace and then
// adds a qual package namespace to the object.
//
// SBMLNamespaces sbmlns(3,1);
// sbmlns.addPkgNamespace("qual",1);
//
// OR
//
// SBMLNamespaces sbmlns(3,1);
// sbmlns.addNamespace(QualExtension::XmlnsL3V1V1,"qual");
//
// (2) Creates a QualPkgNamespaces object (SBMLNamespace derived class for
// qual package. The class is basically used for createing an SBase
// derived objects defined in the qual package) with the given SBML
// level, version, and package version
//
// QualPkgNamespaces sbmlns(3,1,1);
//
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
// mark qual as required
document->setPackageRequired("qual", true);
// create the Model
Model* model=document->createModel();
// create the Compartment
Compartment* compartment = model->createCompartment();
compartment->setId("c");
compartment->setConstant(true);
//
// Get a QualModelPlugin object plugged in the model object.
//
// The type of the returned value of SBase::getPlugin() function is
// SBasePlugin*, and thus the value needs to be casted for the
// corresponding derived class.
//
QualModelPlugin* mplugin
= static_cast<QualModelPlugin*>(model->getPlugin("qual"));
// create the QualitativeSpecies
qs->setId("s1");
qs->setCompartment("c");
qs->setConstant(false);
qs->setMaxLevel(4);
qs->setName("sss");
// create the Transition
Transition* t = mplugin->createTransition();
t->setId("d");
t->setSBOTerm(1);
Input* i = t->createInput();
i->setId("RD");
i->setName("aa");
Output* o = t->createOutput();
o->setId("wd");
o->setName("aa");
dt->setResultLevel(2) ;
ASTNode* math = SBML_parseL3Formula("geq(s1, 2)");
ft->setMath(math);
writeSBML(document,"qual_example1.xml");
delete document;
return 0;
}
@ INPUT_TRANSITION_EFFECT_NONE
Definition: Input.h:78
@ INPUT_SIGN_NEGATIVE
Definition: Input.h:90
ASTNode_t * SBML_parseL3Formula(const char *formula)
Parses a text string as a mathematical formula and returns an AST representation of it.
Definition: L3Parser.cpp:3235
@ OUTPUT_TRANSITION_EFFECT_PRODUCTION
Definition: Output.h:82
Include all SBML types of qual extension in a single header file.
Include all SBML types in a single header file.
int writeSBML(const SBMLDocument_t *d, const char *filename)
Writes the given SBML document d to the file named by filename.
Definition: ASTNode.h:221
Definition: Compartment.h:490
int setConstant(bool value)
Sets the value of the "constant" attribute of this Compartment object.
Definition: Compartment.cpp:661
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Compartment object.
Definition: Compartment.cpp:479
Definition: DefaultTerm.h:75
virtual int setResultLevel(int resultLevel)
Sets the value of the "resultLevel" attribute of this DefaultTerm.
Definition: DefaultTerm.cpp:153
Definition: FunctionTerm.h:85
virtual int setMath(const ASTNode *math)
Sets the "math" element of this FunctionTerm.
Definition: FunctionTerm.cpp:207
virtual int setResultLevel(int resultLevel)
Sets the value of the "resultLevel" attribute of this FunctionTerm.
Definition: FunctionTerm.cpp:195
Definition: Input.h:114
int setTransitionEffect(const InputTransitionEffect_t transitionEffect)
Sets the value of the "transitionEffect" attribute of this Input.
Definition: Input.cpp:301
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this obInputject.
Definition: Input.cpp:273
virtual int setName(const std::string &name)
Sets the value of the "name" attribute of this Input.
Definition: Input.cpp:320
virtual int setThresholdLevel(int thresholdLevel)
Sets the value of the "thresholdLevel" attribute of this Input.
Definition: Input.cpp:350
int setSign(const InputSign_t sign)
Sets the value of the "sign" attribute of this Input.
Definition: Input.cpp:331
virtual int setQualitativeSpecies(const std::string &qualitativeSpecies)
Sets the value of the "qualitativeSpecies" attribute of this Input.
Definition: Input.cpp:283
Definition: Model.h:485
Compartment * createCompartment()
Creates a new Compartment inside this Model and returns it.
Definition: Model.cpp:1558
Definition: Output.h:105
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Output.
Definition: Output.cpp:249
int setTransitionEffect(const OutputTransitionEffect_t transitionEffect)
Sets the value of the "transitionEffect" attribute of this Output.
Definition: Output.cpp:277
virtual int setQualitativeSpecies(const std::string &qualitativeSpecies)
Sets the value of the "qualitativeSpecies" attribute of this Output.
Definition: Output.cpp:259
virtual int setOutputLevel(int outputLevel)
Sets the value of the "outputLevel" attribute of this Output.
Definition: Output.cpp:309
virtual int setName(const std::string &name)
Sets the value of the "name" attribute of this Output.
Definition: Output.cpp:296
Definition: QualModelPlugin.h:70
Transition * createTransition()
Creates a new qual object and adds it to the list of qual objects and returns it.
QualitativeSpecies * createQualitativeSpecies()
Creates a new qual object and adds it to the list of qual objects and returns it.
Definition: QualitativeSpecies.h:96
virtual int setInitialLevel(int initialLevel)
Sets the value of the "initialLevel" attribute of this QualitativeSpecies.
Definition: QualitativeSpecies.cpp:333
virtual int setMaxLevel(int maxLevel)
Sets the value of the "maxLevel" attribute of this QualitativeSpecies.
Definition: QualitativeSpecies.cpp:345
virtual int setCompartment(const std::string &compartment)
Sets the value of the "compartment" attribute of this QualitativeSpecies.
Definition: QualitativeSpecies.cpp:291
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this QualitativeSpecies.
Definition: QualitativeSpecies.cpp:281
virtual int setConstant(bool constant)
Sets the value of the "constant" attribute of this QualitativeSpecies.
Definition: QualitativeSpecies.cpp:309
virtual int setName(const std::string &name)
Sets the value of the "name" attribute of this QualitativeSpecies.
Definition: QualitativeSpecies.cpp:321
Definition: SBMLDocument.h:349
int setPackageRequired(const std::string &package, bool flag)
Sets the required attribute value of the given package extension.
Definition: SBMLDocument.cpp:1414
Model * createModel(const std::string sid="")
Creates a new Model inside this SBMLDocument, and returns a pointer to it.
Definition: SBMLDocument.cpp:627
Definition: SBMLNamespaces.h:145
virtual int setSBOTerm(int value)
Sets the value of the "sboTerm" attribute.
Definition: SBase.cpp:2515
SBasePlugin * getPlugin(const std::string &package)
Returns a plug-in object (extension interface) for an SBML Level&#160;3 package extension with the given p...
Definition: SBase.cpp:3530
Definition: Transition.h:101
Output * createOutput()
Creates a new Output object, adds it to this Transition's ListOfOutputs and returns the Output object...
Definition: Transition.cpp:638
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Transition.
Definition: Transition.cpp:242
FunctionTerm * createFunctionTerm()
Creates a new FunctionTerm object, adds it to this Transition's ListOfFunctionTerms and returns the F...
Definition: Transition.cpp:796
Input * createInput()
Creates a new Input object, adds it to this Transition's ListOfInputs and returns the Input object cr...
Definition: Transition.cpp:454
DefaultTerm * createDefaultTerm()
Creates a new DefaultTerm object, adds it to this Transition's ListOfFunctionTerms and returns the De...
Definition: Transition.cpp:823