Commit f5d1a5af authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1203-import-infinity-kinetic-parameter' into 'devel_14.0.x'

kinetic parameter with infinity can be parsed properly

See merge request !1096
parents 5dc63ecb 15d235c9
Pipeline #23833 failed with stage
in 61 minutes and 52 seconds
...@@ -5,6 +5,10 @@ minerva (14.0.11) stable; urgency=medium ...@@ -5,6 +5,10 @@ minerva (14.0.11) stable; urgency=medium
(#1198) (#1198)
* Bug fix: export to CellDesigner deal with CellDesigner issue that does not * Bug fix: export to CellDesigner deal with CellDesigner issue that does not
allow complex species alias to be shorter than 2 characters (#1204) 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 -- 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; ...@@ -6,6 +6,7 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser; import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; 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.kinetics.SbmlParameter;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
...@@ -27,7 +28,7 @@ public class ParameterXmlParser { ...@@ -27,7 +28,7 @@ public class ParameterXmlParser {
SbmlParameter result = new SbmlParameter(parameterId); SbmlParameter result = new SbmlParameter(parameterId);
result.setName(XmlParser.getNodeAttr("name", unitNode)); 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))); result.setUnits(model.getUnitsByUnitId(XmlParser.getNodeAttr("units", unitNode)));
return result; return result;
} }
......
...@@ -9,7 +9,7 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.AllAnnotationTests ...@@ -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.compartment.AllCompartmentTests;
import lcsb.mapviewer.converter.model.celldesigner.function.AllFunctionTests; import lcsb.mapviewer.converter.model.celldesigner.function.AllFunctionTests;
import lcsb.mapviewer.converter.model.celldesigner.geometry.AllGeometryTests; 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.reaction.AllReactionTests;
import lcsb.mapviewer.converter.model.celldesigner.species.AllSpeciesTests; import lcsb.mapviewer.converter.model.celldesigner.species.AllSpeciesTests;
import lcsb.mapviewer.converter.model.celldesigner.structure.AllStructureTests; import lcsb.mapviewer.converter.model.celldesigner.structure.AllStructureTests;
...@@ -23,18 +23,19 @@ import lcsb.mapviewer.converter.model.celldesigner.unit.UnitXmlParserTest; ...@@ -23,18 +23,19 @@ import lcsb.mapviewer.converter.model.celldesigner.unit.UnitXmlParserTest;
AllCompartmentTests.class, AllCompartmentTests.class,
AllFunctionTests.class, AllFunctionTests.class,
AllGeometryTests.class, AllGeometryTests.class,
AllParameterTests.class,
AllReactionTests.class, AllReactionTests.class,
AllSpeciesTests.class, AllSpeciesTests.class,
AllStructureTests.class, AllStructureTests.class,
AllTypesTests.class, AllTypesTests.class,
CellDesignerElementCollectionTest.class, CellDesignerElementCollectionTest.class,
CellDesignerXmlParserTest.class, CellDesignerXmlParserTest.class,
CellDesignerParserUtilsTest.class,
ComplexParserTests.class, ComplexParserTests.class,
InvalidGroupExceptionTest.class, InvalidGroupExceptionTest.class,
LayerXmlParserTest.class, LayerXmlParserTest.class,
NestedComplexParsingTests.class, NestedComplexParsingTests.class,
ModificationTest.class, ModificationTest.class,
ParameterXmlParserTest.class,
ReconDataInCellDesignerXmlParserTest.class, ReconDataInCellDesignerXmlParserTest.class,
SbmlValidationTests.class, SbmlValidationTests.class,
UnitXmlParserTest.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; package lcsb.mapviewer.converter.model.celldesigner.parameter;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import java.io.IOException; import java.io.IOException;
...@@ -10,8 +9,7 @@ import org.junit.Test; ...@@ -10,8 +9,7 @@ import org.junit.Test;
import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.model.map.kinetics.SbmlParameter; import lcsb.mapviewer.model.map.kinetics.*;
import lcsb.mapviewer.model.map.kinetics.SbmlUnit;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed; import lcsb.mapviewer.model.map.model.ModelFullIndexed;
...@@ -23,14 +21,43 @@ public class ParameterXmlParserTest extends CellDesignerTestFunctions { ...@@ -23,14 +21,43 @@ public class ParameterXmlParserTest extends CellDesignerTestFunctions {
Model model = new ModelFullIndexed(null); Model model = new ModelFullIndexed(null);
model.addUnit(volume); model.addUnit(volume);
ParameterXmlParser parser = new ParameterXmlParser(model); ParameterXmlParser parser = new ParameterXmlParser(model);
SbmlParameter unit = parser SbmlParameter parameter = parser
.parseParameter(super.getXmlDocumentFromFile("testFiles/parameter/simple.xml").getFirstChild()); .parseParameter(super.getXmlDocumentFromFile("testFiles/parameter/simple.xml").getFirstChild());
assertNotNull(unit); assertNotNull(parameter);
assertEquals(unit.getParameterId(), "param_id"); assertEquals(parameter.getParameterId(), "param_id");
assertEquals(unit.getName(), "Parameter name"); assertEquals(parameter.getName(), "Parameter name");
assertEquals(unit.getValue(), 12.0, Configuration.EPSILON); assertEquals(parameter.getValue(), 12.0, Configuration.EPSILON);
assertEquals(unit.getUnits(), volume); 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