libSBML C++ API  5.20.4
example3.cpp

An example layout.

/**
* @file example3.cpp
* @brief SBML Layout example
* @author Ralph Gauges
* @author Akiya Jouraku (Modified this file for layout package of SBML Level 3
* in libSBML 5)
*
* Copyright 2004 European Media Laboratories Research gGmbH
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
* documentation provided hereunder is on an "as is" basis, and the
* European Media Laboratories Research gGmbH have no obligations to
* provide maintenance, support, updates, enhancements or modifications.
* In no event shall the European Media Laboratories Research gGmbH be
* liable to any party for direct, indirect, special, incidental or
* consequential damages, including lost profits, arising out of the use of
* this software and its documentation, even if the European Media
* Laboratories Research gGmbH have been advised of the possibility of such
* damage. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The original code contained here was initially developed by:
*
* Ralph Gaugess
* Bioinformatics Group
* European Media Laboratories Research gGmbH
* Schloss-Wolfsbrunnenweg 31c
* 69118 Heidelberg
* Germany
*
* http://www.eml-research.de/english/Research/BCB/
* mailto:ralph.gauges@eml-r.villa-bosch.de
*/
#include "sbml/SBMLTypes.h"
#if (!defined LIBSBML_HAS_PACKAGE_LAYOUT)
#error "This example requires libSBML to be built with the layout extension."
#endif
LIBSBML_CPP_NAMESPACE_USE
int main(int argc, char** argv)
{
//
// Creates an SBMLNamespaces object with the given SBML level, version
// package name.
//
SBMLNamespaces sbmlns(2, 3);
// (NOTES) The above code creating an SBMLNamespaces object can be replaced
// with the following other style.
//
// (2) Creates a LayoutPkgNamespaces object (SBMLNamespace derived class
// for layout package. The class is basically used for createing an
// SBase derived objects belonging to the layout package) with the
// given SBML level, version. (Package version is not required by
// Layout extension of SBML Level 2)
//
// LayoutPkgNamespaces sbmlns(2, 3);
//
// create the document
SBMLDocument *document = new SBMLDocument(&sbmlns);
// create the Model
Model* model = document->createModel();
model->setId("TestModel_with_modifiers");
document->setModel(model);
// create the Layout
LayoutPkgNamespaces layoutns(2, 3);
= static_cast<LayoutModelPlugin*>(model->getPlugin("layout"));
Layout* layout = mplugin->createLayout();
layout->setId("Layout_1");
Dimensions dim(&layoutns, 400.0, 230.0);
layout->setDimensions(&dim);
// create the Compartment
Compartment* compartment = model->createCompartment();
compartment->setId("Yeast");
// create the CompartmentGlyph
CompartmentGlyph* compartmentGlyph = layout->createCompartmentGlyph();
compartmentGlyph->setId("CompartmentGlyph_1");
compartmentGlyph->setCompartmentId(compartment->getId());
BoundingBox bb(&layoutns, "bb1", 5, 5, 390, 220);
compartmentGlyph->setBoundingBox(&bb);
// create the Species, SpeciesGlyphs and associated TextGlyphs
// Glucose
Species* species_Gluc = model->createSpecies();
species_Gluc->setId("Glucose");
species_Gluc->setCompartment(compartment->getId());
SpeciesGlyph* glyph_Gluc = layout->createSpeciesGlyph();
glyph_Gluc->setId("SpeciesGlyph_Glucose");
glyph_Gluc->setSpeciesId(species_Gluc->getId());
bb = BoundingBox(&layoutns, "bb2", 105, 20, 130, 20);
glyph_Gluc->setBoundingBox(&bb);
TextGlyph* tGlyph = layout->createTextGlyph();
tGlyph->setId("TextGlyph_Glucose");
bb = BoundingBox(&layoutns, "bbA", 115, 20, 110, 20);
tGlyph->setBoundingBox(&bb);
tGlyph->setOriginOfTextId(species_Gluc->getId());
tGlyph->setGraphicalObjectId(glyph_Gluc->getId());
// Glucose-6-phosphate
Species* species_G6P = model->createSpecies();
species_G6P->setId("Glucose_hyphen_6_hyphen_phosphate");
species_G6P->setCompartment(compartment->getId());
SpeciesGlyph* glyph_G6P = layout->createSpeciesGlyph();
glyph_G6P->setId("SpeciesGlyph_G6P");
glyph_G6P->setSpeciesId(species_G6P->getId());
bb = BoundingBox(&layoutns, "bb5", 50, 190, 270, 20);
glyph_G6P->setBoundingBox(&bb);
tGlyph = layout->createTextGlyph();
tGlyph->setId("TextGlyph_G6P");
bb = BoundingBox(&layoutns, "bbD", 60, 190, 250, 20);
tGlyph->setBoundingBox(&bb);
tGlyph->setOriginOfTextId(species_G6P->getId());
tGlyph->setGraphicalObjectId(glyph_G6P->getId());
// ATP
Species* species_ATP = model->createSpecies();
species_ATP->setId("ATP");
species_ATP->setCompartment(compartment->getId());
SpeciesGlyph* glyph_ATP = layout->createSpeciesGlyph();
glyph_ATP->setId("SpeciesGlyph_ATP");
glyph_ATP->setSpeciesId(species_ATP->getId());
bb = BoundingBox(&layoutns, "bb3", 270, 70, 80, 20);
glyph_ATP->setBoundingBox(&bb);
tGlyph = layout->createTextGlyph();
tGlyph->setId("TextGlyph_ATP");
bb = BoundingBox(&layoutns, "bbB", 280, 70, 60, 20);
tGlyph->setBoundingBox(&bb);
tGlyph->setOriginOfTextId(species_ATP->getId());
tGlyph->setGraphicalObjectId(glyph_ATP->getId());
// ADP
Species* species_ADP = model->createSpecies();
species_ADP->setId("ADP");
species_ADP->setCompartment(compartment->getId());
SpeciesGlyph* glyph_ADP = layout->createSpeciesGlyph();
glyph_ADP->setId("glyph_ADP");
glyph_ADP->setSpeciesId(species_ADP->getId());
bb = BoundingBox(&layoutns, "bb4", 270, 140, 80, 20);
glyph_ADP->setBoundingBox(&bb);
tGlyph = layout->createTextGlyph();
tGlyph->setId("TextGlyph_ADP");
bb = BoundingBox(&layoutns, "bbC", 280, 140, 60, 20);
tGlyph->setBoundingBox(&bb);
tGlyph->setOriginOfTextId(species_ADP->getId());
tGlyph->setGraphicalObjectId(glyph_ADP->getId());
// Phosphate
Species* species_Pi = model->createSpecies();
species_Pi->setId("Pi");
species_Pi->setCompartment(compartment->getId());
SpeciesGlyph* glyph_Pi = layout->createSpeciesGlyph();
glyph_Pi->setId("SpeciesGlyph_Pi");
glyph_Pi->setSpeciesId(species_Pi->getId());
bb = BoundingBox(&layoutns, "bb6", 50, 100, 60, 20);
glyph_Pi->setBoundingBox(&bb);
tGlyph = layout->createTextGlyph();
tGlyph->setId("TextGlyph_PI");
bb = BoundingBox(&layoutns, "bbE", 60, 100, 40, 20);
tGlyph->setBoundingBox(&bb);
tGlyph->setOriginOfTextId(species_Pi->getId());
tGlyph->setGraphicalObjectId(glyph_Pi->getId());
// create the Reaction
Reaction* reaction_Hexokinase = model->createReaction();
reaction_Hexokinase->setId("Hexokinase");
reaction_Hexokinase->setReversible(false);
ReactionGlyph* glyph_Hexokinase = layout->createReactionGlyph();
glyph_Hexokinase->setId("glyph_Hexokinase");
glyph_Hexokinase->setReactionId(reaction_Hexokinase->getId());
Curve* curve_Hexokinase = glyph_Hexokinase->getCurve();
LineSegment* ls = curve_Hexokinase->createLineSegment();
Point p(&layoutns, 170, 100);
ls->setStart(&p);
p = Point(&layoutns, 170, 130);
ls->setEnd(&p);
// create the species reference for glucose
SpeciesReference* reference_Gluc = reaction_Hexokinase->createReactant();
reference_Gluc->setSpecies(species_Gluc->getId());
reference_Gluc->setId("SpeciesReference_Glucose");
// create species reference glyph for glucose
SpeciesReferenceGlyph* speciesReferenceGlyph
= glyph_Hexokinase->createSpeciesReferenceGlyph();
speciesReferenceGlyph->setId("SpeciesReferenceGlyph_Glucose");
speciesReferenceGlyph->setSpeciesGlyphId(glyph_Gluc->getId());
speciesReferenceGlyph->setSpeciesReferenceId(reference_Gluc->getId());
speciesReferenceGlyph->setRole(SPECIES_ROLE_SUBSTRATE);
ls = speciesReferenceGlyph->createLineSegment();
p = Point(&layoutns, 170, 100);
ls->setStart(&p);
p = Point(&layoutns, 170, 50);
ls->setEnd(&p);
// create species reference for ATP
SpeciesReference* reference_ATP
= reaction_Hexokinase->createReactant();
reference_ATP->setSpecies(species_ATP->getId());
reference_ATP->setId("SpeciesReference_ATP");
// create the species reference glyph for ATP
speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph();
speciesReferenceGlyph->setId("SpeciesReferenceGlyph_ATP");
speciesReferenceGlyph->setSpeciesGlyphId(glyph_ATP->getId());
speciesReferenceGlyph->setSpeciesReferenceId(reference_ATP->getId());
speciesReferenceGlyph->setRole(SPECIES_ROLE_SIDESUBSTRATE);
CubicBezier* cb = speciesReferenceGlyph->createCubicBezier();
p = Point(&layoutns, 170, 100);
cb->setStart(&p);
p = Point(&layoutns, 170, 80);
cb->setBasePoint1(&p);
p = Point(&layoutns, 170, 80);
cb->setBasePoint2(&p);
p = Point(&layoutns, 260, 80);
cb->setEnd(&p);
// create species reference for G6P
SpeciesReference* reference_G6P = reaction_Hexokinase->createProduct();
reference_G6P->setSpecies(species_G6P->getId());
reference_G6P->setId("SpeciesReference_G6P");
// create species reference for G6P as product
speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph();
speciesReferenceGlyph->setId("SpeciesReferenceGlyph_G6P_1");
speciesReferenceGlyph->setSpeciesGlyphId(glyph_G6P->getId());
speciesReferenceGlyph->setSpeciesReferenceId(reference_G6P->getId());
speciesReferenceGlyph->setRole(SPECIES_ROLE_PRODUCT);
ls = speciesReferenceGlyph->createLineSegment();
p = Point(&layoutns, 170, 130);
ls->setStart(&p);
p = Point(&layoutns, 170, 180);
ls->setEnd(&p);
// create species reference for ADP
SpeciesReference* reference_ADP = reaction_Hexokinase->createProduct();
reference_ADP->setSpecies(species_ADP->getId());
reference_ADP->setId("SpeciesReference_ADP");
// create the species reference glyph for ADP
speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph();
speciesReferenceGlyph->setId("SpeciesReferenceGlyph_ADP");
speciesReferenceGlyph->setSpeciesGlyphId(glyph_ADP->getId());
speciesReferenceGlyph->setSpeciesReferenceId(reference_ADP->getId());
speciesReferenceGlyph->setRole(SPECIES_ROLE_SIDEPRODUCT);
cb = speciesReferenceGlyph->createCubicBezier();
p = Point(&layoutns, 170, 130);
cb->setStart(&p);
p = Point(&layoutns, 170, 150);
cb->setBasePoint1(&p);
p = Point(&layoutns, 170, 150);
cb->setBasePoint2(&p);
p = Point(&layoutns, 260, 150);
cb->setEnd(&p);
// create modifier species reference for glucose-6-phosphate
ModifierSpeciesReference* reference_G6P_2
= reaction_Hexokinase->createModifier();
reference_G6P_2->setSpecies(species_G6P->getId());
reference_G6P_2->setId("ModifierSpeciesReference_G6P");
reaction_Hexokinase->addModifier(reference_G6P_2);
// create species reference glyph for G6P as a modifier
speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph();
speciesReferenceGlyph->setId("SpeciesReferenceGlyph_G6P_2");
speciesReferenceGlyph->setSpeciesReferenceId(reference_G6P_2->getId());
speciesReferenceGlyph->setSpeciesGlyphId(glyph_G6P->getId());
speciesReferenceGlyph->setRole(SPECIES_ROLE_INHIBITOR);
cb = speciesReferenceGlyph->createCubicBezier();
p = Point(&layoutns, 45, 200);
cb->setStart(&p);
p = Point(&layoutns, 0, 200);
cb->setBasePoint1(&p);
p = Point(&layoutns, 0, 120);
cb->setBasePoint2(&p);
p = Point(&layoutns, 165, 120);
cb->setEnd(&p);
// create modifier species reference for phosphate
ModifierSpeciesReference* reference_Pi = reaction_Hexokinase->createModifier();
reference_Pi->setSpecies(species_Pi->getId());
reference_Pi->setId("ModifierSpeciesReference_Pi");
reaction_Hexokinase->addModifier(reference_Pi);
// create the species reference glyph for Phosphate
speciesReferenceGlyph = glyph_Hexokinase->createSpeciesReferenceGlyph();
speciesReferenceGlyph->setId("SpeciesReferenceGlyph_PI");
speciesReferenceGlyph->setSpeciesReferenceId(reference_Pi->getId());
speciesReferenceGlyph->setSpeciesGlyphId(glyph_Pi->getId());
speciesReferenceGlyph->setRole(SPECIES_ROLE_ACTIVATOR);
cb = speciesReferenceGlyph->createCubicBezier();
p = Point(&layoutns, 115, 110);
cb->setStart(&p);
p = Point(&layoutns, 140, 110);
cb->setBasePoint1(&p);
p = Point(&layoutns, 140, 110);
cb->setBasePoint2(&p);
p = Point(&layoutns, 165, 110);
cb->setEnd(&p);
// write model to file
writeSBML(document, "layout_example3_L2.xml");
delete document;
}
Include all SBML types of layout 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.
@ SPECIES_ROLE_SUBSTRATE
Definition: SpeciesReferenceRole.h:61
@ SPECIES_ROLE_PRODUCT
Definition: SpeciesReferenceRole.h:62
@ SPECIES_ROLE_SIDEPRODUCT
Definition: SpeciesReferenceRole.h:64
@ SPECIES_ROLE_ACTIVATOR
Definition: SpeciesReferenceRole.h:66
@ SPECIES_ROLE_INHIBITOR
Definition: SpeciesReferenceRole.h:67
@ SPECIES_ROLE_SIDESUBSTRATE
Definition: SpeciesReferenceRole.h:63
Definition: BoundingBox.h:64
Definition: CompartmentGlyph.h:60
int setCompartmentId(const std::string &id)
Sets the id of the associated compartment.
Definition: CompartmentGlyph.cpp:223
Definition: Compartment.h:490
virtual const std::string & getId() const
Returns the value of the "id" attribute of this Compartment.
Definition: Compartment.cpp:243
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Compartment object.
Definition: Compartment.cpp:479
Definition: CubicBezier.h:71
void setBasePoint2(const Point *p)
Initializes second base point with a copy of the given point.
Definition: CubicBezier.cpp:457
void setBasePoint1(const Point *p)
Initializes first base point with a copy of the given point.
Definition: CubicBezier.cpp:408
Definition: Curve.h:217
LineSegment * createLineSegment()
Creates a new LineSegment and adds it to the end of the list.
Definition: Curve.cpp:360
Definition: Dimensions.h:71
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this GraphicalObject.
Definition: GraphicalObject.cpp:390
void setBoundingBox(const BoundingBox *bb)
Sets the boundingbox for the GraphicalObject.
Definition: GraphicalObject.cpp:475
virtual const std::string & getId() const
Returns the value of the "id" attribute of this GraphicalObject.
Definition: GraphicalObject.cpp:372
static const std::string & getXmlnsL2()
Returns the XML namespace URI of the SBML Level&#160;2 version of the package implemented by this libSBML ...
Definition: LayoutExtension.cpp:109
Definition: Layout.h:789
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Layout.
Definition: Layout.cpp:454
CompartmentGlyph * createCompartmentGlyph()
Creates a CompartmentGlyph object, adds it to the end of the compartment glyph objects list and retur...
Definition: Layout.cpp:1365
ReactionGlyph * createReactionGlyph()
Creates a ReactionGlyph object, adds it to the end of the reaction glyph objects list and returns a p...
Definition: Layout.cpp:1397
void setDimensions(const Dimensions *dimensions)
Sets the dimensions of the layout.
Definition: Layout.cpp:520
TextGlyph * createTextGlyph()
Creates a TextGlyph object, adds it to the end of the text glyph objects list and returns a pointer t...
Definition: Layout.cpp:1428
SpeciesGlyph * createSpeciesGlyph()
Creates a SpeciesGlyph object, adds it to the end of the species glyph objects list and returns a poi...
Definition: Layout.cpp:1381
Definition: LayoutModelPlugin.h:68
Layout * createLayout()
Creates a new layout object and adds it to the list of layout objects and returns it.
Definition: LayoutModelPlugin.cpp:476
Definition: LineSegment.h:69
void setEnd(const Point *end)
Initializes the end point with a copy of the given Point object.
Definition: LineSegment.cpp:374
void setStart(const Point *start)
Initializes the start point with a copy of the given Point object.
Definition: LineSegment.cpp:327
Definition: Model.h:485
Reaction * createReaction()
Creates a new Reaction inside this Model and returns it.
Definition: Model.cpp:1782
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Model.
Definition: Model.cpp:717
Species * createSpecies()
Creates a new Species inside this Model and returns it.
Definition: Model.cpp:1586
Compartment * createCompartment()
Creates a new Compartment inside this Model and returns it.
Definition: Model.cpp:1558
Definition: ModifierSpeciesReference.h:92
Definition: Point.h:65
Definition: ReactionGlyph.h:255
SpeciesReferenceGlyph * createSpeciesReferenceGlyph()
Creates a new SpeciesReferenceGlyph object, adds it to the end of the list of species reference objec...
Definition: ReactionGlyph.cpp:497
int setReactionId(const std::string &id)
Sets the id of the associated reaction.
Definition: ReactionGlyph.cpp:324
const Curve * getCurve() const
Returns the curve object for the reaction glyph.
Definition: ReactionGlyph.cpp:448
Definition: Reaction.h:224
SpeciesReference * createReactant()
Creates a new SpeciesReference, adds it to this Reaction's list of reactants, and returns it.
Definition: Reaction.cpp:954
int setReversible(bool value)
Sets the value of the "reversible" attribute of this Reaction.
Definition: Reaction.cpp:599
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Reaction.
Definition: Reaction.cpp:517
ModifierSpeciesReference * createModifier()
Creates a new ModifierSpeciesReference, adds it to this Reaction's list of modifiers and returns it.
Definition: Reaction.cpp:1012
virtual const std::string & getId() const
Returns the value of the "id" attribute of this Reaction.
Definition: Reaction.cpp:376
SpeciesReference * createProduct()
Creates a new SpeciesReference, adds it to this Reaction's list of products, and returns it.
Definition: Reaction.cpp:983
int addModifier(const ModifierSpeciesReference *msr)
Adds a given ModifierSpeciesReference object as a product in this Reaction.
Definition: Reaction.cpp:900
Definition: SBMLDocument.h:351
Model * createModel(const std::string sid="")
Creates a new Model inside this SBMLDocument, and returns a pointer to it.
Definition: SBMLDocument.cpp:627
int setModel(const Model *m)
Sets the Model for this SBMLDocument to a copy of the given Model.
Definition: SBMLDocument.cpp:583
Definition: SBMLNamespaces.h:145
int addNamespace(const std::string &uri, const std::string &prefix)
Add an XML namespace (a pair of URI and prefix) to the set of namespaces within this SBMLNamespaces o...
Definition: SBMLNamespaces.cpp:483
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
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this SimpleSpeciesReference.
Definition: SimpleSpeciesReference.cpp:214
virtual const std::string & getId() const
Returns the value of the "id" attribute of this SimpleSpeciesReference.
Definition: SimpleSpeciesReference.cpp:132
int setSpecies(const std::string &sid)
Sets the "species" attribute of this SimpleSpeciesReference.
Definition: SimpleSpeciesReference.cpp:196
Definition: SpeciesGlyph.h:65
void setSpeciesId(const std::string &id)
Sets the id of the associated species object.
Definition: SpeciesGlyph.cpp:206
Definition: Species.h:429
int setCompartment(const std::string &sid)
Sets the "compartment" attribute of this Species object.
Definition: Species.cpp:661
virtual const std::string & getId() const
Returns the value of the "id" attribute of this Species.
Definition: Species.cpp:278
virtual int setId(const std::string &sid)
Sets the value of the "id" attribute of this Species.
Definition: Species.cpp:591
Definition: SpeciesReferenceGlyph.h:71
void setSpeciesReferenceId(const std::string &id)
Sets the id of the associated species reference.
Definition: SpeciesReferenceGlyph.cpp:309
CubicBezier * createCubicBezier()
Creates a new CubicBezier object, adds it to the end of the list of curve segment objects of the curv...
Definition: SpeciesReferenceGlyph.cpp:474
LineSegment * createLineSegment()
Creates a new LineSegment object, adds it to the end of the list of curve segment objects of the curv...
Definition: SpeciesReferenceGlyph.cpp:462
void setSpeciesGlyphId(const std::string &speciesGlyphId)
Sets the id of the associated species glyph.
Definition: SpeciesReferenceGlyph.cpp:289
void setRole(const std::string &role)
Sets the role based on a string.
Definition: SpeciesReferenceGlyph.cpp:343
Definition: SpeciesReference.h:281
Definition: TextGlyph.h:65
int setOriginOfTextId(const std::string &orig)
Sets the id of the origin of text.
Definition: TextGlyph.cpp:266
int setGraphicalObjectId(const std::string &id)
Sets the id of the associated graphical object.
Definition: TextGlyph.cpp:246