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

export of old map (uploaded before 14.0.0 ) to SBML produced invalid SBML

parent 31315a08
Pipeline #15162 passed with stage
in 9 minutes and 47 seconds
......@@ -16,6 +16,8 @@ minerva (14.0.3) stable; urgency=medium
* Bug fix: opening map with no available background crashed (#964)
* Bug fix: uploading SBGN file that does not pass xsd validation provides a
warning, but does not fail upload (#937)
* Bug fix: export of the map to SBML that was imported with older version
(below 14.0.0) didn't produce valid SBML (#970)
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 16 Oct 2019 9:00:00 +0200
......
......@@ -27,7 +27,6 @@ public abstract class SbmlElementExporter<T extends Element, S extends org.sbml.
protected void assignLayoutToGlyph(T element, AbstractReferenceGlyph speciesGlyph) {
BoundingBox boundingBox = new BoundingBox();
boundingBox.setPosition(new Point(element.getX(), element.getY(), element.getZ()));
Dimensions dimensions = new Dimensions();
dimensions.setWidth(element.getWidth());
......
package lcsb.mapviewer.converter.model.sbml.species;
import java.awt.*;
import java.awt.Color;
import java.util.*;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.*;
import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.multi.*;
import org.sbml.jsbml.ext.render.*;
import org.sbml.jsbml.ext.render.Rectangle;
import lcsb.mapviewer.converter.model.sbml.SbmlElementExporter;
import lcsb.mapviewer.converter.model.sbml.SbmlExtension;
......@@ -335,14 +332,21 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
if (element.getInitialConcentration() != null) {
result.setInitialConcentration(element.getInitialConcentration());
}
if (element.getInitialAmount() == null && element.getInitialConcentration() == null) {
result.setInitialConcentration(0);
}
if (element.hasOnlySubstanceUnits() != null) {
result.setHasOnlySubstanceUnits(element.hasOnlySubstanceUnits());
}
if (element.getBoundaryCondition() != null) {
result.setBoundaryCondition(element.getBoundaryCondition());
} else {
result.setBoundaryCondition(false);
}
if (element.getConstant() != null) {
result.setConstant(element.getConstant());
} else {
result.setConstant(false);
}
if (isExtensionEnabled(SbmlExtension.MULTI)) {
assignMultiExtensionData(element, result);
......
......@@ -19,6 +19,7 @@ import lcsb.mapviewer.converter.model.sbml.species.AllSbmlSpeciesTests;
ElementPropertiesExport.class,
ElementPropertiesExportToMultiTest.class,
ElementPropertiesExportToLayoutTest.class,
GeneratedSbmlValidationTests.class,
MultiParserTest.class,
ReactionPropertiesExportToMultiTest.class,
SbmlBioEntityExporterTest.class,
......
package lcsb.mapviewer.converter.model.sbml;
import java.io.IOException;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import lcsb.mapviewer.commands.CommandExecutionException;
import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.ZIndexPopulator;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
@RunWith(Parameterized.class)
public class GeneratedSbmlValidationTests extends SbmlTestFunctions {
Logger logger = LogManager.getLogger();
Model model ;
public GeneratedSbmlValidationTests(Model model, String name) {
this.model= model;
}
@Parameters(name = "{index}: {1}")
public static Collection<Object[]> data() throws Exception {
List<Object[]> result = new ArrayList<>();
result.add(createRow( createModelWithSingleSpecies() ));
return result;
}
private static Object[] createRow(Model model) {
new ZIndexPopulator().populateZIndex(model);
return new Object[] {model, model.getName()};
}
private static Model createModelWithSingleSpecies() throws Exception {
Model model = new ModelFullIndexed(null);
model.setName("Single species");
Species species = new GenericProtein("id");
species.setBoundaryCondition(null);
species.setInitialConcentration(null);
species.setInitialAmount(null);
species.setConstant(null);
model.addElement(species);
new ApplySimpleLayoutModelCommand(model).execute();
return model;
}
@Test
public void testIsValidSbml() throws Exception {
SbmlParser parser = new SbmlParser();
String xml = parser.model2String(model);
validateSBML(xml, "xxx");
}
}
package lcsb.mapviewer.converter.model.sbml;
import java.awt.*;
import static org.junit.Assert.assertEquals;
import java.awt.Desktop;
import java.awt.geom.Point2D;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.UnitTestFailedWatcher;
import lcsb.mapviewer.common.*;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.graphics.*;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
......@@ -136,4 +150,30 @@ public class SbmlTestFunctions {
return model2;
}
protected void validateSBML(String xmlContent, String filename) throws IOException, ClientProtocolException, InvalidXmlSchemaException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost("http://sbml.org/validator/");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("file", xmlContent, ContentType.TEXT_PLAIN);
builder.addBinaryBody(
"file",
new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8)),
ContentType.APPLICATION_OCTET_STREAM,
filename);
builder.addTextBody("output", "xml", ContentType.TEXT_PLAIN);
builder.addTextBody("offcheck", "u,r", ContentType.TEXT_PLAIN);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
CloseableHttpResponse response = httpClient.execute(uploadFile);
String responseXml = EntityUtils.toString(response.getEntity());
Document document = XmlParser.getXmlDocumentFromString(responseXml);
List<Node> problems = XmlParser.getAllNotNecessirellyDirectChild("problem", document);
if (problems.size() > 0) {
logger.debug(responseXml);
}
assertEquals("SBML is invalid", 0, problems.size());
}
}
package lcsb.mapviewer.converter.model.sbml;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.model.map.model.Model;
......@@ -52,28 +37,7 @@ public class SbmlValidationTests extends SbmlTestFunctions {
Model model = parser.createModel(new ConverterParams().filename(filename));
String xml = parser.model2String(model);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost("http://sbml.org/validator/");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("file", xml, ContentType.TEXT_PLAIN);
builder.addBinaryBody(
"file",
new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)),
ContentType.APPLICATION_OCTET_STREAM,
filename);
builder.addTextBody("output", "xml", ContentType.TEXT_PLAIN);
builder.addTextBody("offcheck", "u,r", ContentType.TEXT_PLAIN);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
CloseableHttpResponse response = httpClient.execute(uploadFile);
String responseXml = EntityUtils.toString(response.getEntity());
Document document = XmlParser.getXmlDocumentFromString(responseXml);
List<Node> problems = XmlParser.getAllNotNecessirellyDirectChild("problem", document);
if (problems.size() > 0) {
logger.debug(responseXml);
}
assertEquals("SBML is invalid", 0, problems.size());
validateSBML(xml, filename);
}
}
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