libSBML Python API  5.20.2
Loading...
Searching...
No Matches
doc_section_using_sbml_converters Class Reference

Detailed Description

General information about the use of SBML converters

The use of all the converters follows a similar approach. First, one creates a ConversionProperties object and calls ConversionProperties::addOption( ) on this object with one argument: a text string that identifies the desired converter. (The text string is specific to each converter; consult the documentation for a given converter to find out how it should be enabled.)

Next, for some converters, the caller can optionally set some converter-specific properties using additional calls to ConversionProperties::addOption( ). Many converters provide the ability to configure their behavior to some extent; this is realized through the use of properties that offer different options. The default property values for each converter can be interrogated using the method SBMLConverter::getDefaultProperties() on the converter class in question .

Finally, the caller should invoke the method SBMLDocument::convert( ) with the ConversionProperties object as an argument.

Example of invoking an SBML converter

The following code fragment illustrates an example using SBMLReactionConverter, which is invoked using the option string "replaceReactions":

config = ConversionProperties()
if config != None:
config.addOption("replaceReactions")

In the case of SBMLReactionConverter, there are no options to affect its behavior, so the next step is simply to invoke the converter on an SBMLDocument object. Continuing the example code:

# Assume that the variable "document" has been set to an SBMLDocument object.
status = document.convert(config)
if status != LIBSBML_OPERATION_SUCCESS:
# Handle error somehow.
print("Error: conversion failed due to the following:")
document.printErrors()

Here is an example of using a converter that offers an option. The following code invokes SBMLStripPackageConverter to remove the SBML Level 3 Layout package from a model. It sets the name of the package to be removed by adding a value for the option named "package" defined by that converter:

def strip_layout_example(document):
config = ConversionProperties()
if config != None:
config.addOption("stripPackage")
config.addOption("package", "layout")
status = document.convert(config)
if status != LIBSBML_OPERATION_SUCCESS:
# Handle error somehow.
print("Error: unable to strip the Layout package.")
print("LibSBML returned error: " + OperationReturnValue_toString(status).strip())
else:
# Handle error somehow.
print("Error: unable to create ConversionProperties object")

Available SBML converters in libSBML

LibSBML provides a number of built-in converters; by convention, their names end in Converter. The following are the built-in converters provided by libSBML

  • AnnotationToDistribConverter
  • ArraysFlatteningConverter
  • CobraToFbcConverter
  • CompFlatteningConverter
  • DistribToAnnotationConverter
  • FbcToCobraConverter
  • FbcV1ToV2Converter
  • FbcV2ToV1Converter
  • RenderLayoutConverter
  • SBMLFunctionDefinitionConverter
  • SBMLIdConverter
  • SBMLInferUnitsConverter
  • SBMLInitialAssignmentConverter
  • SBMLLevel1Version1Converter
  • SBMLLevelVersionConverter
  • SBMLLocalParameterConverter
  • SBMLRateOfConverter
  • SBMLRateRuleConverter
  • SBMLReactionConverter
  • SBMLRuleConverter
  • SBMLStripPackageConverter
  • SBMLUnitsConverter