Skip to content

Commit

Permalink
Enable reading SBML level 2 models and models with FBC v1
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
Waschina committed Dec 6, 2024
1 parent f26a1cb commit afeb81a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/SBML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sbml/packages/groups/common/GroupsExtensionTypes.h>
#include <sbml/xml/XMLNode.h>
#include <sbml/annotation/CVTerm.h>
#include <sbml/conversion/ConversionProperties.h>
// [[Rcpp::depends(RcppArmadillo)]]

using namespace Rcpp;
Expand Down Expand Up @@ -34,6 +35,35 @@ SEXP readSBMLfile(std::string file_path) {
Rcpp::stop("Error reading SBML document.");
}

// Convert SBML Level 2 to SBML Level 3 with FBC extension
if(document->getLevel() == 2) {
std::cout << "Converting COBRA-style SBML Level 2 model to SBML Level 3 using the Flux Balance Constraints (FBC)." << std::endl;

ConversionProperties props;
props.addOption("convert cobra", true, "Convert Cobra model to FBC");
int result = document->convert(props);

if (result != LIBSBML_OPERATION_SUCCESS) {
std::cout<< "SBML level conversion failed ... " << std::endl;
exit(0);
}
}

// Convert FBC v1 to FBC v2
FbcSBMLDocumentPlugin* dplugin = static_cast<FbcSBMLDocumentPlugin*>(document->getPlugin("fbc"));
if(dplugin->getPackageVersion() == 1) {
std::cout << "Converting FBC V1 to FBC V2." << std::endl;

ConversionProperties propsFBC;
propsFBC.addOption("convert fbc v1 to fbc v2");
int result = document->convert(propsFBC);

if (result != LIBSBML_OPERATION_SUCCESS) {
std::cout<< "FBC conversion failed ... " << std::endl;
exit(0);
}
}

return Rcpp::XPtr<SBMLDocument>(document, false);
}

Expand Down

0 comments on commit afeb81a

Please sign in to comment.