diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 12623062ca..596e8e66dd 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -53,6 +53,7 @@ foreach(example createExampleSBML echoSBML inferUnits + inferReactions inlineFunctionDefintions convertReactions getAllElementsWithNotes @@ -147,6 +148,11 @@ add_test(NAME test_cxx_echoSBML ${CMAKE_SOURCE_DIR}/examples/sample-models/from-spec/level-3/enzymekinetics.xml echoSBML.out.xml ) +add_test(NAME test_cxx_inferReactions + COMMAND "$" + ${CMAKE_SOURCE_DIR}/examples/sample-models/from-spec/level-3/enzymekinetics.xml + inferReactions.out.xml +) add_test(NAME test_cxx_inferUnits COMMAND "$" ${CMAKE_SOURCE_DIR}/examples/sample-models/from-spec/level-3/enzymekinetics.xml diff --git a/examples/c++/inferReactions.cpp b/examples/c++/inferReactions.cpp new file mode 100644 index 0000000000..d0bc6e0a13 --- /dev/null +++ b/examples/c++/inferReactions.cpp @@ -0,0 +1,109 @@ +/** + * @file inferReactions.cpp + * @brief Loads an SBML File and converts ODEs to Reactions + * @author Sarah Keating + * @author Frank T. Bergmann + * + * + */ + + +#include +#include +#include + +using namespace std; +LIBSBML_CPP_NAMESPACE_USE + +int +main (int argc, char *argv[]) +{ + + if (argc != 3) + { + cout + << endl + << "Usage: inferReactions input-filename output-filename" << endl + << endl + << "This program will attempt to convert all ODEs" << endl + << "contained in the source model, and write a new SBML file." + << endl + << endl; + return 1; + } + + const char* inputFile = argv[1]; + const char* outputFile = argv[2]; + + // read document + SBMLDocument* document = readSBML(inputFile); + unsigned int errors = document->getNumErrors(LIBSBML_SEV_ERROR); + + // stop in case of errors + if (errors > 0) + { + cerr << "Encountered the following SBML errors:" << endl; + document->printErrors(cerr); + cerr << "Conversion skipped. Please correct the problems above first." + << endl; + return errors; + } + + // create conversion object that identifies the function definition converter + ConversionProperties props; + props.addOption("inferReactions", true, + "Infer reactions from rateRules in the model"); + + // convert + int success = document->convert(props); + + if (success != LIBSBML_OPERATION_SUCCESS) + { + cerr << "Unable to perform conversion due to the following:" << endl; + document->printErrors(cerr); + return errors; + } + else + { + cout << "Conversion completed." << endl; + writeSBML(document, outputFile); + } + + delete document; + + return 0; +} + +