Example of converting an SBML Level 3 model using the Flux Balance Constraints package to a COBRA-style SBML Level 2 model.
namespace LibSBMLCSExample
{
public class convertFbcToCobra
{
public static void Main (string[] args)
{
if (args.Length != 2)
{
string myname = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
Console.WriteLine("Usage: {0} input-filename output-filename", myname);
Environment.Exit(1);
}
string inputFile = args[0];
string outputFile = args[1];
if ( ! File.Exists(inputFile) )
{
Console.WriteLine("[Error] {0} : No such file.", inputFile);
Environment.Exit(1);
}
var now = DateTime.Now.Ticks;
SBMLReader reader = new SBMLReader();
SBMLWriter writer = new SBMLWriter();
SBMLDocument sbmlDoc = reader.readSBML(inputFile);
if ( sbmlDoc.getErrorLog().getNumFailsWithSeverity(libsbml.LIBSBML_SEV_ERROR) > 0)
{
sbmlDoc.printErrors();
Console.WriteLine("[Error] Cannot read {0}", inputFile);
Environment.Exit(1);
}
Console.WriteLine("Read {0} in {1}", inputFile, new TimeSpan(DateTime.Now.Ticks - now).TotalMilliseconds);
ConversionProperties props = new ConversionProperties();
props.addOption("convert fbc to cobra", true, "Convert FBC model to Cobra model");
now = DateTime.Now.Ticks;
int result = sbmlDoc.convert(props);
if (result != libsbml.LIBSBML_OPERATION_SUCCESS)
{
Console.WriteLine ("conversion failed ... ");
Environment.Exit(3);
}
writer.writeSBML(sbmlDoc, outputFile);
Console.WriteLine("[OK] converted to FBC from {0} and wrote to {1} (in {2} msec)", inputFile, outputFile, new TimeSpan(DateTime.Now.Ticks - now).TotalMilliseconds);
}
}
}