diff --git a/CHANGELOG b/CHANGELOG index fe39b622484a2e2de39feedaa9f50d5e607dad94..81656787ed0d00e831ec78a868d305788fdc2b8a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,8 @@ minerva (14.0.0~beta.2) unstable; urgency=low * Bug fix: hide glyphs tab when necessary (#949) * Bug fix: user with write access but without can_create_privileges cannot create data overlay (#939) + * Bug fix: export to CD could misalign reaction lines that were imported from + format that didn't require reaction line to be attached to the species (#933) -- Piotr Gawron <piotr.gawron@uni.lu> Mon, 16 Sep 2019 21:00:00 +0200 diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java index 543b16a5bd33771872fa62f07070c3b89683153e..c871cbb767b4bfaa5974e6d8b19ef5bf2eb15152 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java @@ -963,6 +963,7 @@ public class ReactionToXml { String getEditPointsXmlStringForSimpleReaction(Reaction reaction) { Product product = reaction.getProducts().get(0); Reactant reactant = reaction.getReactants().get(0); + List<Point2D> points = new ArrayList<>(); for (int i = 0; i < reactant.getLine().getPoints().size() - 1; i++) { points.add(reactant.getLine().getPoints().get(i)); @@ -986,9 +987,18 @@ public class ReactionToXml { } PolylineData pd = new PolylineData(points); + pd.setPoint(0, getAnchorPoint(reactant.getElement(), reactant.getLine().getBeginPoint())); + pd.setPoint(pd.getPoints().size() - 1, getAnchorPoint(product.getElement(), productLine.getEndPoint())); return getEditPointsXmlStringForLine(new PolylineData[] { pd }, centerPosition); } + private Point2D getAnchorPoint(Element element, Point2D originalPoint) { + CellDesignerAliasConverter converter = new CellDesignerAliasConverter(element, sbgn); + + CellDesignerAnchor anchor = converter.getAnchorForCoordinates(element, originalPoint); + return converter.getPointCoordinates(element, anchor); + } + /** * Creates valid xml node with connectScheme for the reaction. * diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerTestFunctions.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerTestFunctions.java index 790087f132bb3b363cc2967e171a272cf9604964..d55b3d967e56949cbe20148c8ef0837b30cf6a27 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerTestFunctions.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerTestFunctions.java @@ -230,7 +230,7 @@ public abstract class CellDesignerTestFunctions { throws InconsistentModelException, UnsupportedEncodingException, InvalidInputDataExecption { CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xmlString = parser.model2String(model); - logger.debug(xmlString); +// logger.debug(xmlString); InputStream is = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java index 63e4b455a0a561f7c89f7ae388ae6246bbb331e0..be028cc32e0977ae977f16aad1ebfd2acd24f4cc 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java @@ -799,5 +799,56 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { assertEquals("Whole reaction should use the same reaction type", 1, reactionTypes.size()); } + @Test + public void testExportReactoinWithLinesNotAttachedToSpecies() throws Exception { + Model model = new ModelFullIndexed(null); + model.setIdModel("as"); + model.setWidth(1000); + model.setHeight(1000); + + Species protein = new SimpleMolecule("id1"); + protein.setX(383); + protein.setY(584); + protein.setWidth(140); + protein.setHeight(60); + model.addElement(protein); + + Species protein2 = new SimpleMolecule("id2"); + protein2.setX(351); + protein2.setY(697); + protein2.setWidth(100); + protein2.setHeight(60); + model.addElement(protein2); + + Reaction reaction = new StateTransitionReaction(); + reaction.setIdReaction("re1"); + reaction.setLine(new PolylineData(new Point2D.Double(401.0, 673.0), new Point2D.Double(401.0, 673.0))); + + Reactant reactant = new Reactant(protein); + reactant.setLine(new PolylineData(Arrays.asList( + new Point2D.Double(420.0, 644.0), + new Point2D.Double(420.0, 654.0), + new Point2D.Double(401.0, 654.0), + new Point2D.Double(401.0, 665.0)))); + reaction.addReactant(reactant); + model.addReaction(reaction); + + Product product = new Product(protein2); + product.setLine(new PolylineData(new Point2D.Double(401.0, 673.0), new Point2D.Double(401.0, 697.0))); + reaction.addProduct(product); + + Model model2 = serializeModel(model); + + Reaction reaction2 = model2.getReactionByReactionId("re1"); + + Reactant newReactant = reaction2.getReactants().get(0); + + // center part of the line shouldn't change - edges should be aligned to touch + // species + assertEquals(0, newReactant.getLine().getPoints().get(1).distance(reactant.getLine().getPoints().get(1)), + Configuration.EPSILON); + assertEquals(0, newReactant.getLine().getPoints().get(2).distance(reactant.getLine().getPoints().get(2)), + Configuration.EPSILON); + } } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXmlTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXmlTest.java index 3b13bce3e6901607d6a2692c79a98ecb285104ce..a1fddefcdbb319a12f02d971584798e1cbe061ba 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXmlTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXmlTest.java @@ -47,6 +47,9 @@ public class ReactionToXmlTest extends CellDesignerTestFunctions { Model model = new ModelFullIndexed(null); Species protein1 = new GenericProtein("2"); Species protein2 = new GenericProtein("3"); + protein2.setX(100); + protein2.setY(100); + Species protein3 = new GenericProtein("4"); model.addElement(protein1); model.addElement(protein2); @@ -61,10 +64,10 @@ public class ReactionToXmlTest extends CellDesignerTestFunctions { reaction.addReactant(reactant); reaction.addProduct(product); - Modifier modifier = new Catalysis(protein1); + Modifier modifier = new Catalysis(protein3); modifier.setLine(new PolylineData(new Point2D.Double(), new Point2D.Double(30, 0))); - Modifier modifier2 = new Catalysis(protein1); + Modifier modifier2 = new Catalysis(protein3); List<Point2D> points = new ArrayList<>(); points.add(new Point2D.Double(0, 0)); points.add(new Point2D.Double(30, 30)); @@ -101,6 +104,7 @@ public class ReactionToXmlTest extends CellDesignerTestFunctions { Model model = new ModelFullIndexed(null); Species protein1 = new GenericProtein("2"); + protein1.setX(100); Species protein2 = new GenericProtein("3"); model.addElement(protein1); @@ -249,10 +253,18 @@ public class ReactionToXmlTest extends CellDesignerTestFunctions { @Test public void testGetEditPointsXmlStringForSimpleReaction() { Reaction r = new TriggerReaction(); - Product product = new Product(); + Species productSpecies = new GenericProtein("id1"); + productSpecies.setX(20); + productSpecies.setY(20); + productSpecies.setWidth(20); + productSpecies.setHeight(20); + Product product = new Product(productSpecies); PolylineData productLine = new PolylineData(new Point2D.Double(10, 10), new Point2D.Double(20, 20)); product.setLine(productLine); - Reactant reactant = new Reactant(); + Species reactantSpecies = new GenericProtein("id1"); + reactantSpecies.setWidth(10); + reactantSpecies.setHeight(10); + Reactant reactant = new Reactant(reactantSpecies); PolylineData reactantLine = new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(10, 10)); reactant.setLine(reactantLine); r.addProduct(product); @@ -264,10 +276,18 @@ public class ReactionToXmlTest extends CellDesignerTestFunctions { @Test public void testGetEditPointsXmlStringForSimpleReactionWhenNotImportedFromCD() { Reaction r = new TriggerReaction(); - Product product = new Product(); + Species productSpecies = new GenericProtein("id1"); + productSpecies.setX(20); + productSpecies.setY(20); + productSpecies.setWidth(20); + productSpecies.setHeight(20); + Product product = new Product(productSpecies); PolylineData productLine = new PolylineData(new Point2D.Double(10, 10), new Point2D.Double(20, 10)); product.setLine(productLine); - Reactant reactant = new Reactant(); + Species reactantSpecies = new GenericProtein("id1"); + reactantSpecies.setWidth(10); + reactantSpecies.setHeight(10); + Reactant reactant = new Reactant(reactantSpecies); PolylineData reactantLine = new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(10, 10)); reactant.setLine(reactantLine); r.addProduct(product);