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

z-index implemented for gpml

parent 2ae42db3
......@@ -145,7 +145,10 @@ public class CellDesignerXmlParser extends Converter {
}
// we ignore metaid - it's useless and obstruct data model
// model.setMetaId(XmlParser.getNodeAttr("metaId", modelNode));
model.setIdModel(XmlParser.getNodeAttr("id", modelNode));
String modelId = XmlParser.getNodeAttr("id", modelNode);
if (modelId != null && !modelId.isEmpty()) {
model.setIdModel(modelId);
}
Node compartmentNode = XmlParser.getNode("listOfCompartments", modelNode.getChildNodes());
if (compartmentNode != null) {
......@@ -612,7 +615,11 @@ public class CellDesignerXmlParser extends Converter {
+ "xmlns:celldesigner=\"http://www.sbml.org/2001/ns/celldesigner\" level=\"2\" version=\"4\">\n");
// metaid is a string cell designer id, usually it's model id and as far as
// we can tell it's not used at all
result.append("<model metaid=\"" + model.getIdModel() + "\" id=\"" + model.getIdModel() + "\">\n");
result.append("<model ");
if (model.getIdModel() != null) {
result.append("metaid=\"" + model.getIdModel() + "\" id=\"" + model.getIdModel() + "\"");
}
result.append(">\n");
result.append(unitCollectionXmlParser.toXml(model.getUnits()));
result.append(functionCollectionXmlParser.toXml(model.getFunctions()));
......@@ -699,7 +706,8 @@ public class CellDesignerXmlParser extends Converter {
result.append("</celldesigner:extension>\n");
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
result.append(xmlAnnotationParser.dataSetToXmlString(model.getMiriamData(), model.getAuthors(), model.getCreationDate(), model.getModificationDates()));
result.append(xmlAnnotationParser.dataSetToXmlString(model.getMiriamData(), model.getAuthors(),
model.getCreationDate(), model.getModificationDates()));
result.append("</annotation>\n");
return result.toString();
}
......
......@@ -404,4 +404,8 @@ public class Layer implements Serializable {
public void removeLayerText(LayerText toRemove) {
texts.remove(toRemove);
}
public boolean isEmpty() {
return this.getOvals().size() == 0 && this.getRectangles().size() == 0 && this.getTexts().size() == 0 && this.getLines().size()==0;
}
}
......@@ -133,7 +133,7 @@ public class GpmlParser {
* @param node
* xml node where data is stored
* @param graph
* object where data is sotred
* object where data is stored
*/
protected void setSize(Node node, Graph graph) {
Element eElement = (Element) node;
......@@ -149,7 +149,7 @@ public class GpmlParser {
* @param groups
* xml nodes
* @param graph
* object where data is sotred
* object where data is stored
* @throws UnknownAttributeValueException
* thrown when there is a problem with xml attributes
*/
......
......@@ -281,6 +281,7 @@ public class ModelContructor {
}
res.addMiriamData(dataNode.getReferences());
res.setZ(dataNode.getzOrder());
res.setName(dataNode.getName());
return res;
}
......@@ -646,6 +647,7 @@ public class ModelContructor {
reaction.setReversible(mapping.isReversible());
reaction.addMiriamData(interaction.getReferences());
reaction.setZ(interaction.getzOrder());
for (String ref : interaction.getBiopaxReferences()) {
BiopaxPublication publication = graph.getBiopaxData().getPublicationByReference(ref);
MiriamData md = biopaxParser.createMiriamData(publication);
......@@ -926,9 +928,6 @@ public class ModelContructor {
model.setWidth(graph.getBoardWidth());
model.setHeight(graph.getBoardHeight());
model.setIdModel("1");
model.getLayers().add(data.layer);
addComplexSpecies(model, graph, data);
addElement(model, graph, data);
putSpeciesIntoComplexes(graph, data);
......@@ -965,11 +964,15 @@ public class ModelContructor {
logger.warn("[Biopax, " + references.toString() + "]\tModel annotations are not supported.");
}
data.layer.addLayerLines(createLines(graph));
if (!data.layer.isEmpty()) {
model.getLayers().add(data.layer);
}
assignNamesToComplexes(model);
assignNamesToCompartments(model);
data.layer.addLayerLines(createLines(graph));
putAliasesIntoCompartments(model);
return model;
......
......@@ -5,12 +5,10 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import org.apache.log4j.Logger;
import org.junit.Test;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
......@@ -18,199 +16,183 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.wikipathway.XML.GPMLToModel;
import org.apache.log4j.Logger;
import org.junit.Test;
public class ComplexReactionToModelTest extends WikipathwaysTestFunctions{
/**
* Default class logger.
*/
static Logger logger = Logger.getLogger(ComplexReactionToModelTest.class);
@Test
public void ComplexReactionTest() throws Exception {
try {
String fileName = "testFiles/reactions/two_segment_reaction.gpml";
Model model1 = new GPMLToModel().getModel(fileName);
assertEquals(1, model1.getReactions().size());
Reaction reaction = model1.getReactions().iterator().next();
public class ComplexReactionToModelTest extends WikipathwaysTestFunctions {
/**
* Default class logger.
*/
static Logger logger = Logger.getLogger(ComplexReactionToModelTest.class);
assertEquals(1, reaction.getReactants().size());
assertEquals(1, reaction.getProducts().size());
@Test
public void ComplexReactionTest() throws Exception {
try {
String fileName = "testFiles/reactions/two_segment_reaction.gpml";
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model1 = new GPMLToModel().getModel(fileName);
@Test
public void ComplexReactantReactionTest() throws Exception {
try {
String fileName = "testFiles/reactions/two_reactants_reaction.gpml";
assertEquals(1, model1.getReactions().size());
Model model1 = new GPMLToModel().getModel(fileName);
Reaction reaction = model1.getReactions().iterator().next();
assertEquals(1, model1.getReactions().size());
assertEquals(1, reaction.getReactants().size());
assertEquals(1, reaction.getProducts().size());
Reaction reaction = model1.getReactions().iterator().next();
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
assertEquals(2, reaction.getReactants().size());
assertEquals(1, reaction.getProducts().size());
@Test
public void ComplexReactantReactionTest() throws Exception {
try {
String fileName = "testFiles/reactions/two_reactants_reaction.gpml";
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model1 = new GPMLToModel().getModel(fileName);
@Test
public void ComplexSplitReactionTest() throws Exception {
try {
String fileName = "testFiles/reactions/split_two_segment_reaction.gpml";
assertEquals(1, model1.getReactions().size());
Model model1 = new GPMLToModel().getModel(fileName);
Reaction reaction = model1.getReactions().iterator().next();
assertEquals(1, model1.getReactions().size());
assertEquals(2, reaction.getReactants().size());
assertEquals(1, reaction.getProducts().size());
Reaction reaction = model1.getReactions().iterator().next();
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
assertEquals(1, reaction.getReactants().size());
assertEquals(2, reaction.getProducts().size());
@Test
public void ComplexSplitReactionTest() throws Exception {
try {
String fileName = "testFiles/reactions/split_two_segment_reaction.gpml";
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model1 = new GPMLToModel().getModel(fileName);
@Test
public void problematicReactantTest() throws Exception {
try {
ModelComparator mc = new ModelComparator(1.0);
assertEquals(1, model1.getReactions().size());
String fileName = "testFiles/small/problematic_reactant.gpml";
Reaction reaction = model1.getReactions().iterator().next();
Model model1 = new GPMLToModel().getModel(fileName);
assertEquals(1, reaction.getReactants().size());
assertEquals(2, reaction.getProducts().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2));
@Test
public void problematicReactantTest() throws Exception {
try {
ModelComparator mc = new ModelComparator(1.0);
assertEquals(7, getWarnings().size());
String fileName = "testFiles/small/problematic_reactant.gpml";
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model1 = new GPMLToModel().getModel(fileName);
@Test
public void problematicReactant2Test() throws Exception {
try {
ModelComparator mc = new ModelComparator(1.0);
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2));
String fileName = "testFiles/small/problematic_reactant_2.gpml";
assertEquals(7, getWarnings().size());
Model model1 = new GPMLToModel().getModel(fileName);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
@Test
public void problematicReactant2Test() throws Exception {
try {
ModelComparator mc = new ModelComparator(1.0);
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2));
String fileName = "testFiles/small/problematic_reactant_2.gpml";
assertEquals(3, getWarnings().size());
Model model1 = new GPMLToModel().getModel(fileName);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2));
@Test
public void missingNodesInReactionTest() throws Exception {
try {
ModelComparator mc = new ModelComparator(1.0);
assertEquals(3, getWarnings().size());
String fileName = "testFiles/small/missing_nodes_in_reaction.gpml";
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Model model1 = new GPMLToModel().getModel(fileName);
@Test
public void missingNodesInReactionTest() throws Exception {
try {
ModelComparator mc = new ModelComparator(1.0);
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
String fileName = "testFiles/small/missing_nodes_in_reaction.gpml";
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model1 = new GPMLToModel().getModel(fileName);
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2));
assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2));
assertEquals(5, getWarnings().size());
assertEquals(5, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testColorReaction() throws Exception {
try {
String fileName = "testFiles/small/color_reaction.gpml";
Model model = new GPMLToModel().getModel(fileName);
@Test
public void testColorReaction() throws Exception {
try {
String fileName = "testFiles/small/color_reaction.gpml";
Model model = new GPMLToModel().getModel(fileName);
assertEquals(1, model.getReactions().size());
assertEquals(1, model.getReactions().size());
Reaction reaction = model.getReactions().iterator().next();
Reaction reaction = model.getReactions().iterator().next();
assertFalse(Color.BLACK.equals(reaction.getReactants().get(0).getLine().getColor()));
assertFalse(Color.BLACK.equals(reaction.getReactants().get(0).getLine().getColor()));
Element redAlias = model.getElementByElementId("d9620");
Element blackAlias = model.getElementByElementId("d046f");
assertFalse(Color.BLACK.equals(redAlias.getColor()));
assertTrue(Color.WHITE.equals(blackAlias.getColor()));
Element redAlias = model.getElementByElementId("d9620");
Element blackAlias = model.getElementByElementId("d046f");
assertFalse(Color.BLACK.equals(redAlias.getColor()));
assertTrue(Color.WHITE.equals(blackAlias.getColor()));
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
/**
* @throws Exception
*/
@Test
public void testReactionWithTwoSegments() throws Exception {
try {
String fileName = "testFiles/small/color_reaction.gpml";
Model model = new GPMLToModel().getModel(fileName);
/**
* @throws Exception
*/
@Test
public void testReactionWithTwoSegments() throws Exception {
try {
String fileName = "testFiles/small/color_reaction.gpml";
Model model = new GPMLToModel().getModel(fileName);
Reaction reaction = model.getReactions().iterator().next();
Reaction reaction = model.getReactions().iterator().next();
int lineCount = 0;
for (AbstractNode node : reaction.getNodes()) {
lineCount += node.getLine().getLines().size();
}
int lineCount = 0;
for (AbstractNode node : reaction.getNodes()) {
lineCount += node.getLine().getLines().size();
}
assertEquals(4, lineCount);
assertEquals(4, lineCount);
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -46,11 +46,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
Model model1 = new GPMLToModel().getModel(pathToFile + fileName);
assertEquals(22, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -68,11 +64,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
Model model1 = new GPMLToModel().getModel(pathToFile + fileName);
assertEquals(22, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -91,11 +83,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
Model model1 = new GPMLToModel().getModel(pathToFile + fileName);
assertEquals(15, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -114,11 +102,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
assertEquals(16, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -137,11 +121,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
assertEquals(3, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -160,11 +140,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
assertEquals(38, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -184,11 +160,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
assertEquals(41, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -208,11 +180,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
assertEquals(22, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xml = parser.model2String(model1);
InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
Model model2 = serializeModelOverCellDesignerParser(model1);
assertEquals(0, mc.compare(model1, model2));
} catch (Exception e) {
......@@ -232,12 +200,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
assertEquals(0, getWarnings().size());
CellDesignerXmlParser parser = new CellDesignerXmlParser();