diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParser.java index f5c1c9dff2818c09021a62c4e0a2bee838c0dca6..e77b6de595c06d3355045c3ad8a3a7b2efb93bc6 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParser.java @@ -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(); } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Layer.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Layer.java index d3ca569b69050d4deee73b9e76e1e0a055f552a4..a44fad8785ef94feef83faaeff904759e69110ff 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Layer.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Layer.java @@ -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; + } } diff --git a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GpmlParser.java b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GpmlParser.java index 4c5c2beb9c07291d502c01e27d9cb23fb736f2cd..b19db3ef42d6c7a25daa04921adc7e379f133d2c 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GpmlParser.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GpmlParser.java @@ -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 */ diff --git a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java index 83d50098591ceecf2ee8dcd6a83012c3ce4ca521..f9075260c72c0b7b804f71cac056ad34916098d1 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java @@ -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; diff --git a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelToGPML.java b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelToGPML.java index 5e2c2025253143a039f45df407bd11f28229a8b7..6634a3e9bdbe7c106557479e024a1ca78ef9551f 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelToGPML.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelToGPML.java @@ -44,563 +44,590 @@ import lcsb.mapviewer.wikipathway.utils.Geo; */ public class ModelToGPML { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(ModelToGPML.class); - - /** - * Maximum distance between point and line. ??? - */ - private static final double DIS_FOR_LINE = 3.0; - - /** - * This value define margin of the group border. Rectangle border will be - * resized by this value in every direction. - */ - private static final int GROUP_RECTANGLE_BORDER_MARGIN = 8; - - /** - * First id value used for generating identifiers during conversion. - */ - private static final int INITIAL_ID_VALUE = 10000; - - /** - * Counter used for generating identifiers if identifiers aren't provided by - * the gpml model. - */ - private int idCounter = INITIAL_ID_VALUE; - - /** - * Maximum distance between point and rectangle. ??? - */ - private static final double DIS_FOR_REP = 9.0; - - /** - * Parser used to convert from/to xml {@link MiriamData} annotations. - */ - private ReferenceParser referenceParser = new ReferenceParser(); - - /** - * Parser used to convert from/to xml (in biopax format) {@link MiriamData} - * annotations. - */ - private BiopaxParser biopaxParser = new BiopaxParser(); - - /** - * Returns new unique identifier for the model. - * - * @return new unique identifier for the model - */ - private String getNewId() { - idCounter++; - return "id" + idCounter; - } - - /** - * This function returns gpml Species type based on class. If it can not - * recognize one of (Rna,GeneProduct,Protein,Metabolite) it will throw - * {@link InvalidArgumentException}. - * - * @param species - * species for which gpml type will be returned - * @return String - type - */ - private String getType(Species species) { - String res = ""; - if (species instanceof AntisenseRna) { - res = "Rna"; - } else if (species instanceof Rna) { - res = "Rna"; - } else if (species instanceof Gene) { - res = "GeneProduct"; - } else if (species instanceof Protein) { - res = "Protein"; - } else if (species instanceof SimpleMolecule) { - res = "Metabolite"; - } else if (species instanceof Ion) { - res = "Metabolite"; - } else if (species instanceof Drug) { - res = "Metabolite"; - } else if (species instanceof Phenotype) { - res = "Pathway"; - } else if (species instanceof Unknown) { - res = "Unknown"; - } else if (species instanceof Degraded) { - res = "Unknown"; - } else { - throw new InvalidArgumentException("Unknown class type: " + species.getClass()); - } - - return res; - } - - /** - * Since in pathvisio it is impossible to set the size of group rectangle this - * function calculates new rectangle for complex based on contents of this - * complex. - * - * @param alias - * alias for which rectangle border is calculated - * @return rectangle border for alias - */ - private Rectangle2D getRectangle(Element alias) { - Rectangle2D res = null; - - if (alias instanceof Complex) { - Complex ca = (Complex) alias; - if (ca.getElements().size() == 0) { - res = (Rectangle2D) ca.getBorder().clone(); - } else { - res = getRectangle(ca.getElements().get(0)); - for (Element al : ca.getElements()) { - Rectangle2D.union(res, getRectangle(al), res); - } - res = new Rectangle2D.Double( - res.getX() - GROUP_RECTANGLE_BORDER_MARGIN, res.getY() - GROUP_RECTANGLE_BORDER_MARGIN, res.getWidth() + 2 * GROUP_RECTANGLE_BORDER_MARGIN, - res.getHeight() + 2 * GROUP_RECTANGLE_BORDER_MARGIN); - } - } else if (alias instanceof Species) { - res = (Rectangle2D) alias.getBorder().clone(); - } - return res; - } - - /** - * This function calculates {@link PolylineData} based on start - * {@link Reactant} and end {@link Product}. If end or start points are to far - * away from their rectangles new points are added. - * - * @param start - * reactant from which polyline starts - * @param end - * product where polyline ends - * @return {@link PolylineData} between start and end - */ - private PolylineData getPolyline(Reactant start, Product end) { - PolylineData res = new PolylineData(); - - NodeOperator and = start.getNodeOperatorForInput(); - // NodeOperator split = end.getNodeOperatorForOutput(); - - PolylineData startLine = start.getLine(); - Point2D ps = startLine.getBeginPoint(); - Rectangle2D rec1 = getRectangle(start.getElement()); - double dis1 = Geo.distance(ps, rec1); - - if (dis1 > DIS_FOR_REP) { - res.addPoint(Geo.closestPointOnRectangle(rec1, ps)); - } - for (Point2D p2d : startLine.getPoints()) { - res.addPoint(p2d); - } - if (and != null) { - for (Point2D p2d : and.getLine().getPoints()) { - res.addPoint(p2d); - } - } - - PolylineData endLine = end.getLine(); - Point2D pe = endLine.getEndPoint(); - Rectangle2D rec2 = getRectangle(end.getElement()); - double dis2 = Geo.distance(pe, rec2); - - for (Point2D p2d : endLine.getPoints()) { - res.addPoint(p2d); - } - if (dis2 > DIS_FOR_REP) { - res.addPoint(Geo.closestPointOnRectangle(rec2, pe)); - } - return Geo.removeRedundantPoints(res); - } - - /** - * This function calculates PolylineData based on ReactionNode. - * - * @param rn - * rection node for which polyline is calculated - * @param mainLine - * main line to which polyline is attached - * @return polyline for {@link ReactionNode} - */ - private PolylineData getPolyline(ReactionNode rn, PolylineData mainLine) { - PolylineData res = new PolylineData(); - - PolylineData line = rn.getLine(); - Point2D ps = line.getBeginPoint(); - Point2D pe = line.getEndPoint(); - Rectangle2D rec = getRectangle(rn.getElement()); - - if (rn instanceof Reactant || rn instanceof Modifier) { - double dis = Geo.distance(ps, rec); - double dis2 = Geo.distanceFromPolyline(pe, mainLine); - if (dis > DIS_FOR_REP) { - res.addPoint(Geo.closestPointOnRectangle(rec, ps)); - } - for (Point2D p2d : line.getPoints()) { - res.addPoint(p2d); - } - if (dis2 > DIS_FOR_LINE) { - Point2D tmpPoint = Geo.closestPointOnPolyline(mainLine, pe); - if (tmpPoint != null) { - res.addPoint(tmpPoint); - } - } - } else if (rn instanceof Product) { - double dis = Geo.distance(pe, rec); - double dis2 = Geo.distanceFromPolyline(ps, mainLine); - if (dis2 > DIS_FOR_LINE) { - Point2D tmpPoint = Geo.closestPointOnPolyline(mainLine, ps); - if (tmpPoint != null) { - res.addPoint(tmpPoint); - } - } - for (Point2D p2d : line.getPoints()) { - res.addPoint(p2d); - } - if (dis > DIS_FOR_REP) { - res.addPoint(Geo.closestPointOnRectangle(rec, pe)); - } - } - return Geo.removeRedundantPoints(res); - } - - /** - * This function returns all species names that are in given Compartment. - * - * @param ca - * compartment alias - * @return string with list of species names in a compartment - */ - private String getAllNames(Compartment ca) { - StringBuilder res = new StringBuilder(""); - for (Element a : ca.getAllSubElements()) { - if (a instanceof Species) { - Species sp = (Species) a; - res.append(sp.getName() + ";"); - } - } - return res.toString(); - } - - /** - * This function transform Compartments into Shapes (Oval or Rectangle) from - * PathVisio. LineThickness=3.0 and Color=ffcc66. It can be easily changed. - * - * @param model - * model where compartments are placed - * @return String that encodes all compartments in gpml format - */ - private String getComparments(Model model) { - StringBuilder comparments = new StringBuilder(""); - for (Compartment ca : model.getCompartments()) { - - double x = ca.getCenterX(), y = ca.getCenterY(), h = ca.getHeight(), w = ca.getWidth(); - String shape; - if (ca instanceof OvalCompartment) { - shape = "Oval"; - } else { - shape = "Rectangle"; - } - - comparments.append(" <Shape TextLabel=\"" + ca.getName() + "\" GraphId=\"" + ca.getElementId() + "\">\n"); - comparments.append(" <Comment>" + 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( - " <Graphics CenterX=\"" + x + "\" CenterY=\"" + y + "\" Width=\"" + w + "\" Height=\"" + h - + "\" ZOrder=\"16384\" FontSize=\"20\" Valign=\"Bottom\" ShapeType=\"" + shape - + "\" LineThickness=\"3.0\" Color=\"ffcc66\" Rotation=\"0.0\" />\n"); - comparments.append(" </Shape>\n"); - } - return comparments.toString(); - } - - /** - * This function creates Interaction for other product, reactant or modifier - * from main reaction. This is support function for getInteractions(Model - * model). - * - * @param rn - * object representing rectanat/product/modifier - * @param anchId - * identifier of the anchor where it will be connected - * @param anchors - * string builder where anchors are stored (it will be modified to - * add anchor for this element) - * @param mainLine - * line used for connecting this element - * @return string representing connection of this element to reaction - * @throws ConverterException - * thrown when there is a problem with conversion - */ - private String getInteractionForAnchor(ReactionNode rn, String anchId, StringBuilder anchors, PolylineData mainLine) throws ConverterException { - StringBuilder interaction = new StringBuilder(""); - - PolylineData line = getPolyline(rn, mainLine); - Point2D ps = line.getBeginPoint(); - Point2D pe = line.getEndPoint(); - double anchorPosition = -1; - - interaction.append(" <Interaction GraphId=\"" + getNewId() + "\">\n"); - interaction.append(" <Attribute Key=\"org.pathvisio.core.ds\" Value=\"\"/>\n"); - interaction.append(" <Attribute Key=\"org.pathvisio.core.id\" Value=\"\"/>\n"); - interaction.append(" <Graphics ConnectorType=\"Segmented\" ZOrder=\"32827\" LineThickness=\"1.0\">\n"); - - if (rn instanceof Reactant) { - for (Point2D p2d : line.getPoints()) { - if (p2d.equals(ps)) { - interaction.append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + rn.getElement().getElementId() + "\"/>\n"); - } else if (p2d.equals(pe)) { - interaction.append(" <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + anchId + "\"/>\n"); - } else { - interaction.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); - } - } - } else if (rn instanceof Product) { - for (Point2D p2d : line.getPoints()) { - if (p2d.equals(ps)) { - interaction.append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + anchId + "\"/>\n"); - } else if (p2d.equals(pe)) { - interaction.append( - " <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + rn.getElement().getElementId() - + "\" ArrowHead=\"mim-conversion\"/>\n"); - } else { - interaction.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); - } - } - } else if (rn instanceof Modifier) { - for (Point2D p2d : line.getPoints()) { - if (p2d.equals(ps)) { - interaction.append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + rn.getElement().getElementId() + "\"/>\n"); - } else if (p2d.equals(pe)) { - interaction.append(" <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + anchId + "\" ArrowHead=\"mim-catalysis\"/>\n"); - } else { - interaction.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); - } - } - } - if (rn instanceof Reactant) { - anchorPosition = Geo.distanceOnPolyline(mainLine, pe); - } else if (rn instanceof Product) { - anchorPosition = Geo.distanceOnPolyline(mainLine, ps); - } else if (rn instanceof Modifier) { - anchorPosition = Geo.distanceOnPolyline(mainLine, pe); - } else { - throw new InvalidArgumentException("Invalid class type: " + rn.getClass()); - } - anchors.append(" <Anchor Position=\"" + anchorPosition + "\" Shape=\"None\" GraphId=\"" + anchId + "\"/>\n"); - interaction.append(" </Graphics>\n"); - interaction.append(referenceParser.toXml((MiriamData) null)); - interaction.append(" </Interaction>\n"); - - return interaction.toString(); - } - - /** - * This function encode SpeciesAliases into DataNodes from .gpml format. Empty - * complexes are also transformed into DataNodes. - * - * @param model - * model where aliases are placed - * @return string representing - * {@link lcsb.mapviewer.wikipathway.model.DataNode data nodes} - * @throws ConverterException - * thrown when there is a problem with conversion - */ - protected String getDataNodes(Model model) throws ConverterException { - StringBuilder dataNodes = new StringBuilder(""); - - for (Species sa : model.getNotComplexSpeciesList()) { - if (!(sa instanceof Complex)) { - dataNodes.append(" <DataNode TextLabel=\"" + sa.getName() + "\" GraphId=\"" + sa.getElementId() + "\" Type=\"" + getType(sa) + "\""); - if (sa.getComplex() != null) { - dataNodes.append(" GroupRef=\"" + sa.getComplex().getElementId() + "\""); - } - dataNodes.append(">\n"); - - dataNodes.append(" <Comment>" + sa.getNotes() + "</Comment>\n"); - dataNodes.append(biopaxParser.toReferenceXml(sa.getMiriamData())); - - String red = Integer.toHexString(sa.getColor().getRed()); - String green = Integer.toHexString(sa.getColor().getGreen()); - String blue = Integer.toHexString(sa.getColor().getBlue()); - if (red.length() == 1) { - red = "0" + red; - } - if (green.length() == 1) { - green = "0" + green; - } - if (blue.length() == 1) { - blue = "0" + blue; - } - String color = red + green + blue; - Rectangle2D rec = sa.getBorder(); - - dataNodes.append( - " <Graphics CenterX=\"" + rec.getCenterX() + "\" CenterY=\"" + rec.getCenterY() + "\" Width=\"" + rec.getWidth() + "\" Height=\"" - + rec.getHeight() + "\" ZOrder=\"32883\" FontSize=\"10\" Valign=\"Middle\" Color=\"" + "0000ff" + "\" FillColor=\"" + color + "\"/>\n"); - - dataNodes.append(referenceParser.toXml(sa.getMiriamData())); - dataNodes.append(" </DataNode>\n"); - } - } - - /** Special Case for empty Complexes **/ - for (Complex ca : model.getComplexList()) { - if (ca.getElements().size() == 0) { - dataNodes.append(" <DataNode TextLabel=\"" + ca.getName() + "\" GraphId=\"" + ca.getElementId() + "\" Type=\"Complex\""); - if (ca.getComplex() != null) { - dataNodes.append(" GroupRef=\"" + ca.getComplex().getElementId() + "\""); - } - dataNodes.append(">\n"); - - dataNodes.append(biopaxParser.toReferenceXml(ca.getMiriamData())); - Rectangle2D rec = ca.getBorder(); - - dataNodes.append( - " <Graphics CenterX=\"" + rec.getCenterX() + "\" CenterY=\"" + rec.getCenterY() + "\" Width=\"" + rec.getWidth() + "\" Height=\"" - + rec.getHeight() + "\" ZOrder=\"32883\" FontSize=\"10\" Valign=\"Middle\" Color=\"0000ff\" FillColor=\"ffffcc\" LineStyle=\"Broken\"/>\n"); - - dataNodes.append(referenceParser.toXml(ca.getMiriamData())); - dataNodes.append(" </DataNode>\n"); - } - } - - return dataNodes.toString(); - } - - /** - * This function encode ComplexAliases into Groups from .gpml format. - * - * @param model - * model where aliases are placed - * @return string representing groups in gpml format - */ - protected String getGroups(Model model) { - StringBuilder groups = new StringBuilder(""); - - for (Complex ca : model.getComplexList()) { - if (ca.getElements().size() > 0) { - groups.append(" <Group GroupId=\"" + ca.getElementId() + "\" GraphId=\"" + ca.getElementId() + "\""); - if (ca.getComplex() != null) { - groups.append(" GroupRef=\"" + ca.getComplex().getElementId() + "\""); - } - groups.append("/>\n"); - } - } - return groups.toString(); - } - - /** - * This function encode Reactions into Interactions from .gpml format. - * - * @param model - * model where reactions are placed - * @return string with interactions in gpml format - * @throws ConverterException - * thrown when there is a problem with conversion - */ - protected String getInteractions(Model model) throws ConverterException { - StringBuilder interactions = new StringBuilder(""); - for (Reaction reaction : model.getReactions()) { - - StringBuilder anchors = new StringBuilder(""); - StringBuilder tmp = new StringBuilder(""); - - interactions.append(" <Interaction GraphId=\"" + reaction.getIdReaction() + "\">\n"); - interactions.append(biopaxParser.toReferenceXml(reaction.getMiriamData())); - // interactions.append(" <Attribute Key=\"org.pathvisio.core.ds\" - // Value=\"\"/>\n"); - // interactions.append(" <Attribute Key=\"org.pathvisio.core.id\" - // Value=\"\"/>\n"); - interactions.append(" <Graphics ConnectorType=\"Segmented\" ZOrder=\"32827\" LineThickness=\"1.0\">\n"); - - /** Start and End **/ - Reactant start = reaction.getReactants().get(0); - Product end = reaction.getProducts().get(0); - - PolylineData line = getPolyline(start, end); - Point2D ps = line.getBeginPoint(); - Point2D pe = line.getEndPoint(); - String sid = start.getElement().getElementId(); - String eid = end.getElement().getElementId(); - - for (Point2D p2d : line.getPoints()) { - if (p2d.equals(ps)) { - interactions.append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + sid + "\"/>\n"); - } else if (p2d.equals(pe)) { - interactions.append(" <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + eid + "\" ArrowHead=\"mim-conversion\"/>\n"); - } else { - interactions.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); - } - } - /** Reactants **/ - boolean first = true; - for (Reactant reactant : reaction.getReactants()) { - if (first) { - first = false; - } else { - tmp.append(getInteractionForAnchor(reactant, getNewId(), anchors, line)); - } - } - /** Products **/ - first = true; - for (Product product : reaction.getProducts()) { - if (first) { - first = false; - } else { - tmp.append(getInteractionForAnchor(product, getNewId(), anchors, line)); - } - } - /** Modifiers **/ - for (Modifier modifier : reaction.getModifiers()) { - tmp.append(getInteractionForAnchor(modifier, getNewId(), anchors, line)); - } - - interactions.append(anchors.toString()); - interactions.append(" </Graphics>\n"); - interactions.append(referenceParser.toXml(reaction.getMiriamData())); - interactions.append(" </Interaction>\n"); - interactions.append(tmp.toString()); - } - - return interactions.toString(); - } - - /** - * This function returns Model in .gpml format. - * - * @param model - * model to transform - * @return string in gpml format representing model - * @throws ConverterException - * thrown when there is a problem with conversion - */ - public String getGPML(Model model) throws ConverterException { - - 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"); - gpml.append(" <Graphics BoardWidth=\"" + model.getWidth() + "\" BoardHeight=\"" + model.getHeight() + "\"/>\n"); - - gpml.append(getDataNodes(model)); - String groups = getGroups(model); - gpml.append(getInteractions(model)); - gpml.append(getComparments(model)); - gpml.append(groups); - Set<MiriamData> set = new HashSet<>(); - for (BioEntity element : model.getBioEntities()) { - set.addAll(element.getMiriamData()); - } - - // the order here is important... - gpml.append(" <InfoBox CenterX=\"0.0\" CenterY=\"0.0\"/>\n"); - gpml.append(biopaxParser.toXml(set)); - - gpml.append("</Pathway>"); - - return gpml.toString(); - } + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private final Logger logger = Logger.getLogger(ModelToGPML.class); + + /** + * Maximum distance between point and line. ??? + */ + private static final double DIS_FOR_LINE = 3.0; + + /** + * This value define margin of the group border. Rectangle border will be + * resized by this value in every direction. + */ + private static final int GROUP_RECTANGLE_BORDER_MARGIN = 8; + + /** + * First id value used for generating identifiers during conversion. + */ + private static final int INITIAL_ID_VALUE = 10000; + + /** + * Counter used for generating identifiers if identifiers aren't provided by the + * gpml model. + */ + private int idCounter = INITIAL_ID_VALUE; + + /** + * Maximum distance between point and rectangle. ??? + */ + private static final double DIS_FOR_REP = 9.0; + + /** + * Parser used to convert from/to xml {@link MiriamData} annotations. + */ + private ReferenceParser referenceParser = new ReferenceParser(); + + /** + * Parser used to convert from/to xml (in biopax format) {@link MiriamData} + * annotations. + */ + private BiopaxParser biopaxParser = new BiopaxParser(); + + /** + * Returns new unique identifier for the model. + * + * @return new unique identifier for the model + */ + private String getNewId() { + idCounter++; + return "id" + idCounter; + } + + /** + * This function returns gpml Species type based on class. If it can not + * recognize one of (Rna,GeneProduct,Protein,Metabolite) it will throw + * {@link InvalidArgumentException}. + * + * @param species + * species for which gpml type will be returned + * @return String - type + */ + private String getType(Species species) { + String res = ""; + if (species instanceof AntisenseRna) { + res = "Rna"; + } else if (species instanceof Rna) { + res = "Rna"; + } else if (species instanceof Gene) { + res = "GeneProduct"; + } else if (species instanceof Protein) { + res = "Protein"; + } else if (species instanceof SimpleMolecule) { + res = "Metabolite"; + } else if (species instanceof Ion) { + res = "Metabolite"; + } else if (species instanceof Drug) { + res = "Metabolite"; + } else if (species instanceof Phenotype) { + res = "Pathway"; + } else if (species instanceof Unknown) { + res = "Unknown"; + } else if (species instanceof Degraded) { + res = "Unknown"; + } else { + throw new InvalidArgumentException("Unknown class type: " + species.getClass()); + } + + return res; + } + + /** + * Since in pathvisio it is impossible to set the size of group rectangle this + * function calculates new rectangle for complex based on contents of this + * complex. + * + * @param alias + * alias for which rectangle border is calculated + * @return rectangle border for alias + */ + private Rectangle2D getRectangle(Element alias) { + Rectangle2D res = null; + + if (alias instanceof Complex) { + Complex ca = (Complex) alias; + if (ca.getElements().size() == 0) { + res = (Rectangle2D) ca.getBorder().clone(); + } else { + res = getRectangle(ca.getElements().get(0)); + for (Element al : ca.getElements()) { + Rectangle2D.union(res, getRectangle(al), res); + } + res = new Rectangle2D.Double( + res.getX() - GROUP_RECTANGLE_BORDER_MARGIN, res.getY() - GROUP_RECTANGLE_BORDER_MARGIN, + res.getWidth() + 2 * GROUP_RECTANGLE_BORDER_MARGIN, + res.getHeight() + 2 * GROUP_RECTANGLE_BORDER_MARGIN); + } + } else if (alias instanceof Species) { + res = (Rectangle2D) alias.getBorder().clone(); + } + return res; + } + + /** + * This function calculates {@link PolylineData} based on start {@link Reactant} + * and end {@link Product}. If end or start points are to far away from their + * rectangles new points are added. + * + * @param start + * reactant from which polyline starts + * @param end + * product where polyline ends + * @return {@link PolylineData} between start and end + */ + private PolylineData getPolyline(Reactant start, Product end) { + PolylineData res = new PolylineData(); + + NodeOperator and = start.getNodeOperatorForInput(); + // NodeOperator split = end.getNodeOperatorForOutput(); + + PolylineData startLine = start.getLine(); + Point2D ps = startLine.getBeginPoint(); + Rectangle2D rec1 = getRectangle(start.getElement()); + double dis1 = Geo.distance(ps, rec1); + + if (dis1 > DIS_FOR_REP) { + res.addPoint(Geo.closestPointOnRectangle(rec1, ps)); + } + for (Point2D p2d : startLine.getPoints()) { + res.addPoint(p2d); + } + if (and != null) { + for (Point2D p2d : and.getLine().getPoints()) { + res.addPoint(p2d); + } + } + + PolylineData endLine = end.getLine(); + Point2D pe = endLine.getEndPoint(); + Rectangle2D rec2 = getRectangle(end.getElement()); + double dis2 = Geo.distance(pe, rec2); + + for (Point2D p2d : endLine.getPoints()) { + res.addPoint(p2d); + } + if (dis2 > DIS_FOR_REP) { + res.addPoint(Geo.closestPointOnRectangle(rec2, pe)); + } + return Geo.removeRedundantPoints(res); + } + + /** + * This function calculates PolylineData based on ReactionNode. + * + * @param rn + * rection node for which polyline is calculated + * @param mainLine + * main line to which polyline is attached + * @return polyline for {@link ReactionNode} + */ + private PolylineData getPolyline(ReactionNode rn, PolylineData mainLine) { + PolylineData res = new PolylineData(); + + PolylineData line = rn.getLine(); + Point2D ps = line.getBeginPoint(); + Point2D pe = line.getEndPoint(); + Rectangle2D rec = getRectangle(rn.getElement()); + + if (rn instanceof Reactant || rn instanceof Modifier) { + double dis = Geo.distance(ps, rec); + double dis2 = Geo.distanceFromPolyline(pe, mainLine); + if (dis > DIS_FOR_REP) { + res.addPoint(Geo.closestPointOnRectangle(rec, ps)); + } + for (Point2D p2d : line.getPoints()) { + res.addPoint(p2d); + } + if (dis2 > DIS_FOR_LINE) { + Point2D tmpPoint = Geo.closestPointOnPolyline(mainLine, pe); + if (tmpPoint != null) { + res.addPoint(tmpPoint); + } + } + } else if (rn instanceof Product) { + double dis = Geo.distance(pe, rec); + double dis2 = Geo.distanceFromPolyline(ps, mainLine); + if (dis2 > DIS_FOR_LINE) { + Point2D tmpPoint = Geo.closestPointOnPolyline(mainLine, ps); + if (tmpPoint != null) { + res.addPoint(tmpPoint); + } + } + for (Point2D p2d : line.getPoints()) { + res.addPoint(p2d); + } + if (dis > DIS_FOR_REP) { + res.addPoint(Geo.closestPointOnRectangle(rec, pe)); + } + } + return Geo.removeRedundantPoints(res); + } + + /** + * This function returns all species names that are in given Compartment. + * + * @param ca + * compartment alias + * @return string with list of species names in a compartment + */ + private String getAllNames(Compartment ca) { + StringBuilder res = new StringBuilder(""); + for (Element a : ca.getAllSubElements()) { + if (a instanceof Species) { + Species sp = (Species) a; + res.append(sp.getName() + ";"); + } + } + return res.toString(); + } + + /** + * This function transform Compartments into Shapes (Oval or Rectangle) from + * PathVisio. LineThickness=3.0 and Color=ffcc66. It can be easily changed. + * + * @param model + * model where compartments are placed + * @return String that encodes all compartments in gpml format + */ + private String getComparments(Model model) { + StringBuilder comparments = new StringBuilder(""); + for (Compartment ca : model.getCompartments()) { + + double x = ca.getCenterX(), y = ca.getCenterY(), h = ca.getHeight(), w = ca.getWidth(); + String shape; + if (ca instanceof OvalCompartment) { + shape = "Oval"; + } else { + shape = "Rectangle"; + } + + comparments.append(" <Shape TextLabel=\"" + ca.getName() + "\" GraphId=\"" + ca.getElementId() + "\">\n"); + comparments.append(" <Comment>" + 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( + " <Graphics CenterX=\"" + x + "\" CenterY=\"" + y + "\" Width=\"" + w + "\" Height=\"" + h + + "\" ZOrder=\"" + ca.getZ() + "\" FontSize=\"20\" Valign=\"Bottom\" ShapeType=\"" + shape + + "\" LineThickness=\"3.0\" Color=\"ffcc66\" Rotation=\"0.0\" />\n"); + comparments.append(" </Shape>\n"); + } + return comparments.toString(); + } + + /** + * This function creates Interaction for other product, reactant or modifier + * from main reaction. This is support function for getInteractions(Model + * model). + * + * @param rn + * object representing rectanat/product/modifier + * @param anchId + * identifier of the anchor where it will be connected + * @param anchors + * string builder where anchors are stored (it will be modified to add + * anchor for this element) + * @param mainLine + * line used for connecting this element + * @return string representing connection of this element to reaction + * @throws ConverterException + * thrown when there is a problem with conversion + */ + private String getInteractionForAnchor(ReactionNode rn, String anchId, StringBuilder anchors, PolylineData mainLine) + throws ConverterException { + StringBuilder interaction = new StringBuilder(""); + + PolylineData line = getPolyline(rn, mainLine); + Point2D ps = line.getBeginPoint(); + Point2D pe = line.getEndPoint(); + double anchorPosition = -1; + + interaction.append(" <Interaction GraphId=\"" + getNewId() + "\">\n"); + interaction.append(" <Attribute Key=\"org.pathvisio.core.ds\" Value=\"\"/>\n"); + interaction.append(" <Attribute Key=\"org.pathvisio.core.id\" Value=\"\"/>\n"); + interaction.append(" <Graphics ConnectorType=\"Segmented\" ZOrder=\"32827\" LineThickness=\"1.0\">\n"); + + if (rn instanceof Reactant) { + for (Point2D p2d : line.getPoints()) { + if (p2d.equals(ps)) { + interaction.append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + + rn.getElement().getElementId() + "\"/>\n"); + } else if (p2d.equals(pe)) { + interaction + .append(" <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + anchId + "\"/>\n"); + } else { + interaction.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); + } + } + } else if (rn instanceof Product) { + for (Point2D p2d : line.getPoints()) { + if (p2d.equals(ps)) { + interaction + .append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + anchId + "\"/>\n"); + } else if (p2d.equals(pe)) { + interaction.append( + " <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + + rn.getElement().getElementId() + + "\" ArrowHead=\"mim-conversion\"/>\n"); + } else { + interaction.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); + } + } + } else if (rn instanceof Modifier) { + for (Point2D p2d : line.getPoints()) { + if (p2d.equals(ps)) { + interaction.append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + + rn.getElement().getElementId() + "\"/>\n"); + } else if (p2d.equals(pe)) { + interaction.append(" <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + anchId + + "\" ArrowHead=\"mim-catalysis\"/>\n"); + } else { + interaction.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); + } + } + } + if (rn instanceof Reactant) { + anchorPosition = Geo.distanceOnPolyline(mainLine, pe); + } else if (rn instanceof Product) { + anchorPosition = Geo.distanceOnPolyline(mainLine, ps); + } else if (rn instanceof Modifier) { + anchorPosition = Geo.distanceOnPolyline(mainLine, pe); + } else { + throw new InvalidArgumentException("Invalid class type: " + rn.getClass()); + } + anchors.append(" <Anchor Position=\"" + anchorPosition + "\" Shape=\"None\" GraphId=\"" + anchId + "\"/>\n"); + interaction.append(" </Graphics>\n"); + interaction.append(referenceParser.toXml((MiriamData) null)); + interaction.append(" </Interaction>\n"); + + return interaction.toString(); + } + + /** + * This function encode SpeciesAliases into DataNodes from .gpml format. Empty + * complexes are also transformed into DataNodes. + * + * @param model + * model where aliases are placed + * @return string representing {@link lcsb.mapviewer.wikipathway.model.DataNode + * data nodes} + * @throws ConverterException + * thrown when there is a problem with conversion + */ + protected String getDataNodes(Model model) throws ConverterException { + StringBuilder dataNodes = new StringBuilder(""); + + for (Species sa : model.getNotComplexSpeciesList()) { + if (!(sa instanceof Complex)) { + dataNodes.append(" <DataNode TextLabel=\"" + sa.getName() + "\" GraphId=\"" + sa.getElementId() + "\" Type=\"" + + getType(sa) + "\""); + if (sa.getComplex() != null) { + dataNodes.append(" GroupRef=\"" + sa.getComplex().getElementId() + "\""); + } + dataNodes.append(">\n"); + + dataNodes.append(" <Comment>" + sa.getNotes() + "</Comment>\n"); + dataNodes.append(biopaxParser.toReferenceXml(sa.getMiriamData())); + + String red = Integer.toHexString(sa.getColor().getRed()); + String green = Integer.toHexString(sa.getColor().getGreen()); + String blue = Integer.toHexString(sa.getColor().getBlue()); + if (red.length() == 1) { + red = "0" + red; + } + if (green.length() == 1) { + green = "0" + green; + } + if (blue.length() == 1) { + blue = "0" + blue; + } + String color = red + green + blue; + Rectangle2D rec = sa.getBorder(); + + dataNodes.append( + " <Graphics CenterX=\"" + rec.getCenterX() + + "\" CenterY=\"" + rec.getCenterY() + + "\" Width=\"" + rec.getWidth() + + "\" Height=\"" + rec.getHeight() + + "\" ZOrder=\"" + sa.getZ() + + "\" FontSize=\"10\"" + + " Valign=\"Middle\" " + + "Color=\"" + "0000ff" + + "\" FillColor=\"" + color + "\"/>\n"); + + dataNodes.append(referenceParser.toXml(sa.getMiriamData())); + dataNodes.append(" </DataNode>\n"); + } + } + + /** Special Case for empty Complexes **/ + for (Complex ca : model.getComplexList()) { + if (ca.getElements().size() == 0) { + dataNodes.append( + " <DataNode TextLabel=\"" + ca.getName() + "\" GraphId=\"" + ca.getElementId() + "\" Type=\"Complex\""); + if (ca.getComplex() != null) { + dataNodes.append(" GroupRef=\"" + ca.getComplex().getElementId() + "\""); + } + dataNodes.append(">\n"); + + dataNodes.append(biopaxParser.toReferenceXml(ca.getMiriamData())); + Rectangle2D rec = ca.getBorder(); + + dataNodes.append( + " <Graphics CenterX=\"" + rec.getCenterX() + + "\" CenterY=\"" + rec.getCenterY() + + "\" Width=\"" + rec.getWidth() + + "\" Height=\"" + rec.getHeight() + + "\" ZOrder=\"" + ca.getZ() + + "\" FontSize=\"10\"" + + " Valign=\"Middle\" " + + "Color=\"0000ff\" " + + "FillColor=\"ffffcc\"" + + " LineStyle=\"Broken\"/>\n"); + + dataNodes.append(referenceParser.toXml(ca.getMiriamData())); + dataNodes.append(" </DataNode>\n"); + } + } + + return dataNodes.toString(); + } + + /** + * This function encode ComplexAliases into Groups from .gpml format. + * + * @param model + * model where aliases are placed + * @return string representing groups in gpml format + */ + protected String getGroups(Model model) { + StringBuilder groups = new StringBuilder(""); + + for (Complex ca : model.getComplexList()) { + if (ca.getElements().size() > 0) { + groups.append(" <Group GroupId=\"" + ca.getElementId() + "\" GraphId=\"" + ca.getElementId() + "\""); + if (ca.getComplex() != null) { + groups.append(" GroupRef=\"" + ca.getComplex().getElementId() + "\""); + } + groups.append("/>\n"); + } + } + return groups.toString(); + } + + /** + * This function encode Reactions into Interactions from .gpml format. + * + * @param model + * model where reactions are placed + * @return string with interactions in gpml format + * @throws ConverterException + * thrown when there is a problem with conversion + */ + protected String getInteractions(Model model) throws ConverterException { + StringBuilder interactions = new StringBuilder(""); + for (Reaction reaction : model.getReactions()) { + + StringBuilder anchors = new StringBuilder(""); + StringBuilder tmp = new StringBuilder(""); + + interactions.append(" <Interaction GraphId=\"" + reaction.getIdReaction() + "\">\n"); + interactions.append(biopaxParser.toReferenceXml(reaction.getMiriamData())); + // interactions.append(" <Attribute Key=\"org.pathvisio.core.ds\" + // Value=\"\"/>\n"); + // interactions.append(" <Attribute Key=\"org.pathvisio.core.id\" + // Value=\"\"/>\n"); + interactions.append(" <Graphics ConnectorType=\"Segmented\" ZOrder=\"32827\" LineThickness=\"1.0\">\n"); + + /** Start and End **/ + Reactant start = reaction.getReactants().get(0); + Product end = reaction.getProducts().get(0); + + PolylineData line = getPolyline(start, end); + Point2D ps = line.getBeginPoint(); + Point2D pe = line.getEndPoint(); + String sid = start.getElement().getElementId(); + String eid = end.getElement().getElementId(); + + for (Point2D p2d : line.getPoints()) { + if (p2d.equals(ps)) { + interactions + .append(" <Point X=\"" + ps.getX() + "\" Y=\"" + ps.getY() + "\" GraphRef=\"" + sid + "\"/>\n"); + } else if (p2d.equals(pe)) { + interactions.append(" <Point X=\"" + pe.getX() + "\" Y=\"" + pe.getY() + "\" GraphRef=\"" + eid + + "\" ArrowHead=\"mim-conversion\"/>\n"); + } else { + interactions.append(" <Point X=\"" + p2d.getX() + "\" Y=\"" + p2d.getY() + "\"/>\n"); + } + } + /** Reactants **/ + boolean first = true; + for (Reactant reactant : reaction.getReactants()) { + if (first) { + first = false; + } else { + tmp.append(getInteractionForAnchor(reactant, getNewId(), anchors, line)); + } + } + /** Products **/ + first = true; + for (Product product : reaction.getProducts()) { + if (first) { + first = false; + } else { + tmp.append(getInteractionForAnchor(product, getNewId(), anchors, line)); + } + } + /** Modifiers **/ + for (Modifier modifier : reaction.getModifiers()) { + tmp.append(getInteractionForAnchor(modifier, getNewId(), anchors, line)); + } + + interactions.append(anchors.toString()); + interactions.append(" </Graphics>\n"); + interactions.append(referenceParser.toXml(reaction.getMiriamData())); + interactions.append(" </Interaction>\n"); + interactions.append(tmp.toString()); + } + + return interactions.toString(); + } + + /** + * This function returns Model in .gpml format. + * + * @param model + * model to transform + * @return string in gpml format representing model + * @throws ConverterException + * thrown when there is a problem with conversion + */ + public String getGPML(Model model) throws ConverterException { + + 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"); + gpml.append(" <Graphics BoardWidth=\"" + model.getWidth() + "\" BoardHeight=\"" + model.getHeight() + "\"/>\n"); + + gpml.append(getDataNodes(model)); + String groups = getGroups(model); + gpml.append(getInteractions(model)); + gpml.append(getComparments(model)); + gpml.append(groups); + Set<MiriamData> set = new HashSet<>(); + for (BioEntity element : model.getBioEntities()) { + set.addAll(element.getMiriamData()); + } + + // the order here is important... + gpml.append(" <InfoBox CenterX=\"0.0\" CenterY=\"0.0\"/>\n"); + gpml.append(biopaxParser.toXml(set)); + + gpml.append("</Pathway>"); + + return gpml.toString(); + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java index ae3dccb80a78c2514cf1debb6d2796abd44c0618..7af111468d47235671d1d732c1a51c806b31d728 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java @@ -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; + } + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/GPMLToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/GPMLToModelTest.java index 47b4d62fd8d5d58925f2acdb91c7bd74219210c4..32c31e6da8f88a889581c55b17d527d6f78ded72 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/GPMLToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/GPMLToModelTest.java @@ -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(); - 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) { @@ -257,12 +220,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertEquals(0, 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) { @@ -282,12 +240,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertEquals(0, 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) { @@ -306,12 +259,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) { @@ -330,12 +278,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) { @@ -476,11 +419,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { String fileName = "testFiles/compartment/complex_in_compartment.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - 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)); @@ -497,11 +436,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { String fileName = "testFiles/small/reaction_to_complex.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - 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)); @@ -518,11 +453,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { String fileName = "testFiles/reactions/complex_color_reaction.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - 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) { @@ -537,11 +468,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { String fileName = "testFiles/reactions/complex_color_reaction2.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - 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) { @@ -560,11 +487,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertNotNull(protein); assertEquals(2, protein.getModificationResidues().size()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2Xml(model1, false); - 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)); @@ -584,11 +507,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertNotNull(protein); assertEquals(2, protein.getModificationResidues().size()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2Xml(model1, false); - 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)); @@ -628,11 +547,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertEquals(1, model1.getReactions().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) { @@ -652,11 +567,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertEquals(1, 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) { @@ -675,11 +586,7 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { assertEquals(0, protein.getModificationResidues().size()); assertEquals("GTP", protein.getStructuralState()); - 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) { diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java index 6b293c28e944192141caf1a238718b87e4c1e1d3..f19d4987a2956e1d15ca9c6eaf3e20e9e71a7195 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java @@ -4,872 +4,821 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.awt.geom.Line2D; -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; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.wikipathway.XML.GPMLToModel; -import org.apache.log4j.Logger; -import org.junit.Test; - -public class ReactionElbowsTest extends WikipathwaysTestFunctions{ - private final static double EPSILON = 1e-6; +public class ReactionElbowsTest extends WikipathwaysTestFunctions { + private final static double EPSILON = 1e-6; - /** - * Default class logger. - */ - static Logger logger = Logger.getLogger(ReactionElbowsTest.class); + /** + * Default class logger. + */ + static Logger logger = Logger.getLogger(ReactionElbowsTest.class); - private ModelComparator mc = new ModelComparator(1.0); + private ModelComparator mc = new ModelComparator(1.0); - @Test - public void LineReactionNorthToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionNorthToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(5, lines); + assertEquals(5, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionNorthToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionNorthToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionNorthToEast2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_e_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionNorthToEast2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_e_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionNorthToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionNorthToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(7, lines); + assertEquals(7, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionNorthToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionNorthToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + logger.debug(model1.getIdModel()); + logger.debug(model2.getIdModel()); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionNorthToWest2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_w_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionNorthToWest2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_w_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionEastToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionEastToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionEastToNorth2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_n_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionEastToNorth2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_n_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionEastToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionEastToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(5, lines); + assertEquals(5, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionEastToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionEastToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionEastToSouth2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_s_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionEastToSouth2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_s_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionEastToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionEastToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(5, lines); + assertEquals(5, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionSouthToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionSouthToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(5, lines); + assertEquals(5, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionSouthToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionSouthToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionSouthToEast2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_e_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionSouthToEast2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_e_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionSouthToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionSouthToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(5, lines); + assertEquals(5, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionSouthToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionSouthToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionSouthToWest2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_w_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionSouthToWest2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_w_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionWestToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionWestToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionWestToNorth2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_n_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionWestToNorth2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_n_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionWestToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionWestToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(7, lines); + assertEquals(7, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionWestToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionWestToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(6, lines); + assertEquals(6, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionWestToSouth2() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_s_2.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionWestToSouth2() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_s_2.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(4, lines); + assertEquals(4, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void LineReactionWestToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void LineReactionWestToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - int lines = 0; - for (AbstractNode node : reaction.getNodes()) { - for (Line2D line : node.getLine().getLines()) { - assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), isHvLine(line)); - lines++; - } - } + int lines = 0; + for (AbstractNode node : reaction.getNodes()) { + for (Line2D line : node.getLine().getLines()) { + assertTrue("Lines should be horizontal or vertical, but found: " + line.getP1() + " - " + line.getP2(), + isHvLine(line)); + lines++; + } + } - assertEquals(5, lines); + assertEquals(5, lines); - assertEquals(1, getWarnings().size()); + assertEquals(1, 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)); + assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - private boolean isHvLine(Line2D line) { - return Math.abs(line.getX1() - line.getX2()) < EPSILON || Math.abs(line.getY1() - line.getY2()) < EPSILON; - } + private boolean isHvLine(Line2D line) { + return Math.abs(line.getX1() - line.getX2()) < EPSILON || Math.abs(line.getY1() - line.getY2()) < EPSILON; + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlInputToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlInputToModelTest.java index 25e05d27f6ec478569112ab3894ca1b31d95c1d5..0d529b8fbe96a0a0a2946b3489d62872c91f9d1f 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlInputToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlInputToModelTest.java @@ -5,12 +5,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; +import org.apache.log4j.Logger; +import org.junit.Test; -import lcsb.mapviewer.converter.ConverterParams; -import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; import lcsb.mapviewer.model.map.modifier.Catalysis; @@ -25,1393 +22,1323 @@ import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.wikipathway.XML.GPMLToModel; -import org.apache.log4j.Logger; -import org.junit.Test; - public class ReactionGpmlInputToModelTest extends WikipathwaysTestFunctions { - /** - * Default class logger. - */ - static Logger logger = Logger.getLogger(ReactionGpmlInputToModelTest.class); - - private ModelComparator mc = new ModelComparator(1.0); - - @Test - public void LineInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_line_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void ArrowInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_arrow_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void DashedLineInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_line_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void DashedArrowInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_arrow_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void TBarInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_tbar_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Inhibition); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void NecessaryStimulationInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_necessary_stimulation_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof PhysicalStimulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void BindingInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_binding_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void ConversionInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_conversion_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void StimulationInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_stimulation_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof PhysicalStimulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void ModificationInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_modification_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void CatalystInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_catalyst_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Catalysis); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void InhibitionInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_inhibition_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Inhibition); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void CleavageInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_cleavage_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void CovalentBondInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_covalent_bond_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void BranchingLeftInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_branching_left_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void BranchingRightInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_branching_right_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void TranscriptionTranslationInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_transcription_translation_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void GapInteractionInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_gap_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void TBarInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_tbar_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof UnknownInhibition); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void NecessaryStimulationInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_necessary_stimulation_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void BindingInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_binding_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void ConversionInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_conversion_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void StimulationInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_stimulation_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void ModificationInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_modification_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void CatalystInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_catalyst_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof UnknownCatalysis); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void InhibitionInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_inhibition_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof UnknownInhibition); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void CleavageInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_cleavage_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void CovalentBondInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_covalent_bond_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void BranchingLeftInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_branching_left_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void BranchingRightInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_branching_right_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void TranscriptionTranslationInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_transcription_translation_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void GapInteractionDashedInputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_gap_input.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNull(product); - assertNotNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + /** + * Default class logger. + */ + static Logger logger = Logger.getLogger(ReactionGpmlInputToModelTest.class); + + private ModelComparator mc = new ModelComparator(1.0); + + @Test + public void LineInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_line_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ArrowInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_arrow_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void DashedLineInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_line_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void DashedArrowInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_arrow_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TBarInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_tbar_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Inhibition); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void NecessaryStimulationInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_necessary_stimulation_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof PhysicalStimulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BindingInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_binding_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ConversionInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_conversion_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void StimulationInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_stimulation_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof PhysicalStimulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ModificationInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_modification_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CatalystInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_catalyst_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Catalysis); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void InhibitionInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_inhibition_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Inhibition); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CleavageInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_cleavage_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CovalentBondInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_covalent_bond_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingLeftInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_branching_left_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingRightInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_branching_right_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TranscriptionTranslationInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_transcription_translation_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void GapInteractionInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_gap_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TBarInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_tbar_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof UnknownInhibition); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void NecessaryStimulationInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_necessary_stimulation_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BindingInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_binding_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ConversionInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_conversion_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void StimulationInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_stimulation_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ModificationInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_modification_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CatalystInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_catalyst_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof UnknownCatalysis); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void InhibitionInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_inhibition_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof UnknownInhibition); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CleavageInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_cleavage_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CovalentBondInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_covalent_bond_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingLeftInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_branching_left_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingRightInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_branching_right_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TranscriptionTranslationInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_transcription_translation_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void GapInteractionDashedInputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_gap_input.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNull(product); + assertNotNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java index 5e111c94e9bae7235ff377952c974539d67a646c..b9b708663ed00e5489f8461f568fe016c8eeac1a 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java @@ -5,12 +5,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; +import org.apache.log4j.Logger; +import org.junit.Test; -import lcsb.mapviewer.converter.ConverterParams; -import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; import lcsb.mapviewer.model.map.modifier.Catalysis; @@ -23,1422 +20,1323 @@ import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.wikipathway.XML.GPMLToModel; -import org.apache.log4j.Logger; -import org.junit.Test; +public class ReactionGpmlOutputToModelTest extends WikipathwaysTestFunctions { + /** + * Default class logger. + */ + static Logger logger = Logger.getLogger(ReactionGpmlOutputToModelTest.class); + + private ModelComparator mc = new ModelComparator(1.0); + + @Test + public void LineInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_line_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ArrowInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_arrow_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void DashedLineInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_line_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void DashedArrowInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_arrow_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TBarInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_tbar_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Inhibition); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void NecessaryStimulationInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_necessary_stimulation_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof PhysicalStimulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BindingInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_binding_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ConversionInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_conversion_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void StimulationInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_stimulation_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof PhysicalStimulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ModificationInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_modification_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CatalystInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_catalyst_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Catalysis); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void InhibitionInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_inhibition_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Inhibition); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CleavageInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_cleavage_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CovalentBondInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_covalent_bond_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingLeftInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_branching_left_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingRightInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_branching_right_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(0, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TranscriptionTranslationInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_transcription_translation_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void GapInteractionOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_gap_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(1, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TBarInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_tbar_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Inhibition); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void NecessaryStimulationInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_necessary_stimulation_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof PhysicalStimulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BindingInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_binding_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ConversionInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_conversion_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void StimulationInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_stimulation_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof PhysicalStimulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void ModificationInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_modification_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CatalystInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_catalyst_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Catalysis); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void InhibitionInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_inhibition_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Inhibition); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CleavageInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_cleavage_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void CovalentBondInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_covalent_bond_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingLeftInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_branching_left_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void BranchingRightInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_branching_right_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modifier); + } + + assertNotNull(reactant); + assertNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void TranscriptionTranslationInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_transcription_translation_output.gpml"; + + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } -public class ReactionGpmlOutputToModelTest extends WikipathwaysTestFunctions{ - /** - * Default class logger. - */ - static Logger logger = Logger.getLogger(ReactionGpmlOutputToModelTest.class); + @Test + public void GapInteractionDashedOutputTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_gap_output.gpml"; - private ModelComparator mc = new ModelComparator(1.0); + Model model1 = new GPMLToModel().getModel(fileName); - @Test - public void LineInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_line_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void ArrowInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_arrow_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void DashedLineInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_line_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void DashedArrowInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_arrow_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void TBarInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_tbar_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Inhibition); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void NecessaryStimulationInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_necessary_stimulation_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof PhysicalStimulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BindingInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_binding_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void ConversionInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_conversion_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void StimulationInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_stimulation_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof PhysicalStimulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void ModificationInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_modification_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void CatalystInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_catalyst_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Catalysis); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void InhibitionInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_inhibition_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Inhibition); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void CleavageInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_cleavage_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void CovalentBondInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_covalent_bond_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BranchingLeftInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_branching_left_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BranchingRightInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_branching_right_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(0, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void TranscriptionTranslationInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_transcription_translation_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void GapInteractionOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_gap_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(1, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void TBarInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_tbar_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Inhibition); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void NecessaryStimulationInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_necessary_stimulation_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof PhysicalStimulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BindingInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_binding_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void ConversionInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_conversion_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void StimulationInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_stimulation_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof PhysicalStimulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void ModificationInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_modification_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void CatalystInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_catalyst_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Catalysis); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void InhibitionInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_inhibition_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Inhibition); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void CleavageInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_cleavage_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void CovalentBondInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_covalent_bond_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BranchingLeftInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_branching_left_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BranchingRightInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_branching_right_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modifier); - } - - assertNotNull(reactant); - assertNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void TranscriptionTranslationInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_transcription_translation_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void GapInteractionDashedOutputTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_gap_output.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - Product product = null; - if (reaction.getProducts().size() > 1) { - product = reaction.getProducts().get(1); - } - Reactant reactant = null; - if (reaction.getReactants().size() > 1) { - reactant = reaction.getReactants().get(1); - } - Modifier modifier = null; - if (reaction.getModifiers().size() > 0) { - modifier = reaction.getModifiers().get(0); - assertTrue(modifier instanceof Modulation); - } - - assertNull(reactant); - assertNotNull(product); - assertNull(modifier); - - assertEquals(2, 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, model1.getReactions().size()); + + Reaction reaction = model1.getReactions().iterator().next(); + + Product product = null; + if (reaction.getProducts().size() > 1) { + product = reaction.getProducts().get(1); + } + Reactant reactant = null; + if (reaction.getReactants().size() > 1) { + reactant = reaction.getReactants().get(1); + } + Modifier modifier = null; + if (reaction.getModifiers().size() > 0) { + modifier = reaction.getModifiers().get(0); + assertTrue(modifier instanceof Modulation); + } + + assertNull(reactant); + assertNotNull(product); + assertNull(modifier); + + assertEquals(2, getWarnings().size()); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals(0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java index d2e625d7934f70c4cde11533a3c80ea09d5cb39e..cf21d37c15c14adbe08436d68ffd18b7b9d44d2b 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java @@ -4,15 +4,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - import org.apache.log4j.Logger; import org.junit.Test; -import lcsb.mapviewer.converter.ConverterParams; -import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; import lcsb.mapviewer.model.map.reaction.Reaction; @@ -26,1029 +20,853 @@ import lcsb.mapviewer.model.map.reaction.type.UnknownPositiveInfluenceReaction; import lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction; import lcsb.mapviewer.wikipathway.XML.GPMLToModel; -public class ReactionGpmlToModelTest extends WikipathwaysTestFunctions{ - /** - * Default class logger. - */ - static Logger logger = Logger.getLogger(ReactionGpmlToModelTest.class); - - private ModelComparator mc = new ModelComparator(1.0); - - @Test - public void LineInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_line.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); - - 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)); - - assertEquals(0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void ArrowInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_arrow.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof StateTransitionReaction); - assertFalse(reaction.isReversible()); - - 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)); - - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void DashedArrowInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_arrow.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); - - 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)); - - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void DashedLineInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_line.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); - - 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)); - - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BindingInteractionTest() throws Exception { - try { - // invalid mim_binding (contains only one reactant) - String fileName = "testFiles/reactions/interaction_mim_binding.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertFalse(reaction.isReversible()); - - 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)); - - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BindingInteractionTest2() throws Exception { - try { - // proper mim_binding (contains two reactants) - String fileName = "testFiles/reactions/interaction_mim_binding2.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(getWarnings().toString(), 0, getWarnings().size()); - assertTrue(reaction instanceof HeterodimerAssociationReaction); - assertFalse(reaction.isReversible()); - assertEquals(2, reaction.getReactants().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)); - - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BranchingLeftInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_branching_left.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); - - 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)); - - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void BranchingRightInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_branching_right.gpml"; - - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - Reaction reaction = model1.getReactions().iterator().next(); - - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); +public class ReactionGpmlToModelTest extends WikipathwaysTestFunctions { + /** + * Default class logger. + */ + static Logger logger = Logger.getLogger(ReactionGpmlToModelTest.class); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + private ModelComparator mc = new ModelComparator(1.0); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + @Test + public void LineInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_line.gpml"; - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, model1.getReactions().size()); - @Test - public void CatalystInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_catalyst.gpml"; + Reaction reaction = model1.getReactions().iterator().next(); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - assertEquals(1, model1.getReactions().size()); + Model model2 = serializeModelOverCellDesignerParser(model1); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(0, mc.compare(model1, model2)); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof PositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + @Test + public void ArrowInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_arrow.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)); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Reaction reaction = model1.getReactions().iterator().next(); - @Test - public void CleavageInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_cleavage.gpml"; + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof StateTransitionReaction); + assertFalse(reaction.isReversible()); - Model model1 = new GPMLToModel().getModel(fileName); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(1, model1.getReactions().size()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Reaction reaction = model1.getReactions().iterator().next(); + @Test + public void DashedArrowInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_arrow.gpml"; - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof StateTransitionReaction); - assertFalse(reaction.isReversible()); + Model model1 = new GPMLToModel().getModel(fileName); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, model1.getReactions().size()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Reaction reaction = model1.getReactions().iterator().next(); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model2 = serializeModelOverCellDesignerParser(model1); - @Test - public void ConversionInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_conversion.gpml"; + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void DashedLineInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_line.gpml"; - assertEquals(1, model1.getReactions().size()); + Model model1 = new GPMLToModel().getModel(fileName); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof StateTransitionReaction); - assertFalse(reaction.isReversible()); + Reaction reaction = model1.getReactions().iterator().next(); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Test + public void BindingInteractionTest() throws Exception { + try { + // invalid mim_binding (contains only one reactant) + String fileName = "testFiles/reactions/interaction_mim_binding.gpml"; - @Test - public void CovalentBondInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_covalent_bond.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, model1.getReactions().size()); - assertEquals(1, model1.getReactions().size()); + Reaction reaction = model1.getReactions().iterator().next(); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertFalse(reaction.isReversible()); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + Model model2 = serializeModelOverCellDesignerParser(model1); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + @Test + public void BindingInteractionTest2() throws Exception { + try { + // proper mim_binding (contains two reactants) + String fileName = "testFiles/reactions/interaction_mim_binding2.gpml"; - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, model1.getReactions().size()); - @Test - public void GapInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_gap.gpml"; + Reaction reaction = model1.getReactions().iterator().next(); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(getWarnings().toString(), 0, getWarnings().size()); + assertTrue(reaction instanceof HeterodimerAssociationReaction); + assertFalse(reaction.isReversible()); + assertEquals(2, reaction.getReactants().size()); - assertEquals(1, model1.getReactions().size()); + Model model2 = serializeModelOverCellDesignerParser(model1); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Reaction reaction = model1.getReactions().iterator().next(); + @Test + public void BranchingLeftInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_branching_left.gpml"; - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + Model model1 = new GPMLToModel().getModel(fileName); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, model1.getReactions().size()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Reaction reaction = model1.getReactions().iterator().next(); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model2 = serializeModelOverCellDesignerParser(model1); - @Test - public void InhibitionInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_inhibition.gpml"; + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void BranchingRightInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_branching_right.gpml"; - assertEquals(1, model1.getReactions().size()); + Model model1 = new GPMLToModel().getModel(fileName); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof NegativeInfluenceReaction); - assertFalse(reaction.isReversible()); + Reaction reaction = model1.getReactions().iterator().next(); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Test + public void CatalystInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_catalyst.gpml"; - @Test - public void ModificationInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_modification.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, model1.getReactions().size()); - assertEquals(1, model1.getReactions().size()); + Reaction reaction = model1.getReactions().iterator().next(); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof PositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof PositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + Model model2 = serializeModelOverCellDesignerParser(model1); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + @Test + public void CleavageInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_cleavage.gpml"; - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, model1.getReactions().size()); - @Test - public void NecessaryStimulationInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_necessary_stimulation.gpml"; + Reaction reaction = model1.getReactions().iterator().next(); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof StateTransitionReaction); + assertFalse(reaction.isReversible()); - assertEquals(1, model1.getReactions().size()); + Model model2 = serializeModelOverCellDesignerParser(model1); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof ReducedPhysicalStimulationReaction); - assertFalse(reaction.isReversible()); + @Test + public void ConversionInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_conversion.gpml"; - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Model model1 = new GPMLToModel().getModel(fileName); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(1, model1.getReactions().size()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof StateTransitionReaction); + assertFalse(reaction.isReversible()); - @Test - public void StimulationInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_stimulation.gpml"; + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(1, model1.getReactions().size()); + @Test + public void CovalentBondInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_covalent_bond.gpml"; - Reaction reaction = model1.getReactions().iterator().next(); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof ReducedPhysicalStimulationReaction); - assertFalse(reaction.isReversible()); + assertEquals(1, model1.getReactions().size()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Reaction reaction = model1.getReactions().iterator().next(); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void TranscriptionTranslationInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_mim_transcription_translation.gpml"; + @Test + public void GapInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_gap.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof PositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Model model2 = serializeModelOverCellDesignerParser(model1); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + @Test + public void InhibitionInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_inhibition.gpml"; - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model1 = new GPMLToModel().getModel(fileName); - @Test - public void TbarTranslationInteractionTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_tbar.gpml"; + assertEquals(1, model1.getReactions().size()); - Model model1 = new GPMLToModel().getModel(fileName); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getReactions().size()); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof NegativeInfluenceReaction); + assertFalse(reaction.isReversible()); - Reaction reaction = model1.getReactions().iterator().next(); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof NegativeInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + @Test + public void ModificationInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_modification.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)); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Reaction reaction = model1.getReactions().iterator().next(); - @Test - public void LineAsInteractionTest2() throws Exception { - try { - // proper mim_binding (contains two reactants) - String fileName = "testFiles/reactions/line_as_interaction.gpml"; + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof PositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - Model model1 = new GPMLToModel().getModel(fileName); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(1, model1.getReactions().size()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Reaction reaction = model1.getReactions().iterator().next(); + @Test + public void NecessaryStimulationInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_necessary_stimulation.gpml"; - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + Model model1 = new GPMLToModel().getModel(fileName); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, model1.getReactions().size()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Reaction reaction = model1.getReactions().iterator().next(); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof ReducedPhysicalStimulationReaction); + assertFalse(reaction.isReversible()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model2 = serializeModelOverCellDesignerParser(model1); - @Test - public void BindingInteractionDashedTest() throws Exception { - try { - // invalid mim_binding (contains only one reactant) - String fileName = "testFiles/reactions/interaction_dashed_mim_binding.gpml"; + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void StimulationInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_stimulation.gpml"; - assertEquals(1, model1.getReactions().size()); + Model model1 = new GPMLToModel().getModel(fileName); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + Reaction reaction = model1.getReactions().iterator().next(); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof ReducedPhysicalStimulationReaction); + assertFalse(reaction.isReversible()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Test + public void TranscriptionTranslationInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_mim_transcription_translation.gpml"; - @Test - public void BranchingLeftInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_branching_left.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, model1.getReactions().size()); - assertEquals(1, model1.getReactions().size()); + Reaction reaction = model1.getReactions().iterator().next(); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof PositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + Model model2 = serializeModelOverCellDesignerParser(model1); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + @Test + public void TbarTranslationInteractionTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_tbar.gpml"; - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, model1.getReactions().size()); - @Test - public void BranchingRightInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_branching_right.gpml"; + Reaction reaction = model1.getReactions().iterator().next(); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof NegativeInfluenceReaction); + assertFalse(reaction.isReversible()); - assertEquals(1, model1.getReactions().size()); + Model model2 = serializeModelOverCellDesignerParser(model1); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + @Test + public void LineAsInteractionTest2() throws Exception { + try { + // proper mim_binding (contains two reactants) + String fileName = "testFiles/reactions/line_as_interaction.gpml"; - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Model model1 = new GPMLToModel().getModel(fileName); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(1, model1.getReactions().size()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - @Test - public void CatalystInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_catalyst.gpml"; + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(1, model1.getReactions().size()); + @Test + public void BindingInteractionDashedTest() throws Exception { + try { + // invalid mim_binding (contains only one reactant) + String fileName = "testFiles/reactions/interaction_dashed_mim_binding.gpml"; - Reaction reaction = model1.getReactions().iterator().next(); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(1, model1.getReactions().size()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Reaction reaction = model1.getReactions().iterator().next(); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void CleavageInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_cleavage.gpml"; + @Test + public void BranchingLeftInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_branching_left.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertFalse(reaction.isReversible()); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Model model2 = serializeModelOverCellDesignerParser(model1); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + @Test + public void BranchingRightInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_branching_right.gpml"; - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model1 = new GPMLToModel().getModel(fileName); - @Test - public void ConversionInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_conversion.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, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - Reaction reaction = model1.getReactions().iterator().next(); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + @Test + public void CatalystInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_catalyst.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)); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Reaction reaction = model1.getReactions().iterator().next(); - @Test - public void CovalentBondInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_covalent_bond.gpml"; + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - Model model1 = new GPMLToModel().getModel(fileName); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(1, model1.getReactions().size()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Reaction reaction = model1.getReactions().iterator().next(); + @Test + public void CleavageInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_cleavage.gpml"; - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + Model model1 = new GPMLToModel().getModel(fileName); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, model1.getReactions().size()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Reaction reaction = model1.getReactions().iterator().next(); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertFalse(reaction.isReversible()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model2 = serializeModelOverCellDesignerParser(model1); - @Test - public void GapInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_gap.gpml"; + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void ConversionInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_conversion.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, getWarnings().size()); - assertTrue(reaction instanceof UnknownTransitionReaction); - assertTrue(reaction.isReversible()); + Reaction reaction = model1.getReactions().iterator().next(); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Test + public void CovalentBondInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_covalent_bond.gpml"; - @Test - public void InhibitionInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_inhibition.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, model1.getReactions().size()); - assertEquals(1, model1.getReactions().size()); + Reaction reaction = model1.getReactions().iterator().next(); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownNegativeInfluenceReaction); - assertFalse(reaction.isReversible()); + Model model2 = serializeModelOverCellDesignerParser(model1); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + @Test + public void GapInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_gap.gpml"; - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, model1.getReactions().size()); - @Test - public void ModificationInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_modification.gpml"; + Reaction reaction = model1.getReactions().iterator().next(); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownTransitionReaction); + assertTrue(reaction.isReversible()); - assertEquals(1, model1.getReactions().size()); + Model model2 = serializeModelOverCellDesignerParser(model1); - Reaction reaction = model1.getReactions().iterator().next(); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(0, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + @Test + public void InhibitionInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_inhibition.gpml"; - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Model model1 = new GPMLToModel().getModel(fileName); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(1, model1.getReactions().size()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownNegativeInfluenceReaction); + assertFalse(reaction.isReversible()); - @Test - public void NecessaryStimulationInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_necessary_stimulation.gpml"; + Model model2 = serializeModelOverCellDesignerParser(model1); - Model model1 = new GPMLToModel().getModel(fileName); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - assertEquals(1, model1.getReactions().size()); + @Test + public void ModificationInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_modification.gpml"; - Reaction reaction = model1.getReactions().iterator().next(); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(1, model1.getReactions().size()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Reaction reaction = model1.getReactions().iterator().next(); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(0, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void StimulationInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_stimulation.gpml"; + @Test + public void NecessaryStimulationInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_necessary_stimulation.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getReactions().size()); + assertEquals(1, model1.getReactions().size()); - Reaction reaction = model1.getReactions().iterator().next(); + Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + Model model2 = serializeModelOverCellDesignerParser(model1); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + @Test + public void StimulationInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_stimulation.gpml"; - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model1 = new GPMLToModel().getModel(fileName); - @Test - public void TranscriptionTranslationInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_mim_transcription_translation.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, getWarnings().size()); + assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - Reaction reaction = model1.getReactions().iterator().next(); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof PositiveInfluenceReaction); - assertFalse(reaction.isReversible()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + @Test + public void TranscriptionTranslationInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_mim_transcription_translation.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)); + assertEquals(1, model1.getReactions().size()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Reaction reaction = model1.getReactions().iterator().next(); - @Test - public void TbarTranslationInteractionDashedTest() throws Exception { - try { - String fileName = "testFiles/reactions/interaction_dashed_tbar.gpml"; + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof PositiveInfluenceReaction); + assertFalse(reaction.isReversible()); - Model model1 = new GPMLToModel().getModel(fileName); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(1, model1.getReactions().size()); + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Reaction reaction = model1.getReactions().iterator().next(); + @Test + public void TbarTranslationInteractionDashedTest() throws Exception { + try { + String fileName = "testFiles/reactions/interaction_dashed_tbar.gpml"; - assertEquals(1, getWarnings().size()); - assertTrue(reaction instanceof UnknownNegativeInfluenceReaction); - assertFalse(reaction.isReversible()); + Model model1 = new GPMLToModel().getModel(fileName); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(1, model1.getReactions().size()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + Reaction reaction = model1.getReactions().iterator().next(); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + assertEquals(1, getWarnings().size()); + assertTrue(reaction instanceof UnknownNegativeInfluenceReaction); + assertFalse(reaction.isReversible()); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Model model2 = serializeModelOverCellDesignerParser(model1); - @Test - public void lineLineCombinedReactionsTest() throws Exception { - try { - String fileName = "testFiles/reactions/line_line_combined_reaction.gpml"; + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - Model model1 = new GPMLToModel().getModel(fileName); + @Test + public void lineLineCombinedReactionsTest() throws Exception { + try { + String fileName = "testFiles/reactions/line_line_combined_reaction.gpml"; - assertEquals(4, model1.getReactions().size()); - - assertEquals(4, getWarnings().size()); + Model model1 = new GPMLToModel().getModel(fileName); - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.model2String(model1); + assertEquals(4, model1.getReactions().size()); - InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + assertEquals(4, getWarnings().size()); - Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); + Model model2 = serializeModelOverCellDesignerParser(model1); - assertEquals(0, mc.compare(model1, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + assertEquals(0, mc.compare(model1, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/WikipathwaysTestFunctions.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/WikipathwaysTestFunctions.java index 25874080f7f2f5d4de3009066ecad3f8ab1a5c0d..fb326be303434c33e6846f6df68b28ad48f6e85e 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/WikipathwaysTestFunctions.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/WikipathwaysTestFunctions.java @@ -1,6 +1,7 @@ package lcsb.mapviewer.wikipathway; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; @@ -13,6 +14,7 @@ import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -26,10 +28,6 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.EventStorageLoggerAppender; -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; - import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; import org.junit.After; @@ -41,194 +39,218 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.EventStorageLoggerAppender; +import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; +import lcsb.mapviewer.converter.ConverterParams; +import lcsb.mapviewer.converter.InvalidInputDataExecption; +import lcsb.mapviewer.converter.ZIndexPopulator; +import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; +import lcsb.mapviewer.model.map.BioEntity; +import lcsb.mapviewer.model.map.InconsistentModelException; +import lcsb.mapviewer.model.map.model.Model; + public abstract class WikipathwaysTestFunctions { - private Logger logger = Logger.getLogger(WikipathwaysTestFunctions.class); - - protected static double EPSILON = Configuration.EPSILON; - - private DocumentBuilder db; - - - private EventStorageLoggerAppender appender; - - @Before - public final void _setUp() throws Exception { - Logger.getRootLogger().removeAppender(appender); - appender = new EventStorageLoggerAppender(); - Logger.getRootLogger().addAppender(appender); - db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } - - @After - public final void _tearDown() throws Exception { - Logger.getRootLogger().removeAppender(appender); - } - - protected List<LoggingEvent> getWarnings() { - return appender.getWarnings(); - } - - protected String readFile(String file) throws IOException { - StringBuilder stringBuilder = new StringBuilder(); - BufferedReader reader = new BufferedReader(new FileReader(file)); - try { - String line = null; - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - } finally { - reader.close(); - } - - return stringBuilder.toString(); - } - - protected Node getNodeFromXmlString(String text) throws InvalidXmlSchemaException { - InputSource is = new InputSource(); - is.setCharacterStream(new StringReader(text)); - return getXmlDocumentFromInputSource(is).getChildNodes().item(0); - } - - protected Document getXmlDocumentFromFile(String fileName) throws InvalidXmlSchemaException, IOException { - File file = new File(fileName); - InputStream inputStream = new FileInputStream(file); - Reader reader = null; - try { - reader = new InputStreamReader(inputStream, "UTF-8"); - InputSource is = new InputSource(reader); - - Document result = getXmlDocumentFromInputSource(is); - inputStream.close(); - return result; - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - protected Document getXmlDocumentFromInputSource(InputSource stream) throws InvalidXmlSchemaException { - DocumentBuilder db; - try { - db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw new InvalidXmlSchemaException("Problem with xml parser"); - } - Document doc = null; - try { - doc = db.parse(stream); - } catch (SAXException e) { - logger.error(e); - } catch (IOException e) { - logger.error(e); - } - return doc; - } - - protected String createTmpFileName() { - try { - File f = File.createTempFile("prefix", ".txt"); - String filename = f.getName(); - f.delete(); - return filename; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - protected String nodeToString(Node node) { - return nodeToString(node, false); - } - - protected String nodeToString(Node node, boolean includeHeadNode) { - if (node == null) - return null; - StringWriter sw = new StringWriter(); - try { - Transformer t = TransformerFactory.newInstance().newTransformer(); - t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - t.setOutputProperty(OutputKeys.INDENT, "yes"); - t.setOutputProperty(OutputKeys.METHOD, "xml"); - - NodeList list = node.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node element = list.item(i); - t.transform(new DOMSource(element), new StreamResult(sw)); - } - } catch (TransformerException te) { - logger.debug("nodeToString Transformer Exception"); - } - if (includeHeadNode) { - return "<" + node.getNodeName() + ">" + sw.toString() + "</" + node.getNodeName() + ">"; - } - return sw.toString(); - } - - protected boolean equalFiles(String fileA, String fileB) throws IOException { - int BLOCK_SIZE = 65536; - FileInputStream inputStreamA = new FileInputStream(fileA); - FileInputStream inputStreamB = new FileInputStream(fileB); - // vary BLOCK_SIZE to suit yourself. - // it should probably a factor or multiple of the size of a disk - // sector/cluster. - // Note that your max heap size may need to be adjused - // if you have a very big block size or lots of these comparators. - - // assume inputStreamA and inputStreamB are streams from your two files. - byte[] streamABlock = new byte[BLOCK_SIZE]; - byte[] streamBBlock = new byte[BLOCK_SIZE]; - boolean match = true; - int bytesReadA = 0; - int bytesReadB = 0; - do { - bytesReadA = inputStreamA.read(streamABlock); - bytesReadB = inputStreamB.read(streamBBlock); - match = ((bytesReadA == bytesReadB) && Arrays.equals(streamABlock, streamBBlock)); - } while (match && (bytesReadA > -1)); - inputStreamA.close(); - inputStreamB.close(); - return match; - } - - public File createTempDirectory() throws IOException { - final File temp; - - temp = File.createTempFile("temp", Long.toString(System.nanoTime())); - - if (!(temp.delete())) { - throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); - } - - if (!(temp.mkdir())) { - throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); - } - - return (temp); - } - - protected String getWebpage(String accessUrl) throws IOException { - String inputLine; - StringBuilder tmp = new StringBuilder(); - URL url = new URL(accessUrl); - URLConnection urlConn = url.openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); - - while ((inputLine = in.readLine()) != null) { - tmp.append(inputLine); - } - in.close(); - return tmp.toString(); - } - - protected Element fileToNode(String filename) throws SAXException, IOException { - InputStream is = new FileInputStream(new File(filename)); - Document doc = null; - doc = db.parse(is); - return doc.getDocumentElement(); - } - + private Logger logger = Logger.getLogger(WikipathwaysTestFunctions.class); + + protected static double EPSILON = Configuration.EPSILON; + + private DocumentBuilder db; + + private EventStorageLoggerAppender appender; + + @Before + public final void _setUp() throws Exception { + Logger.getRootLogger().removeAppender(appender); + appender = new EventStorageLoggerAppender(); + Logger.getRootLogger().addAppender(appender); + db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } + + @After + public final void _tearDown() throws Exception { + Logger.getRootLogger().removeAppender(appender); + } + + protected List<LoggingEvent> getWarnings() { + return appender.getWarnings(); + } + + protected String readFile(String file) throws IOException { + StringBuilder stringBuilder = new StringBuilder(); + BufferedReader reader = new BufferedReader(new FileReader(file)); + try { + String line = null; + String ls = System.getProperty("line.separator"); + + while ((line = reader.readLine()) != null) { + stringBuilder.append(line); + stringBuilder.append(ls); + } + } finally { + reader.close(); + } + + return stringBuilder.toString(); + } + + protected Node getNodeFromXmlString(String text) throws InvalidXmlSchemaException { + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(text)); + return getXmlDocumentFromInputSource(is).getChildNodes().item(0); + } + + protected Document getXmlDocumentFromFile(String fileName) throws InvalidXmlSchemaException, IOException { + File file = new File(fileName); + InputStream inputStream = new FileInputStream(file); + Reader reader = null; + try { + reader = new InputStreamReader(inputStream, "UTF-8"); + InputSource is = new InputSource(reader); + + Document result = getXmlDocumentFromInputSource(is); + inputStream.close(); + return result; + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + protected Document getXmlDocumentFromInputSource(InputSource stream) throws InvalidXmlSchemaException { + DocumentBuilder db; + try { + db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new InvalidXmlSchemaException("Problem with xml parser"); + } + Document doc = null; + try { + doc = db.parse(stream); + } catch (SAXException e) { + logger.error(e); + } catch (IOException e) { + logger.error(e); + } + return doc; + } + + protected String createTmpFileName() { + try { + File f = File.createTempFile("prefix", ".txt"); + String filename = f.getName(); + f.delete(); + return filename; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + protected String nodeToString(Node node) { + return nodeToString(node, false); + } + + protected String nodeToString(Node node, boolean includeHeadNode) { + if (node == null) + return null; + StringWriter sw = new StringWriter(); + try { + Transformer t = TransformerFactory.newInstance().newTransformer(); + t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + t.setOutputProperty(OutputKeys.INDENT, "yes"); + t.setOutputProperty(OutputKeys.METHOD, "xml"); + + NodeList list = node.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node element = list.item(i); + t.transform(new DOMSource(element), new StreamResult(sw)); + } + } catch (TransformerException te) { + logger.debug("nodeToString Transformer Exception"); + } + if (includeHeadNode) { + return "<" + node.getNodeName() + ">" + sw.toString() + "</" + node.getNodeName() + ">"; + } + return sw.toString(); + } + + protected boolean equalFiles(String fileA, String fileB) throws IOException { + int BLOCK_SIZE = 65536; + FileInputStream inputStreamA = new FileInputStream(fileA); + FileInputStream inputStreamB = new FileInputStream(fileB); + // vary BLOCK_SIZE to suit yourself. + // it should probably a factor or multiple of the size of a disk + // sector/cluster. + // Note that your max heap size may need to be adjused + // if you have a very big block size or lots of these comparators. + + // assume inputStreamA and inputStreamB are streams from your two files. + byte[] streamABlock = new byte[BLOCK_SIZE]; + byte[] streamBBlock = new byte[BLOCK_SIZE]; + boolean match = true; + int bytesReadA = 0; + int bytesReadB = 0; + do { + bytesReadA = inputStreamA.read(streamABlock); + bytesReadB = inputStreamB.read(streamBBlock); + match = ((bytesReadA == bytesReadB) && Arrays.equals(streamABlock, streamBBlock)); + } while (match && (bytesReadA > -1)); + inputStreamA.close(); + inputStreamB.close(); + return match; + } + + public File createTempDirectory() throws IOException { + final File temp; + + temp = File.createTempFile("temp", Long.toString(System.nanoTime())); + + if (!(temp.delete())) { + throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); + } + + if (!(temp.mkdir())) { + throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); + } + + return (temp); + } + + protected String getWebpage(String accessUrl) throws IOException { + String inputLine; + StringBuilder tmp = new StringBuilder(); + URL url = new URL(accessUrl); + URLConnection urlConn = url.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); + + while ((inputLine = in.readLine()) != null) { + tmp.append(inputLine); + } + in.close(); + return tmp.toString(); + } + + protected Element fileToNode(String filename) throws SAXException, IOException { + InputStream is = new FileInputStream(new File(filename)); + Document doc = null; + doc = db.parse(is); + return doc.getDocumentElement(); + } + + protected Model serializeModelOverCellDesignerParser(Model model1) + throws InconsistentModelException, InvalidInputDataExecption { + for (BioEntity bioEntity: model1.getBioEntities()) { + bioEntity.setZ(null); + } + new ZIndexPopulator().populateZIndex(model1); + 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)); + return model2; + } + } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/BugTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/BugTest.java index df028cd6edd21317141ddab2687ae613135125d6..81f02a65f9d33c5a2f456d70b3fb65f0cfa0c43b 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/BugTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/BugTest.java @@ -2,68 +2,59 @@ package lcsb.mapviewer.wikipathway.XML; import static org.junit.Assert.assertEquals; -import java.io.ByteArrayInputStream; import java.io.FileInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import org.apache.log4j.Logger; import org.junit.Test; -import lcsb.mapviewer.converter.ConverterParams; -import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; -import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Complex; +import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.wikipathway.WikipathwaysTestFunctions; public class BugTest extends WikipathwaysTestFunctions { - Logger logger = Logger.getLogger(BugTest.class); - - @Test - public void testBug319() throws Exception { - try { - String fileName = "testFiles/bugs/error_319.gpml"; - FileInputStream fis = new FileInputStream(fileName); - new GpmlParser().createGraph(fis); - assertEquals(1, getWarnings().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - private ModelComparator mc = new ModelComparator(1.0); - - @Test - public void testBug328() throws Exception { - try { - String filename = "testFiles/bugs/error_328.gpml"; - Model model1 = new GPMLToModel().getModel(filename); - - assertEquals(7, getWarnings().size()); - - int complexes = 0; - for (Element alias : model1.getElements()) { - if (alias instanceof Complex) { - complexes++; - } - } - assertEquals("Invalid number of complexes", 1, complexes); - - 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)); - - assertEquals("File " + filename + " different after transformation", 0, mc.compare(model1, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Logger logger = Logger.getLogger(BugTest.class); + + @Test + public void testBug319() throws Exception { + try { + String fileName = "testFiles/bugs/error_319.gpml"; + FileInputStream fis = new FileInputStream(fileName); + new GpmlParser().createGraph(fis); + assertEquals(1, getWarnings().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private ModelComparator mc = new ModelComparator(1.0); + + @Test + public void testBug328() throws Exception { + try { + String filename = "testFiles/bugs/error_328.gpml"; + Model model1 = new GPMLToModel().getModel(filename); + + assertEquals(7, getWarnings().size()); + + int complexes = 0; + for (Element alias : model1.getElements()) { + if (alias instanceof Complex) { + complexes++; + } + } + assertEquals("Invalid number of complexes", 1, complexes); + + Model model2 = serializeModelOverCellDesignerParser(model1); + + assertEquals("File " + filename + " different after transformation", 0, mc.compare(model1, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelContructorTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelContructorTest.java index a23566e0385db48d0725ec179c8bf0d1709c67cc..555d8b58e33fcb2c7aa15386f3967bc422721edf 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelContructorTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelContructorTest.java @@ -4,42 +4,88 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.awt.geom.Point2D; +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.model.graphics.PolylineData; - +import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelComparator; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; +import lcsb.mapviewer.model.map.species.GenericProtein; + public class ModelContructorTest { + Logger logger = Logger.getLogger(ModelContructorTest.class); + + ModelComparator comparator = new ModelComparator(); + + private int elementCounter = 0; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSplitPolyline() { + try { + Point2D p1 = new Point2D.Double(1455.5988605049254, 562.0578193221613); + Point2D p2 = new Point2D.Double(1455.5988605049254, 562.0578193221613); + PolylineData pd = new PolylineData(p1, p2); + + ModelContructor mc = new ModelContructor(); + Pair<PolylineData, PolylineData> result = mc.splitPolyline(pd); + assertNotNull(result); + assertNotNull(result.getLeft()); + assertNotNull(result.getRight()); + assertEquals(2, result.getLeft().getPoints().size()); + assertEquals(2, result.getRight().getPoints().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testZIndexForElement() throws Exception { + try { + ModelToGPML parser = new ModelToGPML(); + Model model = createEmptyModel(); + model.addElement(createProtein()); + String xml = parser.getGPML(model); + assertNotNull(xml); + + Model model2 = new GPMLToModel().getModel(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); + assertEquals(0, comparator.compare(model2, model)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private Model createEmptyModel() { + Model result = new ModelFullIndexed(null); + result.setWidth(640); + result.setHeight(480); + return result; + } - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - try { - Point2D p1 = new Point2D.Double(1455.5988605049254, 562.0578193221613); - Point2D p2 = new Point2D.Double(1455.5988605049254, 562.0578193221613); - PolylineData pd = new PolylineData(p1, p2); - - ModelContructor mc = new ModelContructor(); - Pair<PolylineData,PolylineData> result = mc.splitPolyline(pd); - assertNotNull(result); - assertNotNull(result.getLeft()); - assertNotNull(result.getRight()); - assertEquals(2, result.getLeft().getPoints().size()); - assertEquals(2, result.getRight().getPoints().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + private GenericProtein createProtein() { + GenericProtein result = new GenericProtein("s" + (elementCounter++)); + result.setX(100); + result.setY(20); + result.setWidth(100); + result.setHeight(30); + result.setZ(7890); + return result; + } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelToGPMLTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelToGPMLTest.java index 4f58af9d7590935daffd648009f3f9017427131a..da4ba111370fedcd91c056d0009a8f7011807c25 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelToGPMLTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelToGPMLTest.java @@ -61,15 +61,10 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions { model.setWidth(1000); model.setHeight(1000); - GenericProtein alias = new GenericProtein("sa"); - alias.setName("s2"); - alias.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA")); - alias.addMiriamData(new MiriamData(MiriamType.PUBMED, "123")); - alias.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); - alias.setWidth(10); - alias.setHeight(10); - alias.setX(1); - alias.setY(1); + GenericProtein alias = createProtein(); + alias.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA")); + alias.addMiriamData(new MiriamData(MiriamType.PUBMED, "123")); + alias.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); model.addElement(alias); @@ -91,4 +86,15 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions { throw e; } } + + private GenericProtein createProtein() { + GenericProtein alias = new GenericProtein("sa"); + alias.setName("s2"); + alias.setWidth(10); + alias.setHeight(10); + alias.setX(1); + alias.setY(1); + alias.setZ(15); + return alias; + } }