Commit 61cc24c2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1273-exported-as-gpml-that-can-not-upload-to-minerva' into 'master'

Resolve "exported as GPML that can not upload to MINERVA"

Closes #1267 and #1273

See merge request !1166
parents 88d42a60 99c6840e
Pipeline #28780 passed with stage
in 14 minutes and 32 seconds
......@@ -14,6 +14,8 @@ minerva (15.0.0~beta.5) unstable; urgency=medium
(#1268)
* Bug fix: proper color is parsed from CellDesigner species marked as 'brief'
(#1268)
* Bug fix: unknown elements are exported to 'Unknown' data nodes in GPML
(#1273)
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 2 Jun 2020 16:00:00 +0200
......
......@@ -119,6 +119,8 @@ public class ModelContructor {
species = new Complex(dataNode.getGraphId());
} else if (type != null && type.equalsIgnoreCase("None")) {
species = new Unknown(dataNode.getGraphId());
} else if (type == null) {
species = new Unknown(dataNode.getGraphId());
} else {
logger.warn(dataNode.getLogMarker(), "Unknown species type: " + type + ". Using Unknown");
species = new Unknown(dataNode.getGraphId());
......
......@@ -123,6 +123,8 @@ public class ModelToGPML {
res = "Metabolite";
} else if (species instanceof Phenotype) {
res = "Pathway";
} else if (species instanceof Unknown) {
res = null;
} else if (species instanceof Degraded) {
res = "Unknown";
} else {
......@@ -480,8 +482,8 @@ public class ModelToGPML {
StringBuilder dataNodes = new StringBuilder("");
for (Species species : model.getNotComplexSpeciesList()) {
if (!(species instanceof Unknown) && !(species instanceof Complex) && !(species instanceof Degraded)) {
dataNodes.append(speciesToXml(species));
if (!(species instanceof Complex) && !(species instanceof Degraded)) {
dataNodes.append(speciesToDataNode(species));
}
}
......@@ -520,14 +522,6 @@ public class ModelToGPML {
return dataNodes.toString();
}
String speciesToXml(Species species) throws ConverterException {
if (species instanceof Unknown) {
return speciesToLabel(species);
} else {
return speciesToDataNode(species);
}
}
String speciesToLabel(Species species) throws ConverterException {
StringBuilder result = new StringBuilder();
result.append(
......@@ -593,17 +587,21 @@ public class ModelToGPML {
return result.toString();
}
private String speciesToDataNode(Species species) throws ConverterException {
String speciesToDataNode(Species species) throws ConverterException {
StringBuilder result = new StringBuilder();
String lineStyle = null;
if (species.isHypothetical()) {
lineStyle = GpmlLineType.DASHED.getGpmlString();
}
String nodeType = getType(species);
result.append(
" <DataNode TextLabel=\"" + species.getName() + "\" "
+ "GraphId=\"" + species.getElementId() + "\""
+ " Type=\"" + getType(species) + "\"");
+ "GraphId=\"" + species.getElementId() + "\"");
if (nodeType != null) {
result.append(" Type=\"" + nodeType + "\"");
}
if (species.getComplex() != null) {
result.append(" GroupRef=\"" + species.getComplex().getElementId() + "\"");
}
......@@ -813,7 +811,6 @@ public class ModelToGPML {
gpml.append(getStates(model));
String groups = getGroups(model);
gpml.append(getInteractions(model));
gpml.append(getLabels(model));
gpml.append(getShapes(model));
gpml.append(groups);
Set<MiriamData> set = new HashSet<>();
......@@ -846,18 +843,6 @@ public class ModelToGPML {
return colorParser.colorToHtml(color).substring(1);
}
protected String getLabels(Model model) throws ConverterException {
StringBuilder dataNodes = new StringBuilder("");
for (Species species : model.getNotComplexSpeciesList()) {
if (species instanceof Unknown) {
dataNodes.append(speciesToLabel(species));
}
}
return dataNodes.toString();
}
protected String getShapes(Model model) throws ConverterException {
StringBuilder result = new StringBuilder("");
result.append(getComparments(model));
......
......@@ -266,7 +266,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testExportUnknownSpecies() throws Exception {
ModelToGPML parser = new ModelToGPML("xyz");
String content = parser.speciesToXml(createUnknown());
String content = parser.speciesToDataNode(createUnknown());
assertNotNull(content);
}
......@@ -280,15 +280,6 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
assertEquals(1, getWarnings().size());
}
@Test
public void testGetDataNodes() throws Exception {
ModelToGPML parser = new ModelToGPML("xyz");
Model model = new ModelFullIndexed(null);
model.addElement(createUnknown());
String xml = parser.getDataNodes(model);
assertEquals("", xml);
}
@Test
public void testDegraded() throws Exception {
Model model = new ModelFullIndexed(null);
......@@ -304,27 +295,28 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
private Unknown createUnknown() {
Unknown result = new Unknown("id" + (speciesCounter++));
result.setName("s2");
result.setWidth(10);
result.setHeight(10);
result.setX(1);
result.setY(1);
result.setZ(15);
setObligatoryFields(result);
return result;
}
private void setObligatoryFields(Species species) {
species.setName("s2");
species.setWidth(10);
species.setHeight(10);
species.setX(1);
species.setY(1);
species.setZ(15);
species.setNamePoint(species.getCenter());
species.setNameHorizontalAlign(HorizontalAlign.CENTER);
species.setNameVerticalAlign(VerticalAlign.MIDDLE);
}
private Degraded createDegraded() {
Degraded result = new Degraded("id" + (speciesCounter++));
setObligatoryFields(result);
result.setName("");
result.setWidth(10);
result.setHeight(10);
result.setX(1);
result.setY(1);
result.setZ(15);
result.setNamePoint(result.getCenter());
result.setNameHorizontalAlign(HorizontalAlign.CENTER);
result.setNameVerticalAlign(VerticalAlign.MIDDLE);
return result;
}
......@@ -386,4 +378,22 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
assertEquals(0, new ModelComparator().compare(model, model2));
}
@Test
public void testExportUnknown() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Species p1 = createUnknown();
model.addElement(p1);
lcsb.mapviewer.wikipathway.GpmlParser parser = new lcsb.mapviewer.wikipathway.GpmlParser();
String xml = parser.model2String(model);
Model model2 = parser.createModel(new ConverterParams().inputStream(new ByteArrayInputStream(xml.getBytes())));
assertEquals(0, new ModelComparator().compare(model, model2));
}
}
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