Example of converting an SBML Level 3 model using the Flux Balance Constraints package to a COBRA-style SBML Level 2 model.
48 """usage: convertFbcToCobra.py input-filename output-filename 57 if not os.path.exists(infile):
58 print(
"[Error] %s : No such file." % infile)
63 sbmldoc = reader.readSBML(infile)
65 if sbmldoc.getNumErrors() > 0:
66 if sbmldoc.getError(0).getErrorId() == libsbml.XMLFileUnreadable:
69 elif sbmldoc.getError(0).getErrorId() == libsbml.XMLFileOperationError:
79 for p_
in range(sbmldoc.getNumPlugins()):
80 if sbmldoc.getPlugin(p_).getPackageName() !=
'fbc':
82 props.addOption(
"stripPackage",
True,
"Strip SBML Level 3 package constructs from the model")
83 props.addOption(
"package", sbmldoc.getPlugin(p_).getPackageName(),
"Name of the SBML Level 3 package to be stripped")
84 if sbmldoc.convert(props) != libsbml.LIBSBML_OPERATION_SUCCESS:
85 print(
"[Error] Failed to remove package: {}".format(sbmldoc.getPlugin(p_).getPackageName()))
89 props.addOption(
"convert fbc to cobra",
True,
"Convert FBC model to Cobra model")
90 result = sbmldoc.convert(props)
92 if result != libsbml.LIBSBML_OPERATION_SUCCESS:
93 print(
"[Error] Conversion failed... (%d)" % result)
96 writer.writeSBML(sbmldoc, outfile)
97 print(
"[OK] converted file %s to %s" % (infile, outfile))
100 if __name__ ==
'__main__':