Commit 15d235c9 authored by Piotr Gawron's avatar Piotr Gawron

kinetic parameter with infinity can be parsed properly

parent 071bd368
Pipeline #23824 failed with stage
in 35 minutes and 28 seconds
......@@ -5,6 +5,10 @@ minerva (14.0.11) stable; urgency=medium
(#1198)
* Bug fix: export to CellDesigner deal with CellDesigner issue that does not
allow complex species alias to be shorter than 2 characters (#1204)
* Bug fix: kinetic parameters with INFINITY values could not be uploaded to
minerva (#1202)
* Bug fix: infinity value in kinetic parameter could not be parsed from
CellDesigner file minerva (#1203)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 30 Mar 2020 10:00:00 +0200
......
package lcsb.mapviewer.converter.model.celldesigner;
public class CellDesignerParserUtils {
public Double parseDouble(String input) {
if (input == null) {
return null;
}
if (input.equalsIgnoreCase("INF")) {
return Double.POSITIVE_INFINITY;
}
if (input.equalsIgnoreCase("-INF")) {
return Double.NEGATIVE_INFINITY;
}
return Double.parseDouble(input);
}
}
......@@ -6,6 +6,7 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerParserUtils;
import lcsb.mapviewer.model.map.kinetics.SbmlParameter;
import lcsb.mapviewer.model.map.model.Model;
......@@ -27,7 +28,7 @@ public class ParameterXmlParser {
SbmlParameter result = new SbmlParameter(parameterId);
result.setName(XmlParser.getNodeAttr("name", unitNode));
result.setValue(Double.parseDouble(XmlParser.getNodeAttr("value", unitNode)));
result.setValue(new CellDesignerParserUtils().parseDouble(XmlParser.getNodeAttr("value", unitNode)));
result.setUnits(model.getUnitsByUnitId(XmlParser.getNodeAttr("units", unitNode)));
return result;
}
......
......@@ -9,7 +9,7 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.AllAnnotationTests
import lcsb.mapviewer.converter.model.celldesigner.compartment.AllCompartmentTests;
import lcsb.mapviewer.converter.model.celldesigner.function.AllFunctionTests;
import lcsb.mapviewer.converter.model.celldesigner.geometry.AllGeometryTests;
import lcsb.mapviewer.converter.model.celldesigner.parameter.ParameterXmlParserTest;
import lcsb.mapviewer.converter.model.celldesigner.parameter.AllParameterTests;
import lcsb.mapviewer.converter.model.celldesigner.reaction.AllReactionTests;
import lcsb.mapviewer.converter.model.celldesigner.species.AllSpeciesTests;
import lcsb.mapviewer.converter.model.celldesigner.structure.AllStructureTests;
......@@ -23,18 +23,19 @@ import lcsb.mapviewer.converter.model.celldesigner.unit.UnitXmlParserTest;
AllCompartmentTests.class,
AllFunctionTests.class,
AllGeometryTests.class,
AllParameterTests.class,
AllReactionTests.class,
AllSpeciesTests.class,
AllStructureTests.class,
AllTypesTests.class,
CellDesignerElementCollectionTest.class,
CellDesignerXmlParserTest.class,
CellDesignerParserUtilsTest.class,
ComplexParserTests.class,
InvalidGroupExceptionTest.class,
LayerXmlParserTest.class,
NestedComplexParsingTests.class,
ModificationTest.class,
ParameterXmlParserTest.class,
ReconDataInCellDesignerXmlParserTest.class,
SbmlValidationTests.class,
UnitXmlParserTest.class,
......
package lcsb.mapviewer.converter.model.celldesigner;
import static org.junit.Assert.*;
import org.junit.Test;
public class CellDesignerParserUtilsTest {
@Test
public void test() {
assertTrue(Double.isInfinite(new CellDesignerParserUtils().parseDouble("INF")));
}
}
package lcsb.mapviewer.converter.model.celldesigner.parameter;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ GenericParameterXmlParserTest.class, ParameterXmlParserTest.class })
public class AllParameterTests {
}
package lcsb.mapviewer.converter.model.celldesigner.parameter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.nio.file.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.model.map.kinetics.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
@RunWith(Parameterized.class)
public class GenericParameterXmlParserTest extends CellDesignerTestFunctions {
private String filename;
public GenericParameterXmlParserTest(String filename) {
this.filename = filename;
}
@Parameters(name = "{0}")
public static Collection<Object[]> data() throws IOException {
List<Object[]> result = new ArrayList<>();
try (Stream<Path> walk = Files.walk(Paths.get("testFiles/parameter"))) {
List<String> filenames = walk.filter(Files::isRegularFile)
.map(x -> x.toString()).collect(Collectors.toList());
for (String string : filenames) {
result.add(new Object[] { string });
}
return result;
}
}
@Test
public void testSerialization() throws InvalidXmlSchemaException, IOException {
SbmlUnit volume = new SbmlUnit("volume");
Model model = new ModelFullIndexed(null);
model.addUnit(volume);
ParameterXmlParser parser = new ParameterXmlParser(model);
SbmlParameter parameter = parser
.parseParameter(super.getXmlDocumentFromFile(filename).getFirstChild());
assertNotNull(parameter);
String xml = parser.toXml(parameter);
SbmlParameter parameter2 = parser.parseParameter(super.getNodeFromXmlString(xml));
assertEquals(0, new SbmlParameterComparator().compare(parameter, parameter2));
}
}
package lcsb.mapviewer.converter.model.celldesigner.parameter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import java.io.IOException;
......@@ -10,8 +9,7 @@ import org.junit.Test;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.model.map.kinetics.SbmlParameter;
import lcsb.mapviewer.model.map.kinetics.SbmlUnit;
import lcsb.mapviewer.model.map.kinetics.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
......@@ -23,14 +21,43 @@ public class ParameterXmlParserTest extends CellDesignerTestFunctions {
Model model = new ModelFullIndexed(null);
model.addUnit(volume);
ParameterXmlParser parser = new ParameterXmlParser(model);
SbmlParameter unit = parser
SbmlParameter parameter = parser
.parseParameter(super.getXmlDocumentFromFile("testFiles/parameter/simple.xml").getFirstChild());
assertNotNull(unit);
assertEquals(unit.getParameterId(), "param_id");
assertEquals(unit.getName(), "Parameter name");
assertEquals(unit.getValue(), 12.0, Configuration.EPSILON);
assertEquals(unit.getUnits(), volume);
assertNotNull(parameter);
assertEquals(parameter.getParameterId(), "param_id");
assertEquals(parameter.getName(), "Parameter name");
assertEquals(parameter.getValue(), 12.0, Configuration.EPSILON);
assertEquals(parameter.getUnits(), volume);
}
@Test
public void testParseInfinity() throws InvalidXmlSchemaException, IOException {
SbmlUnit volume = new SbmlUnit("volume");
Model model = new ModelFullIndexed(null);
model.addUnit(volume);
ParameterXmlParser parser = new ParameterXmlParser(model);
SbmlParameter parameter = parser
.parseParameter(super.getXmlDocumentFromFile("testFiles/parameter/infinity_parameter.xml").getFirstChild());
assertNotNull(parameter);
assertTrue(Double.isInfinite(parameter.getValue()));
assertTrue(parameter.getValue() > 0);
}
@Test
public void testParseNegativeInfinity() throws InvalidXmlSchemaException, IOException {
SbmlUnit volume = new SbmlUnit("volume");
Model model = new ModelFullIndexed(null);
model.addUnit(volume);
ParameterXmlParser parser = new ParameterXmlParser(model);
SbmlParameter parameter = parser
.parseParameter(
super.getXmlDocumentFromFile("testFiles/parameter/negative_infinity_parameter.xml").getFirstChild());
assertNotNull(parameter);
assertTrue(Double.isInfinite(parameter.getValue()));
assertTrue(parameter.getValue() < 0);
}
}
<parameter metaid="param" id="param" name="infinity param" value="INF" units="substance"/>
<parameter metaid="param" id="param" name="infinity param" value="-INF" units="substance"/>
alter table sbml_parameter_table alter COLUMN value type double precision;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment