Converts SBML Layout and Render datra from SBML Level 2 to Level 3 and vice versa.
43 def convertDocToL2(doc, outputFile):
44 layoutNsUri =
"http://projects.eml.org/bcb/sbml/level2" 45 layoutNs = LayoutPkgNamespaces(2, 4)
46 renderNsUri =
"http://projects.eml.org/bcb/sbml/render/level2" 47 renderNs = RenderPkgNamespaces(2, 4)
49 prop = ConversionProperties(SBMLNamespaces(2,4))
50 prop.addOption(
'strict',
False)
51 prop.addOption(
'setLevelAndVersion',
True)
52 prop.addOption(
'ignorePackages',
True)
56 docPlugin = doc.getPlugin(
"layout")
57 if docPlugin
is not None:
58 docPlugin.setElementNamespace(layoutNsUri)
60 doc.getSBMLNamespaces().removePackageNamespace(3, 1,
"layout", 1)
61 doc.getSBMLNamespaces().addPackageNamespace(
"layout", 1)
63 rdocPlugin = doc.getPlugin(
"render")
64 if rdocPlugin
is not None:
65 rdocPlugin.setElementNamespace(renderNsUri)
67 doc.getSBMLNamespaces().removePackageNamespace(3, 1,
"render", 1)
68 doc.getSBMLNamespaces().addPackageNamespace(
"render", 1)
72 def convertDocToL3(doc, outputFile):
73 layoutNsUri =
"http://www.sbml.org/sbml/level3/version1/layout/version1" 74 layoutNs = LayoutPkgNamespaces(3, 1)
75 renderNsUri =
"http://www.sbml.org/sbml/level3/version1/render/version1" 76 renderNs = RenderPkgNamespaces(3, 1)
78 prop = ConversionProperties(SBMLNamespaces(3,1))
79 prop.addOption(
'strict',
False)
80 prop.addOption(
'setLevelAndVersion',
True)
81 prop.addOption(
'ignorePackages',
True)
85 docPlugin = doc.getPlugin(
"layout")
86 if docPlugin
is not None:
87 docPlugin.setElementNamespace(layoutNsUri)
89 doc.getSBMLNamespaces().removePackageNamespace(3, 1,
"layout", 1)
90 doc.getSBMLNamespaces().addPackageNamespace(
"layout", 1)
92 rdocPlugin = doc.getPlugin(
"render")
93 if rdocPlugin
is not None:
94 rdocPlugin.setElementNamespace(renderNsUri)
96 doc.getSBMLNamespaces().removePackageNamespace(3, 1,
"render", 1)
97 doc.getSBMLNamespaces().addPackageNamespace(
"render", 1)
101 def convertFileToL2(inputFile, outputFile):
103 convertDocToL2(doc, outputFile)
105 def convertFileToL3(inputFile, outputFile):
107 convertDocToL3(doc, outputFile)
109 def convertFile(inputFile, outputFile):
111 if doc.getLevel() == 3:
112 convertDocToL2(doc, outputFile)
114 convertDocToL3(doc, outputFile)
117 if __name__ ==
'__main__':
118 if len(sys.argv) != 3:
121 usage: convertLayout <input file> <output file> 126 convertFile(sys.argv[1], sys.argv[2])