pysb
pysb copied to clipboard
error importing SBML model
Hello everyone,
I found a problem trying to import an SBML model (https://www.ebi.ac.uk/compneur-srv/biomodels-main/MODEL1608100001). It seems the SBML file has something invalid SyntaxError: invalid syntax (<string>, line 1) for PySB. However, using the https://github.com/RuleWorld/BNGTutorial/blob/master/SBML/translateSBML.bngl file, I was able to translate the model into BNGL and simulate it.
Thank you for your time, Best regards
The model is valid, but everything is written in a single line. It could be that the pysb parser is expecting the xml declaration in a separate line then the <sbml> tag.
I attached a prettified xml which should work.
MODEL1608100001_pretty.xml.zip
SyntaxError is raised when some Python code has a syntax error, which leads me to believe your problem lies elsewhere. Could you paste the entire stack trace, and ideally a minimal Python script that reproduces this error?
Ultimately the SBML is parsed using libsbml which has no problem with the single long line. There is in fact a problem parsing the if(...) in some of the expressions, but the exception I see is BnglImportError, not SyntaxError:
$ python -c 'import pysb.importers.sbml; pysb.importers.sbml.model_from_biomodels("MODEL1608100001")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "pysb/importers/sbml.py", line 238, in model_from_biomodels
**kwargs)
File "pysb/importers/sbml.py", line 175, in model_from_sbml
return model_from_bngl(bngl_file, force=force, cleanup=cleanup)
File "pysb/importers/bngl.py", line 426, in model_from_bngl
bb = BnglBuilder(filename, force=force, cleanup=cleanup)
File "pysb/importers/bngl.py", line 48, in __init__
self._parse_bng_xml()
File "pysb/importers/bngl.py", line 391, in _parse_bng_xml
self._parse_expressions()
File "pysb/importers/bngl.py", line 378, in _parse_expressions
ex.message))
File "pysb/importers/bngl.py", line 57, in _warn_or_except
raise BnglImportError(msg)
pysb.importers.bngl.BnglImportError: Could not parse expression functionRate6: if((IFN_compartment>0),(((6.1349*(IFN_compartment**2.0))/((0.0055**2.0)+(IFN_compartment**2.0)))/IFN_compartment),0)
I'm submitting a PR to PySB right now to fix the if parsing.
I take back what I said about the SyntaxError being unlikely, as I did notice sympy triggering that exception in certain cases due to its use of eval! Either way, the issue should be resolved by the forthcoming PR.