Commit 81edecf2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1299-html-tags-in-gpml-comments' into 'devel_15.0.x'

Resolve "hyperlink in NOTES is exported (as gpml) in the Comment, cannot open file in pathvisio"

See merge request !1205
parents 299479fd 738c028e
Pipeline #29085 passed with stage
in 17 minutes and 48 seconds
minerva (15.0.2) stable; urgency=medium
* Bug fix: annotations using identifiers.org urls sometimes required http and
sometimes required https url (#1297)
* Bug fix: map notes were not exported to GPML
* Bug fix: reaction notes were not imported from GPML
* Bug fix: export of notes could create invalid GPML file (#1299)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 29 Jun 2020 11:00:00 +0200
......
......@@ -131,12 +131,16 @@ public class ModelContructor {
species.setHypothetical(true);
}
species.setName(dataNode.getName());
StringBuilder notes = new StringBuilder();
species.setNotes(getComments(dataNode));
return species;
}
private String getComments(PathwayElement dataNode) {
StringBuilder notes = new StringBuilder("");
for (String comment : dataNode.getComments()) {
notes.append(comment + "\n\n");
}
species.setNotes(notes.toString());
return species;
return notes.toString();
}
/**
......@@ -197,7 +201,7 @@ public class ModelContructor {
protected void addElement(Model model, Graph graph, Data data) {
for (DataNode dataNode : graph.getDataNodes()) {
Species species = createSpecies(dataNode);
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), dataNode.getBiopaxReference()));
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), dataNode.getBiopaxReferences()));
Element alias = updateAlias(dataNode, species);
......@@ -207,7 +211,7 @@ public class ModelContructor {
for (Label label : graph.getLabels()) {
if (label.isTreatAsNode()) {
Species species = createSpecies(label);
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), label.getBiopaxReference()));
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), label.getBiopaxReferences()));
Element alias = updateAlias(label, species);
......@@ -221,7 +225,7 @@ public class ModelContructor {
for (Shape shape : graph.getShapes()) {
if (shape.isTreatAsNode()) {
Species species = createSpecies(shape);
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), shape.getBiopaxReference()));
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), shape.getBiopaxReferences()));
Element alias = updateAlias(shape, species);
......@@ -671,6 +675,8 @@ public class ModelContructor {
reaction.setReversible(true);
}
}
reaction.setNotes(getComments(interaction));
reaction.addMiriamData(interaction.getReferences());
reaction.setZ(interaction.getzOrder());
......
......@@ -7,6 +7,7 @@ import java.awt.geom.*;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -338,7 +339,7 @@ public class ModelToGPML {
String shape = ShapeMapping.getShape(ca.getClass()).getStringRepresentation();
comparments.append(" <Shape TextLabel=\"" + ca.getName() + "\" GraphId=\"" + ca.getElementId() + "\">\n");
comparments.append(" <Comment>" + getAllNames(ca) + "</Comment>\n");
comparments.append(" <Comment>" + StringEscapeUtils.escapeXml11(getAllNames(ca)) + "</Comment>\n");
comparments.append(" <Attribute Key=\"org.pathvisio.CellularComponentProperty\" Value=\"Cell\" />\n");
comparments.append(" <Attribute Key=\"org.pathvisio.DoubleLineProperty\" Value=\"Double\" />\n");
comparments.append(
......@@ -531,7 +532,7 @@ public class ModelToGPML {
}
result.append(">\n");
result.append(" <Comment>" + species.getNotes().trim() + "</Comment>\n");
result.append(" <Comment>" + StringEscapeUtils.escapeXml11(species.getNotes().trim()) + "</Comment>\n");
result.append(biopaxParser.toReferenceXml(species.getMiriamData()));
Rectangle2D rec = species.getBorder();
......@@ -564,7 +565,7 @@ public class ModelToGPML {
}
result.append(">\n");
result.append(" <Comment>" + species.getNotes().trim() + "</Comment>\n");
result.append(" <Comment>" + StringEscapeUtils.escapeXml11(species.getNotes().trim()) + "</Comment>\n");
Rectangle2D rec = species.getBorder();
......@@ -607,7 +608,7 @@ public class ModelToGPML {
}
result.append(">\n");
result.append(" <Comment>" + species.getNotes() + "</Comment>\n");
result.append(" <Comment>" + StringEscapeUtils.escapeXml11(species.getNotes().trim()) + "</Comment>\n");
result.append(biopaxParser.toReferenceXml(species.getMiriamData()));
Rectangle2D rec = species.getBorder();
......@@ -721,6 +722,9 @@ public class ModelToGPML {
interactions.append(" <Interaction GraphId=\"" + reaction.getIdReaction() + "\">\n");
interactions.append(biopaxParser.toReferenceXml(reaction.getMiriamData()));
if (reaction.getNotes() != null) {
interactions.append(" <Comment>" + StringEscapeUtils.escapeXml11(reaction.getNotes().trim()) + "</Comment>\n");
}
interactions.append(" <Graphics "
+ "ConnectorType=\"Segmented\" "
+ "ZOrder=\"" + reaction.getZ() + "\" "
......@@ -730,6 +734,8 @@ public class ModelToGPML {
}
interactions.append("LineThickness=\"" + reaction.getLine().getWidth() + "\">\n");
/** Start and End **/
Reactant start = reaction.getReactants().get(0);
Product end = reaction.getProducts().get(0);
......@@ -805,6 +811,9 @@ public class ModelToGPML {
StringBuilder gpml = new StringBuilder("");
gpml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
gpml.append("<Pathway xmlns=\"http://pathvisio.org/GPML/2013a\" Name=\"Generated\">\n");
if (model.getNotes() != null) {
gpml.append(" <Comment>" + StringEscapeUtils.escapeXml11(model.getNotes().trim()) + "</Comment>\n");
}
gpml.append(" <Graphics BoardWidth=\"" + model.getWidth() + "\" BoardHeight=\"" + model.getHeight() + "\"/>\n");
gpml.append(getDataNodes(model));
......
package lcsb.mapviewer.wikipathway.model;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.MiriamData;
......@@ -16,7 +18,7 @@ import lcsb.mapviewer.model.map.MiriamData;
* @author Jan Badura
*
*/
public class Interaction implements Serializable {
public class Interaction extends PathwayElement implements Serializable {
static Logger logger = LogManager.getLogger();
/**
......@@ -24,11 +26,6 @@ public class Interaction implements Serializable {
*/
private static final long serialVersionUID = 1L;
/**
* Identifier in GPML model.
*/
private String graphId;
/**
* Where this {@link Interaction} starts (in which {@link Edge}/
* {@link Interaction}).
......@@ -46,11 +43,6 @@ public class Interaction implements Serializable {
*/
private PolylineData line;
/**
* Z order of the {@link Interaction} (how far it should be located in the z
* coordinate).
*/
private Integer zOrder;
/**
* Gpml interaction type (arrow).
......@@ -62,10 +54,6 @@ public class Interaction implements Serializable {
*/
private Set<String> anchors;
/**
* Comments.
*/
private List<String> comments = new ArrayList<>();
/**
* List of edges representing reactants in interaction.
......@@ -82,11 +70,6 @@ public class Interaction implements Serializable {
*/
private Set<Edge> modifiers = new HashSet<>();
/**
* Identifiers of BioPax references.
*/
private Set<String> biopaxReferences = new HashSet<>();
/**
* References for given edge.
*/
......@@ -101,7 +84,7 @@ public class Interaction implements Serializable {
* object will be created from this {@link Edge}
*/
public Interaction(Edge edge) {
graphId = edge.getGraphId();
super(edge.getGraphId(), null);
setStart(edge.getStart());
setEnd(edge.getEnd());
setLine(edge.getLine());
......@@ -111,8 +94,8 @@ public class Interaction implements Serializable {
addReference(new MiriamData(md));
}
setColor(edge.getColor());
this.comments.addAll(edge.getComments());
biopaxReferences.addAll(edge.getBiopaxReferences());
addComments(edge.getComments());
addBiopaxReferences(edge.getBiopaxReferences());
reversible = edge.isReversibleReaction();
}
......@@ -133,23 +116,6 @@ public class Interaction implements Serializable {
references.add(reference);
}
/**
* @return the graphId
* @see #graphId
*/
public String getGraphId() {
return graphId;
}
/**
* @param graphId
* the graphId to set
* @see #graphId
*/
public void setGraphId(String graphId) {
this.graphId = graphId;
}
/**
* @return the start
* @see #start
......@@ -218,23 +184,6 @@ public class Interaction implements Serializable {
this.anchors = anchors;
}
/**
* @return the comment
* @see #comment
*/
public List<String> getComments() {
return comments;
}
/**
* @param comment
* the comment to set
* @see #comment
*/
public void addComment(String comment) {
this.comments.add(comment);
}
/**
* @return the reactants
* @see #reactants
......@@ -267,7 +216,7 @@ public class Interaction implements Serializable {
*/
public void addProduct(Edge interaction) {
this.products.add(interaction);
biopaxReferences.addAll(interaction.getBiopaxReferences());
addBiopaxReferences(interaction.getBiopaxReferences());
}
/**
......@@ -278,7 +227,7 @@ public class Interaction implements Serializable {
*/
public void addModifier(Edge interaction) {
this.modifiers.add(interaction);
biopaxReferences.addAll(interaction.getBiopaxReferences());
addBiopaxReferences(interaction.getBiopaxReferences());
}
/**
......@@ -289,24 +238,7 @@ public class Interaction implements Serializable {
*/
public void addReactant(Edge interaction) {
this.reactants.add(interaction);
biopaxReferences.addAll(interaction.getBiopaxReferences());
}
/**
* @return the biopaxReferences
* @see #biopaxReferences
*/
public Set<String> getBiopaxReferences() {
return biopaxReferences;
}
/**
* @param biopaxReferences
* the biopaxReferences to set
* @see #biopaxReferences
*/
public void setBiopaxReferences(Set<String> biopaxReferences) {
this.biopaxReferences = biopaxReferences;
addBiopaxReferences(interaction.getBiopaxReferences());
}
/**
......@@ -371,23 +303,6 @@ public class Interaction implements Serializable {
}
}
/**
* @return the zOrder
* @see #zOrder
*/
public Integer getzOrder() {
return zOrder;
}
/**
* @param zOrder
* the zOrder to set
* @see #zOrder
*/
public void setzOrder(Integer zOrder) {
this.zOrder = zOrder;
}
public boolean isReversible() {
return reversible;
}
......@@ -396,4 +311,14 @@ public class Interaction implements Serializable {
this.reversible = reversible;
}
@Override
String getName() {
throw new NotImplementedException();
}
@Override
Rectangle2D getRectangle() {
throw new NotImplementedException();
}
}
......@@ -2,8 +2,7 @@ package lcsb.mapviewer.wikipathway.model;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
......@@ -104,7 +103,7 @@ public abstract class PathwayElement implements Serializable {
* @return the biopaxReference
* @see #biopaxReference
*/
public List<String> getBiopaxReference() {
public List<String> getBiopaxReferences() {
return biopaxReferences;
}
......@@ -113,7 +112,7 @@ public abstract class PathwayElement implements Serializable {
* the biopaxReference to set
* @see #biopaxReference
*/
public void setBiopaxReference(List<String> biopaxReferences) {
public void setBiopaxReferences(List<String> biopaxReferences) {
this.biopaxReferences = biopaxReferences;
}
......@@ -143,6 +142,10 @@ public abstract class PathwayElement implements Serializable {
public void addBiopaxReference(String biopaxString) {
biopaxReferences.add(biopaxString);
}
public void addBiopaxReferences(Collection<String> biopaxStrings) {
biopaxReferences.addAll(biopaxStrings);
}
/**
* @return the comments
......@@ -161,6 +164,10 @@ public abstract class PathwayElement implements Serializable {
this.comments.add(comment);
}
public void addComments(Collection<String> comments) {
this.comments.addAll(comments);
}
public String getMapName() {
return mapName;
}
......
......@@ -33,8 +33,8 @@ public class DataNodeParserTest extends WikipathwaysTestFunctions {
assertNotNull(dataNode);
assertEquals("GeneProduct", dataNode.getTextLabel());
assertEquals("ab30b", dataNode.getGraphId());
assertEquals(1, dataNode.getBiopaxReference().size());
assertEquals("aea", dataNode.getBiopaxReference().get(0));
assertEquals(1, dataNode.getBiopaxReferences().size());
assertEquals("aea", dataNode.getBiopaxReferences().get(0));
assertEquals(1, dataNode.getReferences().size());
assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"), dataNode.getReferences().get(0));
......
......@@ -29,8 +29,8 @@ public class LabelParserTest extends WikipathwaysTestFunctions {
assertEquals("Label 2", label.getTextLabel());
assertEquals("edf06", label.getGraphId());
assertEquals(2, label.getBiopaxReference().size());
assertEquals("b38", label.getBiopaxReference().get(1));
assertEquals(2, label.getBiopaxReferences().size());
assertEquals("b38", label.getBiopaxReferences().get(1));
assertEquals((Integer) 28672, label.getzOrder());
assertEquals((Double) 10.0, label.getFontSize());
......
......@@ -22,6 +22,7 @@ import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction;
import lcsb.mapviewer.model.map.reaction.type.TransportReaction;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.field.ModificationState;
......@@ -200,8 +201,8 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
assertEquals(reaction.isReversible(), newReaction.isReversible());
}
private Reaction createReaction(Protein p1, Protein p2) {
Reaction reaction = new TransportReaction("re" + (speciesCounter++));
private Reaction createReaction(Species p1, Species p2) {
Reaction reaction = new StateTransitionReaction("re" + (speciesCounter++));
Reactant reactant = new Reactant(p1);
Product product = new Product(p2);
reaction.addReactant(reactant);
......@@ -396,4 +397,47 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
assertEquals(0, new ModelComparator().compare(model, model2));
}
@Test
public void testMapNotes() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
model.setNotes("xyz");
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));
}
@Test
public void testHtmlTagInNotes() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
model.setNotes("a < b");
Species p1 = createProtein();
p1.setNotes("<a href='https://google.lu/'>link</a>");
model.addElement(p1);
Species p2 = createProtein();
model.addElement(p2);
Reaction r= createReaction(p1, p2);
r.setNotes("<xml>tag</xml>");
model.addReaction(r);
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));
}
}
......@@ -47,8 +47,8 @@ public class ShapeParserTest extends WikipathwaysTestFunctions {
assertEquals("dfdfs fds ", shape.getTextLabel());
assertEquals("eb55e", shape.getGraphId());
assertEquals(1, shape.getBiopaxReference().size());
assertEquals("d04", shape.getBiopaxReference().get(0));
assertEquals(1, shape.getBiopaxReferences().size());
assertEquals("d04", shape.getBiopaxReferences().get(0));
assertEquals((Integer) 16384, shape.getzOrder());
assertEquals((Double) 10.0, shape.getFontSize());
......@@ -69,8 +69,8 @@ public class ShapeParserTest extends WikipathwaysTestFunctions {
assertEquals("compartment title", shape.getTextLabel());
assertEquals("c5869", shape.getGraphId());
assertEquals(1, shape.getBiopaxReference().size());
assertEquals("b80", shape.getBiopaxReference().get(0));
assertEquals(1, shape.getBiopaxReferences().size());
assertEquals("b80", shape.getBiopaxReferences().get(0));
assertEquals((Integer) 16384, shape.getzOrder());
assertEquals((Double) 10.0, shape.getFontSize());
......
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