libSBML C API  libSBML 5.20.4 C API
Loading...
Searching...
No Matches
printMath.c

Prints the rule, reaction, and event formulas in a given SBML document.

Prints the rule, reaction, and event formulas in a given SBML document.

/**
* @file printMath.c
* @brief Prints Rule_t, Reaction_t, and Event_t formulas in a given SBML Document
* @author Ben Bornstein
*
* <!--------------------------------------------------------------------------
* 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 <stdio.h>
#include <stdlib.h>
#include <sbml/SBMLTypes.h>
void
printFunctionDefinition (unsigned int n, const FunctionDefinition_t *fd)
{
const ASTNode_t *math;
char *formula;
{
printf("FunctionDefinition %d, %s(", n, FunctionDefinition_getId(fd));
/* Print function arguments. */
if (ASTNode_getNumChildren(math) > 1)
{
printf("%s", ASTNode_getName( ASTNode_getLeftChild(math) ));
for (n = 1; n < ASTNode_getNumChildren(math) - 1; ++n)
{
printf(", %s", ASTNode_getName( ASTNode_getChild(math, n) ));
}
}
printf(") := ");
/* Print function body. */
if (ASTNode_getNumChildren(math) == 0)
{
printf("(no body defined)");
}
else
{
math = ASTNode_getChild(math, ASTNode_getNumChildren(math) - 1);
formula = SBML_formulaToString(math);
printf("%s\n", formula);
free(formula);
}
}
}
void
printRuleMath (unsigned int n, const Rule_t *r)
{
char *formula;
if ( Rule_isSetMath(r) )
{
printf("Rule %d, formula: %s\n", n, formula);
free(formula);
}
}
void
printReactionMath (unsigned int n, Reaction_t *r)
{
char *formula;
{
{
printf("Reaction %d, formula: %s\n", n, formula);
free(formula);
}
}
}
void
printEventAssignmentMath (unsigned int n, const EventAssignment_t *ea)
{
const char *variable;
char *formula;
{
printf(" EventAssignment %d, trigger: %s = %s\n", n, variable, formula);
free(formula);
}
}
void
printEventMath (unsigned int n, Event_t *e)
{
char *formula;
unsigned int i;
if ( Event_isSetDelay(e) )
{
const Delay_t *delay = Event_getDelay(e);
formula = SBML_formulaToString( Delay_getMath(delay) );
printf("Event %d delay: %s\n", n, formula);
free(formula);
}
{
const Trigger_t *trigger = Event_getTrigger(e);
formula = SBML_formulaToString( Trigger_getMath(trigger) );
printf("Event %d trigger: %s\n", n, formula);
free(formula);
}
for (i = 0; i < Event_getNumEventAssignments(e); ++i)
{
printEventAssignmentMath(i + 1, Event_getEventAssignment(e, i));
}
printf("\n");
}
void
printMath (Model_t *m)
{
unsigned int n;
for (n = 0; n < Model_getNumFunctionDefinitions(m); ++n)
{
printFunctionDefinition(n + 1, Model_getFunctionDefinition(m, n));
}
for (n = 0; n < Model_getNumRules(m); ++n)
{
printRuleMath(n + 1, Model_getRule(m, n));
}
printf("\n");
for (n = 0; n < Model_getNumReactions(m); ++n)
{
printReactionMath(n + 1, Model_getReaction(m, n));
}
printf("\n");
for (n = 0; n < Model_getNumEvents(m); ++n)
{
printEventMath(n + 1, Model_getEvent(m, n));
}
}
int
main (int argc, char *argv[])
{
Model_t *m;
if (argc != 2)
{
printf("Usage: printMath filename\n");
return 1;
}
d = readSBML(argv[1]);
printMath(m);
printf("\n");
return 0;
}
unsigned int ASTNode_getNumChildren(const ASTNode_t *node)
_tReturns_t _tthe_t _tnumber_t _tof_t _tchildren_t _tof_t _ta_t _tgiven_t _tnode_t.
Definition ASTNode.cpp:4729
const char * ASTNode_getName(const ASTNode_t *node)
_tReturns_t _tthe_t _tvalue_t _tof_t _ta_t _tnode_t _tas_t _ta_t _tstring_t.
Definition ASTNode.cpp:4779
ASTNode_t * ASTNode_getChild(const ASTNode_t *node, unsigned int n)
_tReturns_t _ta_t _tchild_t _tof_t _ta_t _tnode_t _taccording_t _tto_t _tits_t _tindex_t _tnumber_t.
Definition ASTNode.cpp:4702
ASTNode_t * ASTNode_getLeftChild(const ASTNode_t *node)
_tReturns_t _tthe_t _tleft_t-_tmost_t _tchild_t _tof_t _ta_t _tgiven_t _tnode_t.
Definition ASTNode.cpp:4711
const ASTNode_t * Delay_getMath(const Delay_t *t)
_tGet_t _tthe_t _tmathematical_t _tformula_t _tfor_t _ta_t _tDelay_t_t _tstructure_t _tand_t _treturn...
Definition Delay.cpp:908
int Event_isSetTrigger(const Event_t *e)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition Event.cpp:2449
Delay_t * Event_getDelay(Event_t *e)
_tTakes_t _tan_t _tEvent_t_t _tstructure_t _tand_t _treturns_t _tits_t _tDelay_t_t _tstructure_t.
Definition Event.cpp:2401
unsigned int Event_getNumEventAssignments(const Event_t *e)
_tReturns_t _tthe_t _tnumber_t _tof_t _tEventAssignment_t_t _tstructures_t _tattached_t _tto_t _tthe_...
Definition Event.cpp:2719
EventAssignment_t * Event_getEventAssignment(Event_t *e, unsigned int n)
_tReturn_t _ta_t _tspecific_t _tEventAssignment_t_t _tstructure_t _tof_t _tthe_t _tgiven_t _tEvent_t_...
Definition Event.cpp:2702
Trigger_t * Event_getTrigger(Event_t *e)
_tTakes_t _tan_t _tEvent_t_t _tstructure_t _tand_t _treturns_t _tits_t _tTrigger_t_t _tstructure_t.
Definition Event.cpp:2393
int Event_isSetDelay(const Event_t *e)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition Event.cpp:2457
const char * EventAssignment_getVariable(const EventAssignment_t *ea)
_tReturns_t _tthe_t _tvalue_t _tof_t _tthe_t "_tvariable_t" _tattribute_t _tof_t _tthis_t _tEventAssi...
Definition EventAssignment.cpp:1296
const ASTNode_t * EventAssignment_getMath(const EventAssignment_t *ea)
_tReturns_t _tthe_t _tmathematical_t _tformula_t _tstored_t _tin_t _tthe_t _tgiven_t _tEventAssignmen...
Definition EventAssignment.cpp:1304
int EventAssignment_isSetMath(const EventAssignment_t *ea)
_tPredicate_t _tfor_t _ttesting_t _twhether_t _tthe_t _tattribute_t "_tvariable_t" _tof_t _tthe_t _tg...
Definition EventAssignment.cpp:1320
char * SBML_formulaToString(const ASTNode_t *tree)
@_tif_t _tconly_t @_tmemberof_t _tASTNode_t_t @_tendif_t
Definition FormulaFormatter.cpp:56
const char * FunctionDefinition_getId(const FunctionDefinition_t *fd)
_tGet_t _tthe_t _tidentifier_t _tof_t _tthe_t _tgiven_t _tFunctionDefinition_t_t _tstructure_t.
Definition FunctionDefinition.cpp:1375
int FunctionDefinition_isSetMath(const FunctionDefinition_t *fd)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition FunctionDefinition.cpp:1415
const ASTNode_t * FunctionDefinition_getMath(const FunctionDefinition_t *fd)
_tGet_t _tthe_t _tmathematical_t _tformula_t _timplemented_t _tby_t _tthe_t _tgiven_t _tfunction_t.
Definition FunctionDefinition.cpp:1391
const ASTNode_t * KineticLaw_getMath(const KineticLaw_t *kl)
_tReturns_t _tthe_t _tmathematical_t _texpression_t _tof_t _tthis_t _tKineticLaw_t_t _tstructure_t _t...
Definition KineticLaw.cpp:2067
int KineticLaw_isSetMath(const KineticLaw_t *kl)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition KineticLaw.cpp:2101
unsigned int Model_getNumEvents(const Model_t *m)
_tGet_t _tthe_t _tnumber_t _tof_t _tEvent_t_t _tstructures_t _tin_t _tthe_t _tgiven_t _tModel_t_t _ts...
Definition Model.cpp:8213
Event_t * Model_getEvent(Model_t *m, unsigned int n)
_tGet_t _tthe_t _tnth_t _tEvent_t_t _tstructure_t _tcontained_t _tin_t _tthe_t _tgiven_t _tModel_t_t ...
Definition Model.cpp:8102
unsigned int Model_getNumReactions(const Model_t *m)
_tGet_t _tthe_t _tnumber_t _tof_t _tReaction_t_t _tstructures_t _tin_t _tthe_t _tgiven_t _tModel_t_t ...
Definition Model.cpp:8205
unsigned int Model_getNumFunctionDefinitions(const Model_t *m)
_tGet_t _tthe_t _tnumber_t _tof_t _tFunctionDefinition_t_t _tstructures_t _tin_t _tthe_t _tgiven_t _t...
Definition Model.cpp:8118
unsigned int Model_getNumRules(const Model_t *m)
_tGet_t _tthe_t _tnumber_t _tof_t _tRule_t_t _tstructures_t _tin_t _tthe_t _tgiven_t _tModel_t_t _tst...
Definition Model.cpp:8190
Reaction_t * Model_getReaction(Model_t *m, unsigned int n)
_tGet_t _tthe_t _tnth_t _tReaction_t_t _tstructure_t _tcontained_t _tin_t _tthe_t _tgiven_t _tModel_t...
Definition Model.cpp:8078
Rule_t * Model_getRule(Model_t *m, unsigned int n)
_tGet_t _tthe_t _tnth_t _tRule_t_t _tstructure_t _tcontained_t _tin_t _tthe_t _tgiven_t _tModel_t_t _...
Definition Model.cpp:8054
FunctionDefinition_t * Model_getFunctionDefinition(Model_t *m, unsigned int n)
_tGet_t _tthe_t _tnth_t _tFunctionDefinition_t_t _tstructure_t _tcontained_t _tin_t _tthe_t _tgiven_t...
Definition Model.cpp:7926
int Reaction_isSetKineticLaw(const Reaction_t *r)
@_treturn_t @_tc_t _t1_t (_ttrue_t) _tif_t _tthe_t _tKineticLaw_t_t _tof_t _tthis_t _tReaction_t_t _t...
Definition Reaction.cpp:2754
KineticLaw_t * Reaction_getKineticLaw(Reaction_t *r)
@_treturn_t _tthe_t _tKineticLaw_t_t _tof_t _tthis_t _tReaction_t_t.
Definition Reaction.cpp:2705
const ASTNode_t * Rule_getMath(const Rule_t *r)
@_treturn_t _tthe_t _tmath_t _tfor_t _tthis_t _tRule_t_t.
Definition Rule.cpp:2004
int Rule_isSetMath(const Rule_t *r)
@_treturn_t @_tc_t _t1_t (_ttrue_t) _tif_t _tthe_t _tmath_t (_tor_t _tequivalently_t _tthe_t _tformul...
Definition Rule.cpp:2044
void SBMLDocument_printErrors(SBMLDocument_t *d, FILE *stream)
_tPrints_t _tto_t _tthe_t _tgiven_t _toutput_t _tstream_t _tall_t _tthe_t _terrors_t _tor_t _twarning...
Definition SBMLDocument.cpp:2525
void SBMLDocument_free(SBMLDocument_t *d)
_tFrees_t _tthe_t _tgiven_t _tSBMLDocument_t_t _tstructure_t.
Definition SBMLDocument.cpp:2248
Model_t * SBMLDocument_getModel(SBMLDocument_t *d)
_tReturns_t _tthe_t _tModel_t_t _tstructure_t _tstored_t _tin_t _tthis_t _tSBMLDocument_t_t _tstructu...
Definition SBMLDocument.cpp:2290
SBMLDocument_t * readSBML(const char *filename)
@_tcopydoc_t _tdoc_readsbmlfromfile_t
Definition SBMLReader.cpp:446
Include all SBML types in a single header file.
const ASTNode_t * Trigger_getMath(const Trigger_t *t)
@_treturn_t _tthe_t _tmath_t _tof_t _tthis_t _tTrigger_t_t.
Definition Trigger.cpp:1031