From afeb81a3f94d9779277bc1815fb45e2fdb81c1fb Mon Sep 17 00:00:00 2001 From: Silvio Waschina Date: Fri, 6 Dec 2024 16:10:31 +0100 Subject: [PATCH] Enable reading SBML level 2 models and models with FBC v1 Fixes #11 --- src/SBML.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/SBML.cpp b/src/SBML.cpp index 34eaf26..dcb33b2 100644 --- a/src/SBML.cpp +++ b/src/SBML.cpp @@ -7,6 +7,7 @@ #include #include #include +#include // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; @@ -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(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(document, false); }