Commit 00828d27 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1310-sbgn-source-sink-issue' into 'devel_15.0.x'

Resolve "SBGN > CellDesigner conversion of source/sink produces species with empty names"

See merge request !1217
parents 3d8e98d1 0255e063
Pipeline #29567 failed with stage
in 20 minutes and 41 seconds
...@@ -23,8 +23,10 @@ minerva (15.0.2) stable; urgency=medium ...@@ -23,8 +23,10 @@ minerva (15.0.2) stable; urgency=medium
* Bug fix: at random time points there was an issue with cached data (#1323) * Bug fix: at random time points there was an issue with cached data (#1323)
* Bug fix: connection to DAPI timeouted sometimes which resulted in error * Bug fix: connection to DAPI timeouted sometimes which resulted in error
when checking for all chemicals for specfific protein (#1324) when checking for all chemicals for specfific protein (#1324)
* Bug fix: complex/compartment with empty name was incorrectly exported to
CellDesigner (#1310)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 29 Jun 2020 11:00:00 +0200 -- Piotr Gawron <piotr.gawron@uni.lu> Wed, 1 Jul 2020 16:00:00 +0200
minerva (15.0.1) stable; urgency=medium minerva (15.0.1) stable; urgency=medium
* Bug fix: when there was problem with DAPI minerva threw unexpected error * Bug fix: when there was problem with DAPI minerva threw unexpected error
......
...@@ -118,7 +118,9 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC ...@@ -118,7 +118,9 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC
sb.append("</notes>\n"); sb.append("</notes>\n");
sb.append("<annotation>\n"); sb.append("<annotation>\n");
sb.append("<celldesigner:extension>\n"); sb.append("<celldesigner:extension>\n");
sb.append("<celldesigner:name>" + encodeName(compartment.getName()) + "</celldesigner:name>\n"); if (!compartment.getName().isEmpty()) {
sb.append("<celldesigner:name>" + encodeName(compartment.getName()) + "</celldesigner:name>\n");
}
sb.append("</celldesigner:extension>\n"); sb.append("</celldesigner:extension>\n");
sb.append(xmlAnnotationParser.dataSetToXmlString(compartment.getMiriamData(), elements.getElementId(compartment))); sb.append(xmlAnnotationParser.dataSetToXmlString(compartment.getMiriamData(), elements.getElementId(compartment)));
sb.append("</annotation>\n"); sb.append("</annotation>\n");
......
...@@ -196,7 +196,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec ...@@ -196,7 +196,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
} }
if (rdfNode != null) { if (rdfNode != null) {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER); XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode)); species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode));
} }
...@@ -287,7 +288,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec ...@@ -287,7 +288,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
builder.append("</celldesigner:extension>\n"); builder.append("</celldesigner:extension>\n");
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER); XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
builder.append(xmlAnnotationParser.dataSetToXmlString(species.getMiriamData(), elements.getElementId(species))); builder.append(xmlAnnotationParser.dataSetToXmlString(species.getMiriamData(), elements.getElementId(species)));
builder.append("</annotation>\n"); builder.append("</annotation>\n");
...@@ -327,7 +329,9 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec ...@@ -327,7 +329,9 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
} }
SpeciesState state = new SpeciesState(species); SpeciesState state = new SpeciesState(species);
sb.append(speciesStateToXml(state)); sb.append(speciesStateToXml(state));
sb.append("<celldesigner:name>" + XmlParser.escapeXml(encodeName(species.getName())) + "</celldesigner:name>\n"); if (!species.getName().isEmpty()) {
sb.append("<celldesigner:name>" + XmlParser.escapeXml(encodeName(species.getName())) + "</celldesigner:name>\n");
}
Boolean hypothetical = species.getHypothetical(); Boolean hypothetical = species.getHypothetical();
if (hypothetical != null) { if (hypothetical != null) {
......
...@@ -22,13 +22,17 @@ public class UnitCollectionXmlParser { ...@@ -22,13 +22,17 @@ public class UnitCollectionXmlParser {
} }
public String toXml(Set<SbmlUnit> units) { public String toXml(Set<SbmlUnit> units) {
StringBuilder builder = new StringBuilder(); if (units.size() > 0) {
builder.append("<listOfUnitDefinitions>\n"); StringBuilder builder = new StringBuilder();
for (SbmlUnit unit : units) { builder.append("<listOfUnitDefinitions>\n");
builder.append(unitParser.toXml(unit)); for (SbmlUnit unit : units) {
builder.append(unitParser.toXml(unit));
}
builder.append("</listOfUnitDefinitions>\n");
return builder.toString();
} else {
return "";
} }
builder.append("</listOfUnitDefinitions>\n");
return builder.toString();
} }
} }
...@@ -117,7 +117,7 @@ public abstract class CellDesignerTestFunctions { ...@@ -117,7 +117,7 @@ public abstract class CellDesignerTestFunctions {
return doc; return doc;
} }
protected Model getModelForFile(String fileName) throws Exception { protected static Model getModelForFile(String fileName) throws Exception {
CellDesignerXmlParser parser = new CellDesignerXmlParser(); CellDesignerXmlParser parser = new CellDesignerXmlParser();
return parser.createModel(new ConverterParams().filename(fileName).sizeAutoAdjust(false)); return parser.createModel(new ConverterParams().filename(fileName).sizeAutoAdjust(false));
} }
...@@ -255,9 +255,9 @@ public abstract class CellDesignerTestFunctions { ...@@ -255,9 +255,9 @@ public abstract class CellDesignerTestFunctions {
return model2; return model2;
} }
int idCounter = 0; static int idCounter = 0;
protected GenericProtein createProtein() { protected static GenericProtein createProtein() {
GenericProtein protein = new GenericProtein("id" + (idCounter++)); GenericProtein protein = new GenericProtein("id" + (idCounter++));
protein.setActivity(true); protein.setActivity(true);
protein.setFontSize(4); protein.setFontSize(4);
......
...@@ -3,7 +3,6 @@ package lcsb.mapviewer.converter.model.celldesigner; ...@@ -3,7 +3,6 @@ package lcsb.mapviewer.converter.model.celldesigner;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
...@@ -26,35 +25,53 @@ import org.w3c.dom.Node; ...@@ -26,35 +25,53 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser; import lcsb.mapviewer.common.XmlParser;
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.species.Protein;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class SbmlValidationTests extends CellDesignerTestFunctions { public class SbmlValidationTests extends CellDesignerTestFunctions {
Logger logger = LogManager.getLogger(); Logger logger = LogManager.getLogger();
Model model;
String filename; String filename;
public SbmlValidationTests(String filename) { public SbmlValidationTests(String filename, Model model) {
this.filename = filename; this.filename= filename;
this.model = model;
} }
@Parameters(name = "{0}") @Parameters(name = "{0}")
public static Collection<Object[]> data() throws IOException { public static Collection<Object[]> data() throws Exception {
List<Object[]> result = new ArrayList<>(); List<Object[]> result = new ArrayList<>();
result.add(new Object[] { "testFiles/empty.xml" }); result.add(getTestSetFromFile("testFiles/empty.xml"));
result.add(new Object[] { "testFiles/parameter.xml" }); result.add(getTestSetFromFile("testFiles/parameter.xml"));
result.add(new Object[] { "testFiles/model_with_annotations.xml" }); result.add(getTestSetFromFile("testFiles/model_with_annotations.xml"));
result.add(new Object[] { "testFiles/reactions/modifier_with_operator.xml" }); result.add(getTestSetFromFile("testFiles/reactions/modifier_with_operator.xml"));
result.add(new Object[] { "testFiles/problematic/problematic_reaction_name.xml" }); result.add(getTestSetFromFile("testFiles/problematic/problematic_reaction_name.xml"));
result.add(new Object[] { "testFiles/reactions/kinetics.xml" }); result.add(getTestSetFromFile("testFiles/reactions/kinetics.xml"));
result.add(emptyProteinNameTest());
return result; return result;
} }
private static Object[] emptyProteinNameTest() {
Model model = new ModelFullIndexed(null);
model.setWidth(200);
model.setHeight(200);
Protein protein = createProtein();
protein.setName("");
model.addElement(protein);
return new Object[] { "empty-protein-name", model };
}
private static Object[] getTestSetFromFile(String string) throws Exception {
return new Object[] { string, getModelForFile(string) };
}
@Test @Test
public void testIsValidSbml() throws Exception { public void testIsValidSbml() throws Exception {
Model model = super.getModelForFile(filename);
CellDesignerXmlParser parser = new CellDesignerXmlParser(); CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model); String xml = parser.model2String(model);
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost("http://sbml.org/validator/"); HttpPost uploadFile = new HttpPost("http://sbml.org/validator/");
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
...@@ -74,6 +91,7 @@ public class SbmlValidationTests extends CellDesignerTestFunctions { ...@@ -74,6 +91,7 @@ public class SbmlValidationTests extends CellDesignerTestFunctions {
Document document = XmlParser.getXmlDocumentFromString(responseXml); Document document = XmlParser.getXmlDocumentFromString(responseXml);
List<Node> problems = XmlParser.getAllNotNecessirellyDirectChild("problem", document); List<Node> problems = XmlParser.getAllNotNecessirellyDirectChild("problem", document);
if (problems.size() > 0) { if (problems.size() > 0) {
logger.debug(xml);
logger.debug(responseXml); logger.debug(responseXml);
} }
assertEquals("SBML is invalid", 0, problems.size()); assertEquals("SBML is invalid", 0, problems.size());
......
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