使用sbmltoodepy转换SBML文件为ODE时触发AssertionError报错
sbmltoodepy转换SBML为ODE模型时触发AssertionError排查
报错场景
使用sbmltoodepy库运行脚本,将SBML文件转换为常微分方程(ODE)模型时抛出断言错误,完整报错栈如下:
Traceback (most recent call last): File "C:\Users\AppData\Roaming\JetBrains\PyCharm2021.2\scratches\scratch_79.py", line 8, in ParseAndCreateModel(inputFilePath)#, jsonFilePath=None, outputFilePath=None)#, className="SBMLmodel") File "C:\Users\AppData\Roaming\Python\Python39\site-packages\sbmltoodepy\utilities.py", line 66, in ParseAndCreateModel modelData = ParseSBMLFile(inputFilePath) File "C:\Users\AppData\Roaming\Python\Python39\site-packages\sbmltoodepy\parse.py", line 284, in ParseSBMLFile assert(doc.getNumErrors() == 0) AssertionError
经定位,报错由parse.py第284行的assert(doc.getNumErrors() == 0)断言失败触发,即SBML文件解析环节检测到错误。
复现代码
import sbmltoodepy from sbmltoodepy import ParseAndCreateModel inputFilePath = "E:/Borisov2009_insulin_EGF.xml" ParseAndCreateModel(inputFilePath, jsonFilePath=None, outputFilePath=None, className="SBMLmodel") model = sbmltoodepy.SBMLmodel() model.RunSimulation(1, absoluteTolerance = 1e-12, relativeTolerance = 1e-6)
排查方案
- 报错核心逻辑:sbmltoodepy底层依赖libsbml读取SBML文件,该断言直接判定解析过程零错误,但封装逻辑没有打印具体错误明细,需要手动提取解析错误定位根因。
- 基础校验:确认目标路径下的
Borisov2009_insulin_EGF.xml文件完整无损坏、当前Python进程对该文件有读取权限、路径字符串无转义错误。 - 提取具体解析错误:单独调用libsbml接口读取文件,打印所有解析错误明细,参考代码如下:
import libsbml doc = libsbml.readSBML("E:/Borisov2009_insulin_EGF.xml") for idx in range(doc.getNumErrors()): error = doc.getError(idx) print(f"错误等级:{error.getSeverityAsString()},错误详情:{error.getMessage()}")
- 高频触发原因:SBML版本/级别与当前安装的libsbml版本不兼容、XML标签缺失或闭合错误、单位定义冲突、反应/组分属性不符合SBML规范、文件下载/传输过程中内容截断。
- 额外注意点:传入
className="SBMLmodel"参数后,需确认生成的模型类正确挂载到sbmltoodepy命名空间,否则后续sbmltoodepy.SBMLmodel()调用会触发属性错误,该问题与当前断言报错无关联。
内容的提问来源于stack exchange,提问作者Ins Keerg
相关产品推荐
相关产品推荐

