Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error importing SBML model #455

Open
glucksfall opened this issue Aug 9, 2019 · 3 comments · Fixed by maurosilber/pysb#1
Open

error importing SBML model #455

glucksfall opened this issue Aug 9, 2019 · 3 comments · Fixed by maurosilber/pysb#1

Comments

@glucksfall
Copy link

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

@matthiaskoenig
Copy link

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

@jmuhlich
Copy link
Member

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.

@jmuhlich
Copy link
Member

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.

jmuhlich added a commit to jmuhlich/pysb that referenced this issue Aug 13, 2019
BNGL models (and also SBML due to the conversion path) with piecewise
expressions and logical/equality expressions will now parse into
sympy expressions correctly. Piecewise expressions ('if' in BNGL)
in particular would trigger an exception in the sympy parser.

Fixes pysb#455
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants