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.

Home Page:https://sbml.org/software/jsbml/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing double

mephenor opened this issue · comments

The method parseSBMLDouble(String) in the class StringTools.java is used to parse string values into
double values. The method works correct, but for my needs to correct.
In the following SBML snippet is a list of Parameters in KineticLaw.

<listOfParameters>
<parameter id="Vf" value="1,43" />
<parameter id="Kma" value=",059" />
</listOfParameters>

In this parameters values like ,4 and 0,4 are set for the attribute value.

,4 is a expression for 0.4
0,4 is a expression for 0.4

The method returns Double.NAN for both expression. Developers have no oppotunity to get this not correct
double values.

I have got two suggestions. You could add code to the method to transform this cases into a valid double value.
I would suggest the following change for the method parseSBMLDouble:

public static double parseSBMLDouble(String valueAsStr) {

double value = Double.NaN;
String toTest = valueAsStr.trim();

try {
if(toTest.startsWith(",")){
toTest = toTest.replace(",", "0.");
}
else if(toTest.startsWith(".")){
toTest = toTest.replace(".", "0.");
}
else if(toTest.contains(",")){
toTest = toTest.replace(",", ".");
}
value = Double.parseDouble(toTest);
} catch (NumberFormatException e) {

if (toTest.equalsIgnoreCase("INF")) {
value = Double.POSITIVE_INFINITY;
} else if (toTest.equalsIgnoreCase("-INF")) {
value = Double.NEGATIVE_INFINITY;
} else {
Logger logger = Logger.getLogger(StringTools.class);
logger.warn("Could not create a double from the string " + valueAsStr);
}
}

return value;
}

As a alternative I would like to get the wrong double thrown by an exception.

Reported by: *anonymous

The problem here is that your SBML file as to comply to the SBML specifications and we consider a valid double value, only the values that are defined in the SBML specifications.
You can check the SBML specifications, for example level 2 version 4 or Level 3 version 1 core, section 3.1.5 about the primitive data types and specifically the double type. The comma is not accepted as a valid separator, so the numbers would not be understood by many software.

You could change the Locale in your java application so that numbers set into jsbml objects are of the right form.

Original comment by: niko-rodrigue

  • assigned_to: nobody --> niko-rodrigue
  • status: open --> pending-wont-fix

Original comment by: niko-rodrigue

We are currently discussing if we should try to deal with this problem inside JSBML or not, in fact.

Original comment by: niko-rodrigue

  • status: pending-wont-fix --> pending

Original comment by: niko-rodrigue

  • status: pending --> closed-wont-fix
  • Group: --> jsbml 0.8

Original comment by: niko-rodrigue