sbmlteam / jsbml

JSBML is a community-driven project to create a free, open-source, pure Java™ library for reading, writing, and manipulating SBML files (the Systems Biology Markup Language) and data streams. It is an alternative to the mixed Java/native code-based interface provided in libSBML.
https://sbml.org/software/jsbml/
GNU Lesser General Public License v2.1
37 stars 24 forks source link

Found the bug in ASTNode.toFomula() #259

Open TlexCypher opened 10 months ago

TlexCypher commented 10 months ago

Hey, all. I used jsbml-1.6.1, current latest version of jsbml, but I found the method, ASTNode.toFormula() fails to parse the formula. To be specific, for testcase, I downloaded BIOMD0000000022.xml from BioModels(https://www.ebi.ac.uk/biomodels/search?query=BIOMD0000000022&domain=biomodels), and I wrote the program in C with libsbml.5.18.0 and java with jsbml-1.6.1. I attached the both result as libsbml-formula.txt and jsbml-formula.txt, so I wanna you'll check these, then you should compare the first line.

libsbml-formula.txt of first line

formula1: compartment0000003 * (c1 + (B1 + pow(CCn / A1, a)) * s1 / (1 + B1 + pow(CCn / A1, a)_ + pow(PTn / r1, r)))

jsbml-formula.txt of first line

formula1: compartment0000003*(c1+((B1+CCn/A1^a)*s1)/(1+B1+CCn/A1^a_+PTn/r1^r))

They are completely different. And I checked the related report(Robust oscillations within the interlocked feedback model of Drosophila circadian rhythm., but in this report, result by libsbml is correct.

And, I also checked core/src/org/sbml/jsbml/ASTNode.java.newASTNode, this file was revised 2 years ago, but jsbml-1.6.1 was released in Oct 2022. So even in latest version, jsbml has the bug around ASTNode.toFormula().

Any help, please.

libsbml-formula.txt jsbml-formula.txt

luciansmith commented 10 months ago

The trick here is that CCn/A1 needs to be in parentheses in the jsbml version of the formula:

i.e. instead of:

CCn/A1^a

it needs to produce:

(CCn/A1)^a

(It could produce the 'pow' version instead, if that's simpler.)

TlexCypher commented 10 months ago

@luciansmith Yes, that is what i wanna say! jsbml-1.6.1 can't parse this formula correctly, I think.

luciansmith commented 10 months ago

You are correct! Thanks for reporting the issue; hopefully the jsbml team will be able to get to it soon.

TlexCypher commented 10 months ago

I'm gonna to try fix this bug!

luciansmith commented 10 months ago

Good luck! Feel free to post here with questions if you have any.