diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java index 2c5998efc299e86a5292d50f5e8082e1ec76f1a6..1dadb9b0719c267553e8e53f9bd8d9d18b7678c0 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java @@ -28,10 +28,12 @@ import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator; import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Species; @@ -165,13 +167,13 @@ public class ModelAnnotator { /** * Performs all possible and automatic annotations on the model. * - * @param model - * model to update + * @param project + * project to update * @param progressUpdater * callback function used for updating progress of the function */ - public void performAnnotations(Model model, final IProgressUpdater progressUpdater) { - performAnnotations(model, progressUpdater, null); + public void performAnnotations(Project project, final IProgressUpdater progressUpdater) { + performAnnotations(project, progressUpdater, null); } /** @@ -180,19 +182,21 @@ public class ModelAnnotator { * @param annotators * this map contains lists of {@link ElementAnnotator} objects that * should be used for a given classes - * @param model - * model to update + * @param project + * project with models to update * @param progressUpdater * callback function used for updating progress of the function */ - public void performAnnotations(Model model, final IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) { + public void performAnnotations(Project project, final IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) { EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); try { Logger.getRootLogger().addAppender(appender); progressUpdater.setProgress(0); - List<Model> models = new ArrayList<Model>(); - models.add(model); - models.addAll(model.getSubmodels()); + List<Model> models = new ArrayList<>(); + for (ModelData model: project.getModels()) { + models.add(model.getModel()); + models.addAll(model.getModel().getSubmodels()); + } final double size = models.size(); double counter = 0; for (Model m : models) { @@ -215,7 +219,7 @@ public class ModelAnnotator { counter++; } Logger.getRootLogger().removeAppender(appender); - model.addLoggingInfo(appender); + project.addLoggingInfo(appender); } finally { Logger.getRootLogger().removeAppender(appender); } diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java index b920636e1df0756272fad0d9ad983f95d42dd909..0402014d4290a000aee2cefaad7a8ab8b2513932 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java @@ -29,6 +29,7 @@ import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator; import lcsb.mapviewer.annotation.services.annotators.ReconAnnotator; import lcsb.mapviewer.common.IProgressUpdater; +import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamRelationType; @@ -311,7 +312,9 @@ public class ModelAnnotatorTest extends AnnotationTestFunctions { final MutableDouble maxProgress = new MutableDouble(0.0); - modelAnnotator.performAnnotations(model, new IProgressUpdater() { + Project project = new Project(); + project.addModel(model); + modelAnnotator.performAnnotations(project, new IProgressUpdater() { @Override public void setProgress(double progress) { maxProgress.setValue(Math.max(progress, maxProgress.getValue())); diff --git a/console/src/main/java/lcsb/mapviewer/run/BellExport.java b/console/src/main/java/lcsb/mapviewer/run/BellExport.java index fb59ddcb953c2734f0b1e469225fb349d66df143..b70a0b9423f1d14817c996a6ca3f5d529ee0dc2e 100644 --- a/console/src/main/java/lcsb/mapviewer/run/BellExport.java +++ b/console/src/main/java/lcsb/mapviewer/run/BellExport.java @@ -7,6 +7,7 @@ import lcsb.mapviewer.annotation.services.ModelAnnotator; import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; +import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.persist.ApplicationContextLoader; @@ -26,25 +27,25 @@ public class BellExport { /** * Default class logger. */ - private static Logger logger = Logger.getLogger(BellExport.class.getName()); + private static Logger logger = Logger.getLogger(BellExport.class.getName()); /** * Object that performs different types of export transformation. */ @Autowired - private IExporterService exporter; + private IExporterService exporter; /** * Object used to annotate the model. */ @Autowired - private ModelAnnotator modelAnnotator; + private ModelAnnotator modelAnnotator; /** * Object used to annotate the model. */ @Autowired - private DbUtils dbUtils; + private DbUtils dbUtils; /** * Static main method used to run this stand alone code. @@ -76,23 +77,22 @@ public class BellExport { try { String filename = PdMapAnnotations.getLastPdFilename(); String version = PdMapAnnotations.getLastPdVersion(); - - //filename = "testFiles/other_full/ASTHMAP18000X8000V1_38.xml"; - //version = "1.1.38"; + + // filename = "testFiles/other_full/ASTHMAP18000X8000V1_38.xml"; + // version = "1.1.38"; dbUtils.createSessionForCurrentThread(); Model model = p.createModel(new ConverterParams().filename(filename)); + Project project = new Project(); + project.addModel(model); - modelAnnotator.performAnnotations(model, new IProgressUpdater() { - + modelAnnotator.performAnnotations(project, new IProgressUpdater() { @Override public void setProgress(double progress) { - // TODO Auto-generated method stub - } }); ExporterParameters params = new IExporterService.ExporterParameters().model(model).// - fileName("out/bell/" + version + "-reactions.txt").// + fileName("out/bell/" + version + "-reactions.txt").// fileType(ExportFileType.TAB_SEPARATED).// type(Species.class).// moleculeEdges(false); @@ -100,15 +100,15 @@ public class BellExport { exporter.exportReactions(params); params = new IExporterService.ExporterParameters().model(model).// - fileName("out/bell/" + version + "-species.txt").// + fileName("out/bell/" + version + "-species.txt").// fileType(ExportFileType.TAB_SEPARATED).// type(Species.class).// -// column(ExportColumn.FULL).// + // column(ExportColumn.FULL).// moleculeEdges(false); exporter.exportSpecies(params); params = new IExporterService.ExporterParameters().model(model).// - fileName("out/bell/" + version + "-compartments.txt").// + fileName("out/bell/" + version + "-compartments.txt").// fileType(ExportFileType.TAB_SEPARATED).// type(Object.class); // // column(ExportColumn.FULL); diff --git a/console/src/main/java/lcsb/mapviewer/run/Statistics.java b/console/src/main/java/lcsb/mapviewer/run/Statistics.java index bb399e4ae4f317e7aef6b5fdf75e9452d04d575a..661ba6db47c7c665ece62c7058f37c82b7cf6491 100644 --- a/console/src/main/java/lcsb/mapviewer/run/Statistics.java +++ b/console/src/main/java/lcsb/mapviewer/run/Statistics.java @@ -20,13 +20,14 @@ import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; +import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Complex; +import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.persist.ApplicationContextLoader; import lcsb.mapviewer.persist.DbUtils; @@ -112,8 +113,11 @@ public class Statistics { try { // String modelName = PdMapAnnotations.getLastPdFilename(); CellDesignerXmlParser parser = new CellDesignerXmlParser(); + Project project = new Project(); for (String name : fileNames) { - models.add(parser.createModel(new ConverterParams().filename(name))); + Model model = parser.createModel(new ConverterParams().filename(name)); + models.add(model); + project.addModel(model); } IProgressUpdater updater = new IProgressUpdater() { @@ -122,9 +126,7 @@ public class Statistics { logger.debug("Progress: " + progress); } }; - for (Model model : models) { - modelAnnotator.performAnnotations(model, updater); - } + modelAnnotator.performAnnotations(project, updater); // modelAnnotator.removeIncorrectAnnotations(model, updater); printStatistics(models); 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 45dfe52fb0bfb0aba3c7bc6fa5311a9f8b9b1762..5de0ddc5436920c2f323c701d57e0ee801001496 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 @@ -18,7 +18,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.common.MimeType; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.XmlParser; @@ -77,7 +76,6 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { /** * Default class logger. */ - @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(CellDesignerXmlParser.class.getName()); /** @@ -107,153 +105,144 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { @Override public Model createModel(ConverterParams params) throws InvalidInputDataExecption { - EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); - try { - Logger.getRootLogger().addAppender(appender); + CellDesignerElementCollection elements = new CellDesignerElementCollection(); - CellDesignerElementCollection elements = new CellDesignerElementCollection(); + Model model = new ModelFullIndexed(null); + model.setSbgnFormat(params.isSbgnFormat()); - Model model = new ModelFullIndexed(null); - model.setSbgnFormat(params.isSbgnFormat()); + if (params.getFilename() != null) { + model.setName(FilenameUtils.getBaseName(params.getFilename())); + } + speciesSbmlParser = new SpeciesCollectionXmlParser(elements); + aliasCollectionParser = new AliasCollectionXmlParser(elements, model); + compartmentCollectionXmlParser = new CompartmentCollectionXmlParser(elements); - if (params.getFilename() != null) { - model.setName(FilenameUtils.getBaseName(params.getFilename())); - } - speciesSbmlParser = new SpeciesCollectionXmlParser(elements); - aliasCollectionParser = new AliasCollectionXmlParser(elements, model); - compartmentCollectionXmlParser = new CompartmentCollectionXmlParser(elements); - - DOMParser parser = new DOMParser(); - try { - parser.parse(params.getSource()); - } catch (IOException e) { - throw new InvalidInputDataExecption("IO Problem with a file: " + params.getSource().getSystemId(), e); - } - Document doc = parser.getDocument(); - try { + DOMParser parser = new DOMParser(); + try { + parser.parse(params.getSource()); + } catch (IOException e) { + throw new InvalidInputDataExecption("IO Problem with a file: " + params.getSource().getSystemId(), e); + } + Document doc = parser.getDocument(); + try { - // Get the document's root XML node - NodeList root = doc.getChildNodes(); + // Get the document's root XML node + NodeList root = doc.getChildNodes(); - // Navigate down the hierarchy to get to the CEO node - Node sbmlNode = getNode("SBML", root); - if (sbmlNode == null) { - throw new InvalidInputDataExecption("No SBML node"); - } + // Navigate down the hierarchy to get to the CEO node + Node sbmlNode = getNode("SBML", root); + if (sbmlNode == null) { + throw new InvalidInputDataExecption("No SBML node"); + } - Node modelNode = getNode("model", sbmlNode.getChildNodes()); - if (modelNode == null) { - throw new InvalidInputDataExecption("No model node in SBML"); - } - // we ignore metaid - it's useless and obstruct data model - // model.setMetaId(getNodeAttr("metaId", modelNode)); - model.setIdModel(getNodeAttr("id", modelNode)); - - Node compartmentNode = getNode("listOfCompartments", modelNode.getChildNodes()); - if (compartmentNode != null) { - List<CellDesignerCompartment> compartments = compartmentCollectionXmlParser.parseXmlCompartmentCollection(compartmentNode); - elements.addElements(compartments); - } + Node modelNode = getNode("model", sbmlNode.getChildNodes()); + if (modelNode == null) { + throw new InvalidInputDataExecption("No model node in SBML"); + } + // we ignore metaid - it's useless and obstruct data model + // model.setMetaId(getNodeAttr("metaId", modelNode)); + model.setIdModel(getNodeAttr("id", modelNode)); + + Node compartmentNode = getNode("listOfCompartments", modelNode.getChildNodes()); + if (compartmentNode != null) { + List<CellDesignerCompartment> compartments = compartmentCollectionXmlParser.parseXmlCompartmentCollection(compartmentNode); + elements.addElements(compartments); + } - InternalModelSpeciesData modelData = new InternalModelSpeciesData(); + InternalModelSpeciesData modelData = new InternalModelSpeciesData(); - Node speciesNode = getNode("listOfSpecies", modelNode.getChildNodes()); - if (speciesNode != null) { - List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode); - modelData.updateSpecies(species); - } - Node reactionsNode = null; - - NodeList nodes = modelNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("annotation")) { - continue; - } else if (node.getNodeName().equalsIgnoreCase("listOfSpecies")) { - continue; - } else if (node.getNodeName().equalsIgnoreCase("listOfReactions")) { - reactionsNode = node; - } else if (node.getNodeName().equalsIgnoreCase("listOfCompartments")) { - // we already parsed compartemnts - continue; - } else if (node.getNodeName().equalsIgnoreCase("notes")) { - String notes = rap.getNotes(node); - if (notes != null) { - notes = StringEscapeUtils.unescapeHtml4(notes); - } - model.setNotes(notes); - } else if (node.getNodeName().equalsIgnoreCase("listOfUnitDefinitions")) { - continue; // we can ignore unit definitions - } else { - throw new InvalidInputDataExecption("Unknown element of model: " + node.getNodeName()); + Node speciesNode = getNode("listOfSpecies", modelNode.getChildNodes()); + if (speciesNode != null) { + List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode); + modelData.updateSpecies(species); + } + Node reactionsNode = null; + + NodeList nodes = modelNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("annotation")) { + continue; + } else if (node.getNodeName().equalsIgnoreCase("listOfSpecies")) { + continue; + } else if (node.getNodeName().equalsIgnoreCase("listOfReactions")) { + reactionsNode = node; + } else if (node.getNodeName().equalsIgnoreCase("listOfCompartments")) { + // we already parsed compartemnts + continue; + } else if (node.getNodeName().equalsIgnoreCase("notes")) { + String notes = rap.getNotes(node); + if (notes != null) { + notes = StringEscapeUtils.unescapeHtml4(notes); } + model.setNotes(notes); + } else if (node.getNodeName().equalsIgnoreCase("listOfUnitDefinitions")) { + continue; // we can ignore unit definitions + } else { + throw new InvalidInputDataExecption("Unknown element of model: " + node.getNodeName()); } } + } - Node annotationNode = getNode("annotation", modelNode.getChildNodes()); - if (annotationNode == null) { - throw new InvalidInputDataExecption("No annotation node in SBML/model"); - } + Node annotationNode = getNode("annotation", modelNode.getChildNodes()); + if (annotationNode == null) { + throw new InvalidInputDataExecption("No annotation node in SBML/model"); + } - parseAnnotation(model, annotationNode, modelData, elements); + parseAnnotation(model, annotationNode, modelData, elements); - if (speciesNode != null) { - List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode); - modelData.updateSpecies(species); - } + if (speciesNode != null) { + List<Pair<String, ? extends CellDesignerSpecies<?>>> species = speciesSbmlParser.parseSbmlSpeciesCollection(speciesNode); + modelData.updateSpecies(species); + } - if (reactionsNode != null) { - ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements); - List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode); - model.addReactions(reactions); - } + if (reactionsNode != null) { + ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements); + List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode); + model.addReactions(reactions); + } - if (params.isSizeAutoAdjust()) { - Rectangle2D bound = getModelBound(model); - double width = bound.getWidth() + 2 * (Math.max(0, bound.getX())); - double height = bound.getHeight() + 2 * (Math.max(0, bound.getY())); + if (params.isSizeAutoAdjust()) { + Rectangle2D bound = getModelBound(model); + double width = bound.getWidth() + 2 * (Math.max(0, bound.getX())); + double height = bound.getHeight() + 2 * (Math.max(0, bound.getY())); - model.setWidth(width); - model.setHeight(height); - } - } catch (InvalidXmlSchemaException e) { - throw new InvalidInputDataExecption(e); - } catch (UnknownReactionClassException e) { - String type = e.getReactionType(); - String reactionId = e.getReactionId(); - String newType = null; - if ("CATALYSIS".equalsIgnoreCase(type)) { - newType = "positive influence"; - } else if ("INHIBITION".equalsIgnoreCase(type)) { - newType = "negative influence"; - } else if ("UNKNOWN_CATALYSIS".equalsIgnoreCase(type)) { - newType = "unknown positive influence"; - } else if ("UNKNOWN_INHIBITION".equalsIgnoreCase(type)) { - newType = "unknown negative influence"; - } else if ("PHYSICAL_STIMULATION".equalsIgnoreCase(type)) { - newType = "reduced physical stimulation"; - } else if ("MODULATION".equalsIgnoreCase(type)) { - newType = "reduced modulation"; - } else if ("TRIGGER".equalsIgnoreCase(type)) { - newType = "reduced trigger"; - } else { - throw new InvalidInputDataExecption(e); - } - throw new InvalidInputDataExecption( - "Reaction type \"" + type + "\" is inappropriate for reaction " + reactionId + ". Suggested type: " + newType - + " in the \"Reduced\" notation of CellDesigner.", - e); - } catch (CellDesignerParserException e) { + model.setWidth(width); + model.setHeight(height); + } + } catch (InvalidXmlSchemaException e) { + throw new InvalidInputDataExecption(e); + } catch (UnknownReactionClassException e) { + String type = e.getReactionType(); + String reactionId = e.getReactionId(); + String newType = null; + if ("CATALYSIS".equalsIgnoreCase(type)) { + newType = "positive influence"; + } else if ("INHIBITION".equalsIgnoreCase(type)) { + newType = "negative influence"; + } else if ("UNKNOWN_CATALYSIS".equalsIgnoreCase(type)) { + newType = "unknown positive influence"; + } else if ("UNKNOWN_INHIBITION".equalsIgnoreCase(type)) { + newType = "unknown negative influence"; + } else if ("PHYSICAL_STIMULATION".equalsIgnoreCase(type)) { + newType = "reduced physical stimulation"; + } else if ("MODULATION".equalsIgnoreCase(type)) { + newType = "reduced modulation"; + } else if ("TRIGGER".equalsIgnoreCase(type)) { + newType = "reduced trigger"; + } else { throw new InvalidInputDataExecption(e); } - - Logger.getRootLogger().removeAppender(appender); - model.addLoggingInfo(appender); - return model; - } finally { - Logger.getRootLogger().removeAppender(appender); + throw new InvalidInputDataExecption( + "Reaction type \"" + type + "\" is inappropriate for reaction " + reactionId + ". Suggested type: " + newType + + " in the \"Reduced\" notation of CellDesigner.", + e); + } catch (CellDesignerParserException e) { + throw new InvalidInputDataExecption(e); } + + return model; } /** @@ -451,7 +440,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { if (!species.getElementId().equals("")) { elements.addElement(species); } else { - model.addCreationWarning( + logger.warn( "Species (class: " + species.getClass().getName() + ", name: " + species.getName() + ") exists in CD file, but is never instantiated. It's CellDesigner file problem."); } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java index c0d6c8925f83df9142dd484f57f26aa52b6fcf20..ac9d237edfe67225d9b64bd99c7e6ee74332b30f 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java @@ -24,9 +24,9 @@ import lcsb.mapviewer.model.map.MiriamType; 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.Element; import lcsb.mapviewer.model.map.species.AntisenseRna; import lcsb.mapviewer.model.map.species.Complex; +import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.model.map.species.Rna; @@ -310,8 +310,8 @@ public class ComplexParserTests extends CellDesignerTestFunctions { @Test public void testWarningInParser() throws Exception { try { - Model model = getModelForFile("testFiles/problematic/invalid_elements_name.xml"); - assertTrue(model.getCreationWarnings().size() > 0); + getModelForFile("testFiles/problematic/invalid_elements_name.xml"); + assertTrue(getWarnings().size() > 0); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java b/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java index 95d5bd72fed6b4f9083e1d0f8e725737cf675162..adc4fbff1c1912131303412721531f3133b0e74a 100644 --- a/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java +++ b/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java @@ -36,8 +36,8 @@ import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; import lcsb.mapviewer.model.map.model.SubmodelType; import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Complex; +import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Phenotype; import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.model.map.species.Species; @@ -59,11 +59,12 @@ public class ComplexZipConverter<T extends IConverter> { * stream. */ private static final int BUFFER_SIZE = 1024; + /** * Default class logger. */ - @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(ComplexZipConverter.class); + /** * Class used to create single submap from a file. */ @@ -202,31 +203,27 @@ public class ComplexZipConverter<T extends IConverter> { */ public void processReaction(String mapping, Map<String, Model> nameModelMap, Model topModel, Reaction reaction) { if (reaction.getReactants().size() > 1) { - topModel.addCreationWarning( - "[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains too many reactants. Skipped"); + logger.warn("[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains too many reactants. Skipped"); } else if (reaction.getProducts().size() > 1) { - topModel.addCreationWarning( - "[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains too many products. Skipped"); + logger.warn("[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains too many products. Skipped"); } else if (reaction.getModifiers().size() > 0) { - topModel - .addCreationWarning("[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains modifiers. Skipped"); + logger.warn("[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains modifiers. Skipped"); } else { Element fromAlias = reaction.getReactants().get(0).getElement(); Element toAlias = reaction.getProducts().get(0).getElement(); if (!(fromAlias instanceof Species)) { - topModel.addCreationWarning( - "[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains doesn't start in species. Skipped"); + logger + .warn("[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains doesn't start in species. Skipped"); } else if (!(toAlias instanceof Species)) { - topModel.addCreationWarning( - "[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains doesn't end in species. Skipped"); + logger.warn("[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains doesn't end in species. Skipped"); } else { Complex complexFrom = ((Species) fromAlias).getComplex(); Complex complexTo = ((Species) toAlias).getComplex(); if (complexFrom == null) { - topModel.addCreationWarning( + logger.warn( "[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains doesn't start inside complex. Skipped"); } else if (complexTo == null && (!(toAlias instanceof Complex))) { - topModel.addCreationWarning( + logger.warn( "[SUBMODEL MAPPING] Reaction " + reaction.getIdReaction() + " in mapping file (" + mapping + ") contains doesn't end inside complex. Skipped"); } else { if (complexTo == null) { diff --git a/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java b/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java index 8060021ba71c66965135eb29bfb3d4f5af56595c..e17ac596abfc01b292edf3e731403967135a2972 100644 --- a/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java +++ b/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java @@ -36,13 +36,15 @@ import lcsb.mapviewer.model.map.reaction.Product; import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.type.TransportReaction; -import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Complex; +import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Phenotype; import lcsb.mapviewer.model.map.species.Species; public class ComplexZipConverterTest { + + @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(ComplexZipConverterTest.class); private abstract class AbstractConverter implements IConverter { @@ -492,10 +494,7 @@ public class ComplexZipConverterTest { params.entry(new ModelZipEntryFile("main.xml", "main", true, false, null)); params.entry(new ModelZipEntryFile("mapping.xml", null, false, true, null)); try { - Model model = converter.createModel(params); - for (String string : model.getCreationWarnings()) { - logger.debug(string); - } + converter.createModel(params); fail("Exception expected"); } catch (InvalidArgumentException e) { diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java index 02a8aac49a6fcdbb036f7c180c5c6c0aec8a70ef..070d2109aeb85b503b677f6baa6b8d64b4d2a450 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java @@ -36,6 +36,7 @@ public class CopyCommand extends NewModelCommand { /** * Defaul class logger. */ + @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(CopyCommand.class); /** @@ -54,7 +55,7 @@ public class CopyCommand extends NewModelCommand { * @return copy of the model */ public Model execute() { - Map<Model, Model> copies = new HashMap<Model, Model>(); + Map<Model, Model> copies = new HashMap<>(); Model model = getModel(); @@ -70,7 +71,6 @@ public class CopyCommand extends NewModelCommand { } } if (parent != null) { - logger.warn("Dirty copying of submodel"); CopyCommand copyParentCommand = new CopyCommand(parent.getParentModel().getModel()); Model copy = copyParentCommand.execute(); for (ModelSubmodelConnection submodel : copy.getSubmodelConnections()) { @@ -258,8 +258,6 @@ public class CopyCommand extends NewModelCommand { copy.setIdModel(original.getIdModel()); copy.setZoomLevels(original.getZoomLevels()); copy.setTileSize(original.getTileSize()); - - copy.addCreationWarnings(original.getCreationWarnings()); } /** diff --git a/model/src/main/java/lcsb/mapviewer/model/Project.java b/model/src/main/java/lcsb/mapviewer/model/Project.java index ba235988a14662705b353facc9b89fd8f99bd224..3dd760de58e3ba51f01a07ef79a4808835642d59 100644 --- a/model/src/main/java/lcsb/mapviewer/model/Project.java +++ b/model/src/main/java/lcsb/mapviewer/model/Project.java @@ -1,7 +1,9 @@ package lcsb.mapviewer.model; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.persistence.Basic; @@ -15,10 +17,14 @@ import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; +import org.apache.log4j.Appender; import org.apache.log4j.Logger; +import org.apache.log4j.spi.LoggingEvent; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; +import lcsb.mapviewer.common.EventStorageLoggerAppender; +import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelData; @@ -37,7 +43,6 @@ public class Project implements Serializable { /** * Default class logger. */ - @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(Project.class); /** @@ -91,12 +96,18 @@ public class Project implements Serializable { */ private String errors = null; + /** + * Short description of the map. + */ + @Column(columnDefinition = "TEXT") + private String warnings; + /** * Map models in the project. */ @Cascade({ CascadeType.ALL }) @OneToMany(mappedBy = "project", orphanRemoval = true) - private Set<ModelData> models = new HashSet<ModelData>(); + private Set<ModelData> models = new HashSet<>(); /** * Here we store input file. @@ -365,4 +376,88 @@ public class Project implements Serializable { public MiriamData getOrganism() { return organism; } + + /** + * Adds a warning to a list of warnings generated during model creation. + * + * @param warning + * warning to add + */ + public void addWarning(String warning) { + if (warning.trim().contains("\n")) { + throw new InvalidArgumentException("Warning must be one line of text"); + } + if (warning.trim().equals("")) { + return; + } + if (warnings == null) { + warnings = warning.trim(); + } else { + warnings = warnings + "\n" + warning.trim(); + } + } + + /** + * Returns list of warnings set during creation of mode. + * + * @return list of warnings set during creation of mode + */ + public List<String> getWarnings() { + List<String> result = new ArrayList<>(); + if (warnings == null) { + return result; + } + String[] warningsArray = warnings.split("\n"); + for (String string : warningsArray) { + result.add(string); + } + return result; + } + + /** + * Adds warnings to a list of warnings generated during model creation. + * + * @param warnings + * list of warnings to add + */ + public void addWarnings(List<String> warnings) { + StringBuilder sb = new StringBuilder(""); + if (this.warnings != null) { + sb.append(this.warnings); + } + for (String string : warnings) { + if (string.trim().equals("")) { + continue; + } + if (string.contains("\n")) { + throw new InvalidArgumentException("Warning must be one line of text, but found:\n" + string); + } + if (sb.length() > 0) { + sb.append("\n"); + } + sb.append(string.trim()); + } + if (sb.length() != 0) { + this.warnings = sb.toString(); + } + } + + /** + * Adds warning log information to a project. + * + * @param appender + * {@link Appender log4j appender} that gathered logs + */ + public void addLoggingInfo(EventStorageLoggerAppender appender) { + List<String> warnings = new ArrayList<>(); + for (LoggingEvent event : appender.getWarnings()) { + if (event.getMessage() instanceof String) { + warnings.add(((String) event.getMessage()).replaceAll("\n", "_NEW_LINE_")); + } else { + logger.warn("Unknown message class: " + event.getClass()); + } + } + addWarnings(warnings); + } + } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/model/Model.java b/model/src/main/java/lcsb/mapviewer/model/map/model/Model.java index eaaa741a2baf098789efd892457461715fb846be..198209731d452f3f01ca8da3119ca6703aabe3a5 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/model/Model.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/model/Model.java @@ -5,9 +5,6 @@ import java.util.Collection; import java.util.List; import java.util.Set; -import org.apache.log4j.Appender; - -import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.MiriamData; @@ -121,7 +118,8 @@ public interface Model { Set<Element> getElements(); /** - * Returns element with the given element identfier ({@link Element#elementId}). + * Returns element with the given element identfier ({@link Element#elementId} + * ). * * @param idElement * element identifier @@ -220,29 +218,6 @@ public interface Model { */ void addBlockDiagream(BlockDiagram blockDiagram); - /** - * Adds warnings to a list of warnings generated during model creation. - * - * @param warnings - * list of warnings to add - */ - void addCreationWarnings(List<String> warnings); - - /** - * Returns list of warnings set during creation of mode. - * - * @return list of warnings set during creation of mode - */ - List<String> getCreationWarnings(); - - /** - * Adds a warning to a list of warnings generated during model creation. - * - * @param warning - * warning to add - */ - void addCreationWarning(String warning); - /** * @param notifyEmail * the notifyEmail to set @@ -666,13 +641,4 @@ public interface Model { * @return list od all {@link AnnotatedObject} in the map */ List<AnnotatedObject> getAnnotatedObjects(); - - /** - * Adds warning log information to a model. - * - * @param appender - * {@link Appender log4j appender} that gathered logs - */ - void addLoggingInfo(EventStorageLoggerAppender appender); - } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/model/ModelData.java b/model/src/main/java/lcsb/mapviewer/model/map/model/ModelData.java index c957eea0078d25f0bfe49688313137b0f1857b82..81632a39d66299421e7f733cc3807eabb722fd72 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/model/ModelData.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/model/ModelData.java @@ -82,7 +82,7 @@ public class ModelData implements Serializable { */ @Cascade({ CascadeType.ALL }) @OneToMany(mappedBy = "model", orphanRemoval = true) - private Set<Layer> layers = new HashSet<Layer>(); + private Set<Layer> layers = new HashSet<>(); /** * Unique database identifier. @@ -100,7 +100,7 @@ public class ModelData implements Serializable { */ @Cascade({ CascadeType.ALL }) @OneToMany(mappedBy = "model", orphanRemoval = true) - private Set<Reaction> reactions = new HashSet<Reaction>(); + private Set<Reaction> reactions = new HashSet<>(); /** * Version of the map. @@ -143,11 +143,6 @@ public class ModelData implements Serializable { */ private String notifyEmail; - /** - * Short description of the map. - */ - @Column(columnDefinition = "TEXT") - private String creationWarnings; /** * How many hierarchical levels are in this map. @@ -170,7 +165,7 @@ public class ModelData implements Serializable { @Cascade({ CascadeType.ALL }) @OneToMany(fetch = FetchType.EAGER, mappedBy = "model", orphanRemoval = true) @OrderBy("id") - private List<Layout> layouts = new ArrayList<Layout>(); + private List<Layout> layouts = new ArrayList<>(); /** * Project to which this model belong to. @@ -192,7 +187,7 @@ public class ModelData implements Serializable { */ @Cascade({ CascadeType.ALL }) @OneToMany(fetch = FetchType.EAGER, mappedBy = "parentModel", orphanRemoval = true) - private Set<ModelSubmodelConnection> submodels = new HashSet<ModelSubmodelConnection>(); + private Set<ModelSubmodelConnection> submodels = new HashSet<>(); /** * List of connections with parent model (by definition one map can be a @@ -200,7 +195,7 @@ public class ModelData implements Serializable { */ @Cascade({ CascadeType.ALL }) @OneToMany(fetch = FetchType.LAZY, mappedBy = "submodel") - private Set<SubmodelConnection> parentModels = new HashSet<SubmodelConnection>(); + private Set<SubmodelConnection> parentModels = new HashSet<>(); /** * List of overview images describing this model. This list should be set only @@ -211,7 +206,7 @@ public class ModelData implements Serializable { @Cascade({ CascadeType.ALL }) @OneToMany(mappedBy = "model", orphanRemoval = true) @OrderBy("id") - private List<OverviewImage> overviewImages = new ArrayList<OverviewImage>(); + private List<OverviewImage> overviewImages = new ArrayList<>(); /** * List of {@link DataMiningSet} in the model. These data mining sets are used @@ -220,7 +215,7 @@ public class ModelData implements Serializable { @Cascade({ CascadeType.ALL }) @OneToMany(mappedBy = "model", orphanRemoval = true) @OrderBy("id") - private List<DataMiningSet> dataMiningSets = new ArrayList<DataMiningSet>(); + private List<DataMiningSet> dataMiningSets = new ArrayList<>(); /** * Default constructor. @@ -546,71 +541,6 @@ public class ModelData implements Serializable { this.notifyEmail = notifyEmail; } - /** - * Adds a warning to a list of warnings generated during model creation. - * - * @param warning - * warning to add - */ - public void addCreationWarning(String warning) { - if (warning.trim().contains("\n")) { - throw new InvalidArgumentException("Warning must be one line of text"); - } - if (warning.trim().equals("")) { - return; - } - if (creationWarnings == null) { - creationWarnings = warning.trim(); - } else { - creationWarnings = creationWarnings + "\n" + warning.trim(); - } - } - - /** - * Returns list of warnings set during creation of mode. - * - * @return list of warnings set during creation of mode - */ - public List<String> getCreationWarnings() { - List<String> result = new ArrayList<String>(); - if (creationWarnings == null) { - return result; - } - String[] warnings = creationWarnings.split("\n"); - for (String string : warnings) { - result.add(string); - } - return result; - } - - /** - * Adds warnings to a list of warnings generated during model creation. - * - * @param warnings - * list of warnings to add - */ - public void addCreationWarnings(List<String> warnings) { - StringBuilder sb = new StringBuilder(""); - if (creationWarnings != null) { - sb.append(creationWarnings); - } - for (String string : warnings) { - if (string.trim().equals("")) { - continue; - } - if (string.contains("\n")) { - throw new InvalidArgumentException("Warning must be one line of text, but found:\n" + string); - } - if (sb.length() > 0) { - sb.append("\n"); - } - sb.append(string.trim()); - } - if (sb.length() != 0) { - creationWarnings = sb.toString(); - } - } - /** * @return the model * @see #model diff --git a/model/src/main/java/lcsb/mapviewer/model/map/model/ModelFullIndexed.java b/model/src/main/java/lcsb/mapviewer/model/map/model/ModelFullIndexed.java index 80e382b845be31d8c23888d6ad406b4c71135519..920e5f16de1d6b69f8ced1e64b58ea072b285923 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/model/ModelFullIndexed.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/model/ModelFullIndexed.java @@ -11,9 +11,7 @@ import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; -import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.AnnotatedObject; @@ -474,21 +472,6 @@ public class ModelFullIndexed implements Model { modelData.setNotifyEmail(notifyEmail); } - @Override - public void addCreationWarning(String warning) { - modelData.addCreationWarning(warning); - } - - @Override - public List<String> getCreationWarnings() { - return modelData.getCreationWarnings(); - } - - @Override - public void addCreationWarnings(List<String> warnings) { - modelData.addCreationWarnings(warnings); - } - @Override public ModelData getModelData() { return modelData; @@ -694,19 +677,6 @@ public class ModelFullIndexed implements Model { return result; } - @Override - public void addLoggingInfo(EventStorageLoggerAppender appender) { - List<String> warnings = new ArrayList<>(); - for (LoggingEvent event : appender.getWarnings()) { - if (event.getMessage() instanceof String) { - warnings.add(((String) event.getMessage()).replaceAll("\n", "_NEW_LINE_")); - } else { - logger.warn("Unknown message class: " + event.getClass()); - } - } - addCreationWarnings(warnings); - } - @Override public List<Element> getElementsByName(String name) { List<Element> result = new ArrayList<>(); diff --git a/model/src/test/java/lcsb/mapviewer/model/ProjectTest.java b/model/src/test/java/lcsb/mapviewer/model/ProjectTest.java index 917ebae588b496ca276621eaf5dfa8be8574c690..ec95a2738e445d55b50cba9db379c214ccaa0ce5 100644 --- a/model/src/test/java/lcsb/mapviewer/model/ProjectTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/ProjectTest.java @@ -2,22 +2,30 @@ package lcsb.mapviewer.model; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.apache.commons.lang3.SerializationUtils; +import org.apache.log4j.Logger; +import org.apache.log4j.spi.LoggingEvent; import org.junit.After; import org.junit.Before; import org.junit.Test; import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.EventStorageLoggerAppender; +import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelFullIndexed; public class ProjectTest { + Logger logger = Logger.getLogger(ProjectTest.class); @Before public void setUp() throws Exception { @@ -127,4 +135,126 @@ public class ProjectTest { } } + @Test + public void testAddCreationWarning() { + try { + Project md = new Project(); + md.addWarning("text\ntext"); + + fail("Exception expected"); + } catch (InvalidArgumentException e) { + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCreationWarning2() { + try { + Project md = new Project(); + md.addWarning(""); + List<String> warnings = md.getWarnings(); + assertEquals(0, warnings.size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCreationWarning3() { + try { + Project md = new Project(); + md.addWarning("xqw"); + List<String> warnings = md.getWarnings(); + assertEquals(1, warnings.size()); + assertEquals("xqw", warnings.get(0)); + + md.addWarning("WER"); + warnings = md.getWarnings(); + assertEquals(2, warnings.size()); + assertEquals("WER", warnings.get(1)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCreationWarnings() { + try { + List<String> warnings = new ArrayList<>(); + warnings.add("xqw"); + warnings.add("aso"); + warnings.add(""); + Project project = new Project(); + project.addWarnings(warnings); + + project.addWarning("WER"); + warnings = project.getWarnings(); + assertEquals(3, warnings.size()); + assertEquals("aso", warnings.get(1)); + + project.addWarnings(warnings); + warnings = project.getWarnings(); + assertEquals(6, warnings.size()); + assertEquals("aso", warnings.get(1)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCreationWarnings2() { + try { + List<String> warnings = new ArrayList<>(); + warnings.add("xqw\nwer\nt"); + Project md = new Project(); + md.addWarnings(warnings); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCreationWarnings3() { + try { + List<String> warnings = new ArrayList<>(); + Project md = new Project(); + md.addWarnings(warnings); + assertEquals(0, md.getWarnings().size()); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddLoggingInfo() { + try { + Project project = new Project(); + EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); + logger.addAppender(appender); + logger.warn("test"); + logger.warn("test2"); + LoggingEvent event = appender.getWarnings().get(0); + appender.getWarnings().add(new LoggingEvent("St", event.getLogger(), null, new Object(), null)); + logger.removeAppender(appender); + + project.addLoggingInfo(appender); + assertEquals(2, project.getWarnings().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + } diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java index aad0ee4aae9aeb687f5b2603c4cb740dfea00531..000ca61d9449e91062a5ea331a5a0bf463f3d8cd 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java @@ -205,106 +205,6 @@ public class ModelDataTest { } } - @Test - public void testAddCreationWarning() { - try { - ModelData md = new ModelData(); - md.addCreationWarning("text\ntext"); - - fail("Exception expected"); - } catch (InvalidArgumentException e) { - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCreationWarning2() { - try { - ModelData md = new ModelData(); - md.addCreationWarning(""); - List<String> warnings = md.getCreationWarnings(); - assertEquals(0, warnings.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCreationWarning3() { - try { - ModelData md = new ModelData(); - md.addCreationWarning("xqw"); - List<String> warnings = md.getCreationWarnings(); - assertEquals(1, warnings.size()); - assertEquals("xqw", warnings.get(0)); - - md.addCreationWarning("WER"); - warnings = md.getCreationWarnings(); - assertEquals(2, warnings.size()); - assertEquals("WER", warnings.get(1)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCreationWarnings() { - try { - List<String> warnings = new ArrayList<>(); - warnings.add("xqw"); - warnings.add("aso"); - warnings.add(""); - ModelData md = new ModelData(); - md.addCreationWarnings(warnings); - - md.addCreationWarning("WER"); - warnings = md.getCreationWarnings(); - assertEquals(3, warnings.size()); - assertEquals("aso", warnings.get(1)); - - md.addCreationWarnings(warnings); - warnings = md.getCreationWarnings(); - assertEquals(6, warnings.size()); - assertEquals("aso", warnings.get(1)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCreationWarnings2() { - try { - List<String> warnings = new ArrayList<>(); - warnings.add("xqw\nwer\nt"); - ModelData md = new ModelData(); - md.addCreationWarnings(warnings); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCreationWarnings3() { - try { - List<String> warnings = new ArrayList<>(); - ModelData md = new ModelData(); - md.addCreationWarnings(warnings); - assertEquals(0, md.getCreationWarnings().size()); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } @Test public void testAddSubmodel() { diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelFullIndexedTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelFullIndexedTest.java index ed871452d4c59498b942a521815d739d1d9a5862..8fdcfd03523fcabff5167c03291cbb17a760fae2 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelFullIndexedTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelFullIndexedTest.java @@ -14,14 +14,12 @@ import java.util.List; import java.util.Set; import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.AnnotatedObject; @@ -118,7 +116,7 @@ public class ModelFullIndexedTest { assertEquals(1, elements.size()); assertEquals(0, unkElements.size()); - + } catch (Exception e) { e.printStackTrace(); throw e; @@ -136,11 +134,10 @@ public class ModelFullIndexedTest { model.addElement(protein2); model.addElement(new Compartment("compId")); - List<Species> speciesList = model.getSpeciesList(); - + assertEquals(2, speciesList.size()); - + } catch (Exception e) { e.printStackTrace(); throw e; @@ -200,20 +197,6 @@ public class ModelFullIndexedTest { } } - @Test - public void testAddCreationWarning() { - try { - ModelFullIndexed model = new ModelFullIndexed(null); - model.addCreationWarning("str"); - - assertEquals(1, model.getCreationWarnings().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test public void testAddSpeciesWithParent() { try { @@ -447,7 +430,6 @@ public class ModelFullIndexedTest { } } - @Test public void testAddInvalidElement2() { try { @@ -806,7 +788,6 @@ public class ModelFullIndexedTest { String notifyEmail = "email@email.lu"; String idModel = "model_ID"; Calendar creationDate = Calendar.getInstance(); - List<String> warnings = new ArrayList<>(); boolean sbgnFormat = true; model.setWidth(widthStr); @@ -850,8 +831,6 @@ public class ModelFullIndexedTest { assertEquals(creationDate, model.getCreationDate()); model.setMapVersion(mapVersion); assertEquals(mapVersion, model.getMapVersion()); - model.addCreationWarnings(warnings); - assertEquals(warnings, model.getCreationWarnings()); model.setSbgnFormat(sbgnFormat); assertEquals(sbgnFormat, model.isSbgnFormat()); @@ -883,25 +862,4 @@ public class ModelFullIndexedTest { } } - @Test - public void testAddLoggingInfo() { - try { - ModelFullIndexed model = new ModelFullIndexed(null); - EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); - logger.addAppender(appender); - logger.warn("test"); - logger.warn("test2"); - LoggingEvent event = appender.getWarnings().get(0); - appender.getWarnings().add(new LoggingEvent("St", event.getLogger(), null, new Object(), null)); - logger.removeAppender(appender); - - model.addLoggingInfo(appender); - assertEquals(2, model.getCreationWarnings().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - } diff --git a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/ImportExport.java b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/ImportExport.java index e4de0af6b3305917b7b8a88e952d8df19a625f4f..31511781b93c5625331b6f4c2c28211ddf07d8f7 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/ImportExport.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/ImportExport.java @@ -151,7 +151,12 @@ public class ImportExport implements Plugin { /** * {@link Model} that was created using this {@link PathwayExporter}. */ - private Model model = null; + private Model model = null; + + /** + * List of export warnings. + */ + private List<String> warnings = new ArrayList<>(); @Override public String[] getExtensions() { @@ -165,29 +170,52 @@ public class ImportExport implements Plugin { @Override public List<String> getWarnings() { - if (model == null) { - logger.warn("Getting warnings without parsing"); - return new ArrayList<>(); - } - return model.getCreationWarnings(); + return warnings; } @Override public void doExport(File file, Pathway pathway) throws ConverterException { + EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); try { + Logger.getRootLogger().addAppender(appender); pathway.writeToXml(new File("tmp.gpml"), false); model = new GPMLToModel().getModel("tmp.gpml"); - model.addCreationWarning("Please manually change extension of saved file from .cell to .xml"); + + Logger.getRootLogger().removeAppender(appender); + warnings = createWarnings(appender); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model); PrintWriter writer = new PrintWriter(file.getPath(), "UTF-8"); writer.println(xml); writer.close(); + + warnings.add("Please manually change extension of saved file from .cell to .xml"); } catch (Exception e) { logger.error(e.getMessage(), e); throw new ConverterException(e); + } finally { + Logger.getRootLogger().removeAppender(appender); + } + } + + /** + * Creates list of warnings from log4j appender data. + * + * @param appender + * appender with the logs + * @return list of warnings from log4j appender data + */ + private List<String> createWarnings(EventStorageLoggerAppender appender) { + List<String> warnings = new ArrayList<>(); + for (LoggingEvent event : appender.getWarnings()) { + if (event.getMessage() instanceof String) { + warnings.add(((String) event.getMessage()).replaceAll("\n", "_NEW_LINE_")); + } else { + logger.warn("Unknown message class: " + event.getClass()); + } } + return warnings; } } } diff --git a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GPMLToModel.java b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GPMLToModel.java index 5522e76654bb81b743de852aa000c7c13cb9690e..52e273300c88f0aa5e84c74b97b46da01d01ae89 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GPMLToModel.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/GPMLToModel.java @@ -4,9 +4,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.converter.ConverterException; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.wikipathway.model.Graph; @@ -31,17 +28,9 @@ public class GPMLToModel { * thrown when model couldn't be created */ public Model getModel(InputStream stream) throws IOException, ConverterException { - EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); - try { - Logger.getRootLogger().addAppender(appender); - Graph graph = new GpmlParser().createGraph(stream); - Logger.getRootLogger().removeAppender(appender); - Model model = new ModelContructor().getModel(graph); - model.addLoggingInfo(appender); - return model; - } finally { - Logger.getRootLogger().removeAppender(appender); - } + Graph graph = new GpmlParser().createGraph(stream); + Model model = new ModelContructor().getModel(graph); + return model; } /** 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 6ccd58e182e43cac1244390fd2a900e75ae3aa0a..4d4440f15a348c59e3318c403dd8ae5d98b3ee00 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java @@ -16,7 +16,6 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.log4j.Logger; import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidStateException; @@ -886,9 +885,7 @@ public class ModelContructor { * */ public Model getModel(Graph graph) throws ConverterException { - EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); try { - Logger.getRootLogger().addAppender(appender); Data data = new Data(); Model model = new ModelFullIndexed(null); model.setWidth(graph.getBoardWidth()); @@ -940,13 +937,9 @@ public class ModelContructor { putAliasesIntoCompartments(model); - Logger.getRootLogger().removeAppender(appender); - model.addLoggingInfo(appender); return model; } catch (UnknownChildClassException e) { throw new ConverterException(e); - } finally { - Logger.getRootLogger().removeAppender(appender); } } diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java index 7b8690e29c538a6a83e900b3754e1b1e088d124f..9ddcf820eebd6a4ea86a5bf74c4c6a4e9ebed315 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ComplexReactionToModelTest.java @@ -21,7 +21,7 @@ import lcsb.mapviewer.wikipathway.XML.GPMLToModel; import org.apache.log4j.Logger; import org.junit.Test; -public class ComplexReactionToModelTest { +public class ComplexReactionToModelTest extends WikipathwaysTestFunctions{ /** * Default class logger. */ @@ -41,7 +41,7 @@ public class ComplexReactionToModelTest { assertEquals(1, reaction.getReactants().size()); assertEquals(1, reaction.getProducts().size()); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -62,7 +62,7 @@ public class ComplexReactionToModelTest { assertEquals(2, reaction.getReactants().size()); assertEquals(1, reaction.getProducts().size()); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -83,7 +83,7 @@ public class ComplexReactionToModelTest { assertEquals(1, reaction.getReactants().size()); assertEquals(2, reaction.getProducts().size()); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -106,7 +106,7 @@ public class ComplexReactionToModelTest { Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2)); - assertEquals(7, model1.getCreationWarnings().size()); + assertEquals(7, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); @@ -130,7 +130,7 @@ public class ComplexReactionToModelTest { Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false)); assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2)); - assertEquals(3, model1.getCreationWarnings().size()); + assertEquals(3, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); @@ -156,7 +156,7 @@ public class ComplexReactionToModelTest { assertEquals("File " + fileName + " different after transformation", 0, mc.compare(model1, model2)); - assertEquals(5, model1.getCreationWarnings().size()); + assertEquals(5, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); @@ -181,7 +181,7 @@ public class ComplexReactionToModelTest { assertFalse(Color.BLACK.equals(redAlias.getColor())); assertTrue(Color.WHITE.equals(blackAlias.getColor())); - assertEquals(1, model.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -206,7 +206,7 @@ public class ComplexReactionToModelTest { assertEquals(4, lineCount); - assertEquals(1, model.getCreationWarnings().size()); + 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 e7c8ca27736ee50f28d23e12d0412184b65e6965..00c46bbbc7fcf0c4c6cb35aa560a01d763fc45f9 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/GPMLToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/GPMLToModelTest.java @@ -29,7 +29,7 @@ import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.wikipathway.XML.GPMLToModel; -public class GPMLToModelTest { +public class GPMLToModelTest extends WikipathwaysTestFunctions{ /** * Default class logger. */ @@ -45,7 +45,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(22, model1.getCreationWarnings().size()); + assertEquals(22, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); @@ -67,7 +67,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(22, model1.getCreationWarnings().size()); + assertEquals(22, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); @@ -90,7 +90,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(15, model1.getCreationWarnings().size()); + assertEquals(15, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); @@ -112,7 +112,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(16, model1.getCreationWarnings().size()); + assertEquals(16, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -135,7 +135,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(3, model1.getCreationWarnings().size()); + assertEquals(3, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -158,7 +158,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(38, model1.getCreationWarnings().size()); + assertEquals(38, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -182,7 +182,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(41, model1.getCreationWarnings().size()); + assertEquals(41, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -206,7 +206,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(20, model1.getCreationWarnings().size()); + assertEquals(22, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -230,7 +230,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(48, model1.getCreationWarnings().size()); + assertEquals(48, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -254,7 +254,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile + fileName); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -279,7 +279,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile); assertEquals(2, model1.getReactions().iterator().next().getMiriamData().size()); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -304,7 +304,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile); assertTrue(model1.getNotes().contains("Metabolic Process")); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -328,7 +328,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile); - assertEquals(3, model1.getCreationWarnings().size()); + assertEquals(3, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -352,7 +352,7 @@ public class GPMLToModelTest { Model model1 = new GPMLToModel().getModel(pathToFile); - assertEquals(3, model1.getCreationWarnings().size()); + assertEquals(3, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); @@ -375,7 +375,7 @@ public class GPMLToModelTest { String fileName = "testFiles/small/model_with_line.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertEquals(1, model1.getLayers().iterator().next().getLines().size()); } catch (Exception e) { @@ -388,9 +388,9 @@ public class GPMLToModelTest { public void testModelShapes() throws Exception { try { String fileName = "testFiles/small/shapes.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); + new GPMLToModel().getModel(fileName); - assertEquals(11, model1.getCreationWarnings().size()); + assertEquals(11, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); @@ -407,7 +407,7 @@ public class GPMLToModelTest { assertTrue("Complex parsed from gpml should be hypothetical", species.isHypothetical()); } - assertEquals(0, model.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -422,7 +422,7 @@ public class GPMLToModelTest { for (Complex species : model.getComplexList()) { assertFalse("Complex parsed from gpml should be hypothetical", species.isHypothetical()); } - assertEquals(0, model.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -441,7 +441,7 @@ public class GPMLToModelTest { } } assertTrue("Complex parsed from gpml should have a valid name", nameFound); - assertEquals(1, model.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -456,7 +456,7 @@ public class GPMLToModelTest { for (Compartment compartment : model.getCompartments()) { assertEquals("Compartment parsed from gpml should have a valid name", "Label", compartment.getName()); } - assertEquals(0, model.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -507,7 +507,7 @@ public class GPMLToModelTest { assertEquals(0, mc.compare(model1, model2)); - assertEquals(2, model1.getCreationWarnings().size()); + assertEquals(2, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -528,7 +528,7 @@ public class GPMLToModelTest { assertEquals(0, mc.compare(model1, model2)); - assertEquals(54, model1.getCreationWarnings().size()); + assertEquals(54, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); throw e; @@ -578,7 +578,7 @@ public class GPMLToModelTest { try { String fileName = "testFiles/small/protein_with_modification.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); Gene protein = (Gene)model1.getElementByElementId("be3de"); assertNotNull(protein); @@ -603,7 +603,7 @@ public class GPMLToModelTest { try { String fileName = "testFiles/small/protein_with_modification_2.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); Gene protein = (Gene)model1.getElementByElementId("be3de"); assertNotNull(protein); @@ -634,7 +634,7 @@ public class GPMLToModelTest { double distance = reaction.getCenterPoint().distance(reaction.getModifiers().get(0).getLine().getEndPoint()); assertTrue("Modifier is too far from center point: " + distance, distance < ReactionCellDesignerConverter.RECT_SIZE); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); } catch (Exception e) { e.printStackTrace(); @@ -648,7 +648,7 @@ public class GPMLToModelTest { String fileName = "testFiles/small/reaction_to_label.gpml"; Model model1 = new GPMLToModel().getModel(fileName); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertEquals(1, model1.getReactions().size()); @@ -674,7 +674,7 @@ public class GPMLToModelTest { assertEquals(1, model1.getReactions().size()); assertEquals(3, model1.getReactions().iterator().next().getNodes().size()); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java index 5d9b66f3ee38a806a80d7741f73e77d2f509b40f..7fc254299ab01907c414605d1ba86e2a224725b2 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionElbowsTest.java @@ -1,875 +1,875 @@ -package lcsb.mapviewer.wikipathway; - -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 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 { - private final static double EPSILON = 1e-6; - - /** - * Default class logger. - */ - static Logger logger = Logger.getLogger(ReactionElbowsTest.class); - - 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); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(5, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionNorthToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionNorthToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(7, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionNorthToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_n_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionEastToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionEastToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(5, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionEastToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionEastToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_e_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(5, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionSouthToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(5, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionSouthToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionSouthToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(5, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionSouthToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_s_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionWestToNorth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_n.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionWestToEast() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_e.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(7, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionWestToSouth() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_s.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(6, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 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()); - - 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++; - } - } - - assertEquals(4, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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 LineReactionWestToWest() throws Exception { - try { - String fileName = "testFiles/elbow/elbow_line_w_w.gpml"; - Model model1 = new GPMLToModel().getModel(fileName); - - assertEquals(1, model1.getReactions().size()); - - 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++; - } - } - - assertEquals(5, lines); - - assertEquals(1, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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; - } - } - - private boolean isHvLine(Line2D line) { - return Math.abs(line.getX1() - line.getX2()) < EPSILON || Math.abs(line.getY1() - line.getY2()) < EPSILON; - } -} +package lcsb.mapviewer.wikipathway; + +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 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; + + /** + * Default class logger. + */ + static Logger logger = Logger.getLogger(ReactionElbowsTest.class); + + 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); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(5, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionNorthToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionNorthToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(7, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionNorthToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_n_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionEastToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionEastToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(5, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionEastToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionEastToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_e_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(5, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionSouthToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(5, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionSouthToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionSouthToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(5, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionSouthToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_s_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionWestToNorth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_n.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionWestToEast() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_e.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(7, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionWestToSouth() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_s.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(6, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 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()); + + 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++; + } + } + + assertEquals(4, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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 LineReactionWestToWest() throws Exception { + try { + String fileName = "testFiles/elbow/elbow_line_w_w.gpml"; + Model model1 = new GPMLToModel().getModel(fileName); + + assertEquals(1, model1.getReactions().size()); + + 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++; + } + } + + assertEquals(5, lines); + + assertEquals(1, getWarnings().size()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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; + } + } + + 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 a27c5176604eb4cd6d5cb05b167023b881bb11aa..d0b7a19add525e20c5fb1b5289c8a504264bc46b 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlInputToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlInputToModelTest.java @@ -1,1417 +1,1417 @@ -package lcsb.mapviewer.wikipathway; - -import static org.junit.Assert.assertEquals; -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 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; -import lcsb.mapviewer.model.map.modifier.Inhibition; -import lcsb.mapviewer.model.map.modifier.Modulation; -import lcsb.mapviewer.model.map.modifier.PhysicalStimulation; -import lcsb.mapviewer.model.map.modifier.UnknownCatalysis; -import lcsb.mapviewer.model.map.modifier.UnknownInhibition; -import lcsb.mapviewer.model.map.reaction.Modifier; -import lcsb.mapviewer.model.map.reaction.Product; -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 { - /** - * 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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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; - } - } -} +package lcsb.mapviewer.wikipathway; + +import static org.junit.Assert.assertEquals; +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 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; +import lcsb.mapviewer.model.map.modifier.Inhibition; +import lcsb.mapviewer.model.map.modifier.Modulation; +import lcsb.mapviewer.model.map.modifier.PhysicalStimulation; +import lcsb.mapviewer.model.map.modifier.UnknownCatalysis; +import lcsb.mapviewer.model.map.modifier.UnknownInhibition; +import lcsb.mapviewer.model.map.reaction.Modifier; +import lcsb.mapviewer.model.map.reaction.Product; +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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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; + } + } +} diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java index 90d62631d20162c0a3b1d44bcb31a1f78a2b90b6..c6522070e1163dbac619ccfb1fb44932b0971dac 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlOutputToModelTest.java @@ -1,1444 +1,1444 @@ -package lcsb.mapviewer.wikipathway; - -import static org.junit.Assert.assertEquals; -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 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; -import lcsb.mapviewer.model.map.modifier.Inhibition; -import lcsb.mapviewer.model.map.modifier.Modulation; -import lcsb.mapviewer.model.map.modifier.PhysicalStimulation; -import lcsb.mapviewer.model.map.reaction.Modifier; -import lcsb.mapviewer.model.map.reaction.Product; -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 { - /** - * 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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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, model1.getCreationWarnings().size()); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - String xml = parser.toXml(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; - } - } -} +package lcsb.mapviewer.wikipathway; + +import static org.junit.Assert.assertEquals; +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 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; +import lcsb.mapviewer.model.map.modifier.Inhibition; +import lcsb.mapviewer.model.map.modifier.Modulation; +import lcsb.mapviewer.model.map.modifier.PhysicalStimulation; +import lcsb.mapviewer.model.map.reaction.Modifier; +import lcsb.mapviewer.model.map.reaction.Product; +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()); + + CellDesignerXmlParser parser = new CellDesignerXmlParser(); + String xml = parser.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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.toXml(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; + } + } +} diff --git a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java index b8de14bad47912a3837d61327d632f7118067e1f..bacd853e5227903437db4d8589fa4d36f4cb4161 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/ReactionGpmlToModelTest.java @@ -26,7 +26,7 @@ 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 { +public class ReactionGpmlToModelTest extends WikipathwaysTestFunctions{ /** * Default class logger. */ @@ -45,7 +45,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -75,7 +75,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof StateTransitionReaction); assertFalse(reaction.isReversible()); @@ -104,7 +104,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -133,7 +133,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -163,7 +163,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertFalse(reaction.isReversible()); @@ -193,7 +193,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(model1.getCreationWarnings().toString(), 0, model1.getCreationWarnings().size()); + assertEquals(getWarnings().toString(), 0, getWarnings().size()); assertTrue(reaction instanceof HeterodimerAssociationReaction); assertFalse(reaction.isReversible()); assertEquals(2, reaction.getReactants().size()); @@ -223,7 +223,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -252,7 +252,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -281,7 +281,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof PositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -310,7 +310,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof StateTransitionReaction); assertFalse(reaction.isReversible()); @@ -339,7 +339,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof StateTransitionReaction); assertFalse(reaction.isReversible()); @@ -368,7 +368,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -397,7 +397,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -426,7 +426,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof NegativeInfluenceReaction); assertFalse(reaction.isReversible()); @@ -455,7 +455,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof PositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -484,7 +484,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof ReducedPhysicalStimulationReaction); assertFalse(reaction.isReversible()); @@ -513,7 +513,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof ReducedPhysicalStimulationReaction); assertFalse(reaction.isReversible()); @@ -542,7 +542,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof PositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -571,7 +571,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof NegativeInfluenceReaction); assertFalse(reaction.isReversible()); @@ -601,7 +601,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -631,7 +631,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -660,7 +660,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -689,7 +689,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -718,7 +718,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -747,7 +747,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertFalse(reaction.isReversible()); @@ -776,7 +776,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -805,7 +805,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -834,7 +834,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownTransitionReaction); assertTrue(reaction.isReversible()); @@ -863,7 +863,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownNegativeInfluenceReaction); assertFalse(reaction.isReversible()); @@ -892,7 +892,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(0, model1.getCreationWarnings().size()); + assertEquals(0, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -921,7 +921,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -950,7 +950,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownPositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -979,7 +979,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof PositiveInfluenceReaction); assertFalse(reaction.isReversible()); @@ -1008,7 +1008,7 @@ public class ReactionGpmlToModelTest { Reaction reaction = model1.getReactions().iterator().next(); - assertEquals(1, model1.getCreationWarnings().size()); + assertEquals(1, getWarnings().size()); assertTrue(reaction instanceof UnknownNegativeInfluenceReaction); assertFalse(reaction.isReversible()); @@ -1035,7 +1035,7 @@ public class ReactionGpmlToModelTest { assertEquals(4, model1.getReactions().size()); - assertEquals(4, model1.getCreationWarnings().size()); + assertEquals(4, getWarnings().size()); CellDesignerXmlParser parser = new CellDesignerXmlParser(); String xml = parser.toXml(model1); 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 80442db55bc7089b08c0e1b59f77d53997df9095..f955ec36c12f13bc7d06bb6425f0497a7bceb9f2 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/BugTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/BugTest.java @@ -42,7 +42,7 @@ public class BugTest extends WikipathwaysTestFunctions { String filename = "testFiles/bugs/error_328.gpml"; Model model1 = new GPMLToModel().getModel(filename); - assertEquals(7, model1.getCreationWarnings().size()); + assertEquals(7, getWarnings().size()); int complexes = 0; for (Element alias : model1.getElements()) { 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 233155016416cd53a3e76c174738d921da7c34ba..82c58720f523ed95e0b6ddc1d6f09cbd5b6783a1 100644 --- a/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelToGPMLTest.java +++ b/pathvisio/src/test/java/lcsb/mapviewer/wikipathway/XML/ModelToGPMLTest.java @@ -41,7 +41,6 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions { Model model = cellDesignerXmlParser.createModel(new ConverterParams().filename("testFiles/other_full/GSTP1 subnetwork_220214.xml")); String xml = parser.getGPML(model); assertNotNull(xml); - assertEquals(0, model.getCreationWarnings().size()); assertEquals(10, getWarnings().size()); Model model2 = new GPMLToModel().getModel(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); diff --git a/persist/src/db/10.0.3/fix_db_20161026.sql b/persist/src/db/10.0.3/fix_db_20161026.sql new file mode 100644 index 0000000000000000000000000000000000000000..da2d2fd21298ac7ab430ae2193886ac06a4b8b09 --- /dev/null +++ b/persist/src/db/10.0.3/fix_db_20161026.sql @@ -0,0 +1,3 @@ +--merging project and model logs +alter table project_table add column warnings text; +update project_table set warnings = (select creationwarnings from model_table where project_iddb = project_table.iddb); diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/ProjectDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/ProjectDaoTest.java index bc43440560de033d093eb732800ddd78cd7075ed..75636b31ce21634d1418faeffcad20a67b951329 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/ProjectDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/ProjectDaoTest.java @@ -263,4 +263,31 @@ public class ProjectDaoTest extends PersistTestFunctions { } } + /** + * After adding model to db with creation warnings... + * + * @throws Exception + */ + @Test + public void testCreationWarnings() throws Exception { + try { + Project project = new Project(); + project.addWarning("warning A"); + project.addWarning("warning B"); + assertEquals(2, project.getWarnings().size()); + + projectDao.add(project); + + projectDao.evict(project); + Project project2 = projectDao.getById(project.getId()); + + assertEquals(2, project2.getWarnings().size()); + + projectDao.delete(project2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + } diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/ModelDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/ModelDaoTest.java index dd51cd7bc75fc67b2a29271b70c8bd2f23e5b2e5..315bc6abbdf11dcc840555fb1b5baff4647597d8 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/ModelDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/ModelDaoTest.java @@ -230,37 +230,6 @@ public class ModelDaoTest extends PersistTestFunctions { } } - /** - * After adding model to db with creation warnings... - * - * @throws Exception - */ - @Test - public void testCreationWarnings() throws Exception { - try { - Model model = createModel(); - model.addCreationWarning("warning A"); - model.addCreationWarning("warning B"); - assertEquals(2, model.getCreationWarnings().size()); - - Project project = new Project(); - project.addModel(model); - projectDao.add(project); - - modelDao.evict(model); - projectDao.evict(project); - ModelData model2 = modelDao.getById(model.getId()); - - assertEquals(2, model2.getCreationWarnings().size()); - - project = projectDao.getById(project.getId()); - projectDao.delete(project); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - /** * After adding model to db, miriam annotations disappear... * diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java b/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java index 8288bfdfce3141b5d603d23824545f7fb2b43517..4c0f70bd4c0226f7b1213fe62697481be01daf3c 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java @@ -735,7 +735,7 @@ public class ProjectService implements IProjectService { } } logger.debug("Updating annotations"); - modelAnnotator.performAnnotations(model, new IProgressUpdater() { + modelAnnotator.performAnnotations(project, new IProgressUpdater() { @Override public void setProgress(final double progress) { @@ -780,51 +780,43 @@ public class ProjectService implements IProjectService { * thrown when one of the files is invalid */ private void processDataMining(Model model, List<DataMiningSet> dataMiningSets, final IProgressUpdater progressUpdater) throws InvalidDataMiningInputFile { - EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); - try { - Logger.getRootLogger().addAppender(appender); - Set<Element> nodes = new HashSet<>(); - nodes.addAll(model.getElements()); - for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { - nodes.addAll(connection.getSubmodel().getElements()); - } - Set<Reaction> reactions = new HashSet<Reaction>(); - reactions.addAll(model.getReactions()); - for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { - reactions.addAll(connection.getSubmodel().getReactions()); - } + Set<Element> nodes = new HashSet<>(); + nodes.addAll(model.getElements()); + for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { + nodes.addAll(connection.getSubmodel().getElements()); + } + Set<Reaction> reactions = new HashSet<Reaction>(); + reactions.addAll(model.getReactions()); + for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { + reactions.addAll(connection.getSubmodel().getReactions()); + } - int fileCounter = 0; - final int filesCount = dataMiningSets.size(); - for (DataMiningSet dmSet : dataMiningSets) { + int fileCounter = 0; + final int filesCount = dataMiningSets.size(); + for (DataMiningSet dmSet : dataMiningSets) { - final double offset = IProgressUpdater.MAX_PROGRESS * fileCounter / filesCount; - IProgressUpdater secondPartUpdater = new IProgressUpdater() { + final double offset = IProgressUpdater.MAX_PROGRESS * fileCounter / filesCount; + IProgressUpdater secondPartUpdater = new IProgressUpdater() { - @Override - public void setProgress(double progress) { - progressUpdater.setProgress((progress * CREATION_OF_DATA) / ((double) filesCount) + offset); - } - }; - Set<DataMining> result = dataMiningService.parseData(dmSet, nodes, reactions, secondPartUpdater); - double size = result.size(); - double count = 0; - - double updateOffset = IProgressUpdater.MAX_PROGRESS * fileCounter / filesCount + CREATION_OF_DATA / ((double) filesCount); - dbUtils.setAutoFlush(false); - for (DataMining missingConnection : result) { - missingConnection.setType(dmSet.getType()); - missingConnectionDao.add(missingConnection); - count++; - progressUpdater.setProgress(updateOffset + IProgressUpdater.MAX_PROGRESS * count / size * UPLOAD_OF_DATA); + @Override + public void setProgress(double progress) { + progressUpdater.setProgress((progress * CREATION_OF_DATA) / ((double) filesCount) + offset); } - dbUtils.setAutoFlush(true); - missingConnectionDao.flush(); + }; + Set<DataMining> result = dataMiningService.parseData(dmSet, nodes, reactions, secondPartUpdater); + double size = result.size(); + double count = 0; + + double updateOffset = IProgressUpdater.MAX_PROGRESS * fileCounter / filesCount + CREATION_OF_DATA / ((double) filesCount); + dbUtils.setAutoFlush(false); + for (DataMining missingConnection : result) { + missingConnection.setType(dmSet.getType()); + missingConnectionDao.add(missingConnection); + count++; + progressUpdater.setProgress(updateOffset + IProgressUpdater.MAX_PROGRESS * count / size * UPLOAD_OF_DATA); } - Logger.getRootLogger().removeAppender(appender); - model.addLoggingInfo(appender); - } finally { - Logger.getRootLogger().removeAppender(appender); + dbUtils.setAutoFlush(true); + missingConnectionDao.flush(); } } @@ -897,7 +889,9 @@ public class ProjectService implements IProjectService { } waitForInitialData.countDown(); double[] outOfMemoryBuffer; + EventStorageLoggerAppender appender = new EventStorageLoggerAppender(); try { + Logger.getRootLogger().addAppender(appender); logger.debug("Running: " + params.getProjectId() + "; " + params.getProjectFile()); outOfMemoryBuffer = new double[OUT_OF_MEMORY_BACKUP_BUFFER_SIZE]; for (int i = 0; i < OUT_OF_MEMORY_BACKUP_BUFFER_SIZE; i++) { @@ -931,16 +925,16 @@ public class ProjectService implements IProjectService { if (meshParser.isValidMeshId(disease)) { project.setDisease(disease); } else { - originalModel.addCreationWarning("No valid disease is provided for project:" + project.getName()); + logger.warn("No valid disease is provided for project:" + project.getName()); } } catch (AnnotatorException e1) { - originalModel.addCreationWarning("Problem with accessing mesh db. More info in logs."); + logger.warn("Problem with accessing mesh db. More info in logs."); } if (taxonomyBackend.getNameForTaxonomy(organism) != null) { project.setOrganism(organism); } else { - originalModel.addCreationWarning("No valid organism is provided for project:" + project.getName()); + logger.warn("No valid organism is provided for project:" + project.getName()); } modelDao.update(originalModel); @@ -952,8 +946,8 @@ public class ProjectService implements IProjectService { if (params.isAnalyzeAnnotations()) { analyzeAnnotations(originalModel, params); } - modelDao.update(originalModel); - + Logger.getRootLogger().removeAppender(appender); + project.addLoggingInfo(appender); updateProjectStatus(project, ProjectStatus.DONE, IProgressUpdater.MAX_PROGRESS, params); if (originalModel.getNotifyEmail() != null && !originalModel.getNotifyEmail().equals("")) { try { @@ -987,10 +981,9 @@ public class ProjectService implements IProjectService { // close the transaction for this thread dbUtils.closeSessionForCurrentThread(); } + Logger.getRootLogger().removeAppender(appender); } - } - }); if (params.isAsync()) { computations.start(); @@ -1227,7 +1220,7 @@ public class ProjectService implements IProjectService { updateProjectStatus(originalModel.getProject(), ProjectStatus.VALIDATING_MIRIAM, progress, params); } }, params.getValidAnnotations()); - List<String> res = new ArrayList<String>(); + List<String> res = new ArrayList<>(); for (ProblematicAnnotation improperAnnotation : improperAnnotations) { res.add(improperAnnotation.toString()); } @@ -1237,8 +1230,9 @@ public class ProjectService implements IProjectService { for (ProblematicAnnotation improperAnnotation : missingAnnotations) { res.add(improperAnnotation.toString()); } - originalModel.addCreationWarnings(res); - modelDao.update(originalModel); + for (String message: res) { + logger.warn(message); + } logger.debug("Analyze finished"); } diff --git a/service/src/main/java/lcsb/mapviewer/services/view/ModelView.java b/service/src/main/java/lcsb/mapviewer/services/view/ModelView.java index cb53baff24fd83df2076906192ce2df09e8f75da..2780593bd456eb2f2f407d6a645ca4158bcafe00 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/ModelView.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/ModelView.java @@ -1,440 +1,418 @@ -package lcsb.mapviewer.services.view; - -import java.io.Serializable; -import java.util.List; - -import lcsb.mapviewer.model.map.model.Model; - -import org.apache.log4j.Logger; -import org.primefaces.model.map.LatLng; - -/** - * View representatin of a model. It's a light structre that present - * {@link Model} data to the client side. - * - * @author Piotr Gawron - * - */ -public class ModelView extends AbstractView<Model> implements Serializable { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(ModelView.class); - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Version of the model. - */ - private String version; - - /** - * Name of the model. - */ - private String name; - - /** - * {@link lcsb.mapviewer.model.Project#projectId Project identifier}. - */ - private String projectId; - - /** - * Description of the model. - */ - private String description; - /** - * Size in pixels of the single square tile (small image used for graphical - * representation). - */ - private Integer tileSize; - /** - * Size of the whole map. - */ - private Integer pictureSize; - /** - * Minimum zoom level that should be allowed by the Google Maps API. - */ - private Integer minZoom; - /** - * Maximum zoom level that should be allowed by the Google Maps API. - */ - private Integer maxZoom; - /** - * Public layouts available for the model. - */ - private List<LayoutView> layouts; - - /** - * Custom layouts available only for the current user. - */ - private List<LayoutView> customLayouts; - - /** - * List of submodels in the model. - */ - private List<ModelView> submodels; - - /** - * Where is the center of the map in latituted, longiude format. - */ - private LatLng centerLatLng; - - /** - * Top-Left corner of the map (0,0) as a latLng coordinates. - */ - private LatLng topLeftLatLng; - - /** - * Bottom-Right corner of the map (width,height) as a latLng coordinates. - */ - private LatLng bottomRightLatLng; - - /** - * Should the map be automatically fit in the browser window. Bean should - * change this value if the map was already viewed by user and there is - * information about zoom level and coordinates where user is browsing it. - */ - private Boolean fitMapBounds = true; - - /** - * List of warnings that appeard during model creation. - */ - private List<String> creationWarnings; - - /** - * List of overview images attached to this model. - */ - private List<OverviewImageView> overviewImageViews; - - /** - * Top level overview image. - */ - private OverviewImageView topOverviewImage; - - /** - * Default constructor which creates view representation from the orignial - * model. - * - * @param model - * source map model - */ - protected ModelView(Model model) { - super(model); - } - - /** - * Default constructor. Should be used only for deserialization. - */ - protected ModelView() { - } - - /** - * @return the version - * @see #version - */ - public String getVersion() { - return version; - } - - /** - * @param version - * the version to set - * @see #version - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the tileSize - * @see #tileSize - */ - public Integer getTileSize() { - return tileSize; - } - - /** - * @param tileSize - * the tileSize to set - * @see #tileSize - */ - public void setTileSize(Integer tileSize) { - this.tileSize = tileSize; - } - - /** - * @return the pictureSize - * @see #pictureSize - */ - public Integer getPictureSize() { - return pictureSize; - } - - /** - * @param pictureSize - * the pictureSize to set - * @see #pictureSize - */ - public void setPictureSize(Integer pictureSize) { - this.pictureSize = pictureSize; - } - - /** - * @return the minZoom - * @see #minZoom - */ - public Integer getMinZoom() { - return minZoom; - } - - /** - * @param minZoom - * the minZoom to set - * @see #minZoom - */ - public void setMinZoom(Integer minZoom) { - this.minZoom = minZoom; - } - - /** - * @return the maxZoom - * @see #maxZoom - */ - public Integer getMaxZoom() { - return maxZoom; - } - - /** - * @param maxZoom - * the maxZoom to set - * @see #maxZoom - */ - public void setMaxZoom(Integer maxZoom) { - this.maxZoom = maxZoom; - } - - /** - * @return the layouts - * @see #layouts - */ - public List<LayoutView> getLayouts() { - return layouts; - } - - /** - * @param layouts - * the layouts to set - * @see #layouts - */ - public void setLayouts(List<LayoutView> layouts) { - this.layouts = layouts; - } - - /** - * @return the centerLatLng - * @see #centerLatLng - */ - public LatLng getCenterLatLng() { - return centerLatLng; - } - - /** - * @param centerLatLng - * the centerLatLng to set - * @see #centerLatLng - */ - public void setCenterLatLng(LatLng centerLatLng) { - this.centerLatLng = centerLatLng; - } - - /** - * @return the creationWarnings - * @see #creationWarnings - */ - public List<String> getCreationWarnings() { - return creationWarnings; - } - - /** - * @param creationWarnings - * the creationWarnings to set - * @see #creationWarnings - */ - public void setCreationWarnings(List<String> creationWarnings) { - this.creationWarnings = creationWarnings; - } - - /** - * @return the name - * @see #name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - * @see #name - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the customLayouts - * @see #customLayouts - */ - public List<LayoutView> getCustomLayouts() { - return customLayouts; - } - - /** - * @param customLayouts - * the customLayouts to set - * @see #customLayouts - */ - public void setCustomLayouts(List<LayoutView> customLayouts) { - this.customLayouts = customLayouts; - } - - /** - * @return the submodels - * @see #submodels - */ - public List<ModelView> getSubmodels() { - return submodels; - } - - /** - * @param submodels - * the submodels to set - * @see #submodels - */ - public void setSubmodels(List<ModelView> submodels) { - this.submodels = submodels; - } - - /** - * @return the overviewImageViews - * @see #overviewImageViews - */ - public List<OverviewImageView> getOverviewImageViews() { - return overviewImageViews; - } - - /** - * @param overviewImageViews - * the overviewImageViews to set - * @see #overviewImageViews - */ - public void setOverviewImageViews(List<OverviewImageView> overviewImageViews) { - this.overviewImageViews = overviewImageViews; - } - - /** - * @return the topOverviewImage - * @see #topOverviewImage - */ - public OverviewImageView getTopOverviewImage() { - return topOverviewImage; - } - - /** - * @param topOverviewImage - * the topOverviewImage to set - * @see #topOverviewImage - */ - public void setTopOverviewImage(OverviewImageView topOverviewImage) { - this.topOverviewImage = topOverviewImage; - } - - /** - * @return the topLeftLatLng - * @see #topLeftLatLng - */ - public LatLng getTopLeftLatLng() { - return topLeftLatLng; - } - - /** - * @param topLeftLatLng - * the topLeftLatLng to set - * @see #topLeftLatLng - */ - public void setTopLeftLatLng(LatLng topLeftLatLng) { - this.topLeftLatLng = topLeftLatLng; - } - - /** - * @return the bottomRightLatLng - * @see #bottomRightLatLng - */ - public LatLng getBottomRightLatLng() { - return bottomRightLatLng; - } - - /** - * @param bottomRightLatLng - * the bottomRightLatLng to set - * @see #bottomRightLatLng - */ - public void setBottomRightLatLng(LatLng bottomRightLatLng) { - this.bottomRightLatLng = bottomRightLatLng; - } - - /** - * @return the fitMapBounds - * @see #fitMapBounds - */ - public Boolean getFitMapBounds() { - return fitMapBounds; - } - - /** - * @param fitMapBounds - * the fitMapBounds to set - * @see #fitMapBounds - */ - public void setFitMapBounds(Boolean fitMapBounds) { - this.fitMapBounds = fitMapBounds; - } - - /** - * @return the projectId - * @see #projectId - */ - public String getProjectId() { - return projectId; - } - - /** - * @param projectId - * the projectName to set - * @see #projectId - */ - public void setProjectId(String projectId) { - this.projectId = projectId; - } - -} +package lcsb.mapviewer.services.view; + +import java.io.Serializable; +import java.util.List; + +import lcsb.mapviewer.model.map.model.Model; + +import org.apache.log4j.Logger; +import org.primefaces.model.map.LatLng; + +/** + * View representatin of a model. It's a light structre that present + * {@link Model} data to the client side. + * + * @author Piotr Gawron + * + */ +public class ModelView extends AbstractView<Model> implements Serializable { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(ModelView.class); + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Version of the model. + */ + private String version; + + /** + * Name of the model. + */ + private String name; + + /** + * {@link lcsb.mapviewer.model.Project#projectId Project identifier}. + */ + private String projectId; + + /** + * Description of the model. + */ + private String description; + /** + * Size in pixels of the single square tile (small image used for graphical + * representation). + */ + private Integer tileSize; + /** + * Size of the whole map. + */ + private Integer pictureSize; + /** + * Minimum zoom level that should be allowed by the Google Maps API. + */ + private Integer minZoom; + /** + * Maximum zoom level that should be allowed by the Google Maps API. + */ + private Integer maxZoom; + /** + * Public layouts available for the model. + */ + private List<LayoutView> layouts; + + /** + * Custom layouts available only for the current user. + */ + private List<LayoutView> customLayouts; + + /** + * List of submodels in the model. + */ + private List<ModelView> submodels; + + /** + * Where is the center of the map in latituted, longiude format. + */ + private LatLng centerLatLng; + + /** + * Top-Left corner of the map (0,0) as a latLng coordinates. + */ + private LatLng topLeftLatLng; + + /** + * Bottom-Right corner of the map (width,height) as a latLng coordinates. + */ + private LatLng bottomRightLatLng; + + /** + * Should the map be automatically fit in the browser window. Bean should + * change this value if the map was already viewed by user and there is + * information about zoom level and coordinates where user is browsing it. + */ + private Boolean fitMapBounds = true; + + /** + * List of overview images attached to this model. + */ + private List<OverviewImageView> overviewImageViews; + + /** + * Top level overview image. + */ + private OverviewImageView topOverviewImage; + + /** + * Default constructor which creates view representation from the orignial + * model. + * + * @param model + * source map model + */ + protected ModelView(Model model) { + super(model); + } + + /** + * Default constructor. Should be used only for deserialization. + */ + protected ModelView() { + } + + /** + * @return the version + * @see #version + */ + public String getVersion() { + return version; + } + + /** + * @param version + * the version to set + * @see #version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * @return the description + * @see #description + */ + public String getDescription() { + return description; + } + + /** + * @param description + * the description to set + * @see #description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the tileSize + * @see #tileSize + */ + public Integer getTileSize() { + return tileSize; + } + + /** + * @param tileSize + * the tileSize to set + * @see #tileSize + */ + public void setTileSize(Integer tileSize) { + this.tileSize = tileSize; + } + + /** + * @return the pictureSize + * @see #pictureSize + */ + public Integer getPictureSize() { + return pictureSize; + } + + /** + * @param pictureSize + * the pictureSize to set + * @see #pictureSize + */ + public void setPictureSize(Integer pictureSize) { + this.pictureSize = pictureSize; + } + + /** + * @return the minZoom + * @see #minZoom + */ + public Integer getMinZoom() { + return minZoom; + } + + /** + * @param minZoom + * the minZoom to set + * @see #minZoom + */ + public void setMinZoom(Integer minZoom) { + this.minZoom = minZoom; + } + + /** + * @return the maxZoom + * @see #maxZoom + */ + public Integer getMaxZoom() { + return maxZoom; + } + + /** + * @param maxZoom + * the maxZoom to set + * @see #maxZoom + */ + public void setMaxZoom(Integer maxZoom) { + this.maxZoom = maxZoom; + } + + /** + * @return the layouts + * @see #layouts + */ + public List<LayoutView> getLayouts() { + return layouts; + } + + /** + * @param layouts + * the layouts to set + * @see #layouts + */ + public void setLayouts(List<LayoutView> layouts) { + this.layouts = layouts; + } + + /** + * @return the centerLatLng + * @see #centerLatLng + */ + public LatLng getCenterLatLng() { + return centerLatLng; + } + + /** + * @param centerLatLng + * the centerLatLng to set + * @see #centerLatLng + */ + public void setCenterLatLng(LatLng centerLatLng) { + this.centerLatLng = centerLatLng; + } + + /** + * @return the name + * @see #name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + * @see #name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the customLayouts + * @see #customLayouts + */ + public List<LayoutView> getCustomLayouts() { + return customLayouts; + } + + /** + * @param customLayouts + * the customLayouts to set + * @see #customLayouts + */ + public void setCustomLayouts(List<LayoutView> customLayouts) { + this.customLayouts = customLayouts; + } + + /** + * @return the submodels + * @see #submodels + */ + public List<ModelView> getSubmodels() { + return submodels; + } + + /** + * @param submodels + * the submodels to set + * @see #submodels + */ + public void setSubmodels(List<ModelView> submodels) { + this.submodels = submodels; + } + + /** + * @return the overviewImageViews + * @see #overviewImageViews + */ + public List<OverviewImageView> getOverviewImageViews() { + return overviewImageViews; + } + + /** + * @param overviewImageViews + * the overviewImageViews to set + * @see #overviewImageViews + */ + public void setOverviewImageViews(List<OverviewImageView> overviewImageViews) { + this.overviewImageViews = overviewImageViews; + } + + /** + * @return the topOverviewImage + * @see #topOverviewImage + */ + public OverviewImageView getTopOverviewImage() { + return topOverviewImage; + } + + /** + * @param topOverviewImage + * the topOverviewImage to set + * @see #topOverviewImage + */ + public void setTopOverviewImage(OverviewImageView topOverviewImage) { + this.topOverviewImage = topOverviewImage; + } + + /** + * @return the topLeftLatLng + * @see #topLeftLatLng + */ + public LatLng getTopLeftLatLng() { + return topLeftLatLng; + } + + /** + * @param topLeftLatLng + * the topLeftLatLng to set + * @see #topLeftLatLng + */ + public void setTopLeftLatLng(LatLng topLeftLatLng) { + this.topLeftLatLng = topLeftLatLng; + } + + /** + * @return the bottomRightLatLng + * @see #bottomRightLatLng + */ + public LatLng getBottomRightLatLng() { + return bottomRightLatLng; + } + + /** + * @param bottomRightLatLng + * the bottomRightLatLng to set + * @see #bottomRightLatLng + */ + public void setBottomRightLatLng(LatLng bottomRightLatLng) { + this.bottomRightLatLng = bottomRightLatLng; + } + + /** + * @return the fitMapBounds + * @see #fitMapBounds + */ + public Boolean getFitMapBounds() { + return fitMapBounds; + } + + /** + * @param fitMapBounds + * the fitMapBounds to set + * @see #fitMapBounds + */ + public void setFitMapBounds(Boolean fitMapBounds) { + this.fitMapBounds = fitMapBounds; + } + + /** + * @return the projectId + * @see #projectId + */ + public String getProjectId() { + return projectId; + } + + /** + * @param projectId + * the projectName to set + * @see #projectId + */ + public void setProjectId(String projectId) { + this.projectId = projectId; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/ModelViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/ModelViewFactory.java index 36c649437f5e94b6086b7fd72f3ad1cf74e676d7..434de14923c2cc4c2a42b0fd16db7b14523dc97a 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/ModelViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/ModelViewFactory.java @@ -1,102 +1,100 @@ -package lcsb.mapviewer.services.view; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.List; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.model.map.layout.Layout; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; -import lcsb.mapviewer.services.utils.gmap.CoordinationConverter; - -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -import com.google.gson.Gson; - -/** - * Factory class for {@link ModelView} class. - * - * @author Piotr Gawron - * - */ -@Transactional(value = "txManager") -public class ModelViewFactory extends AbstractViewFactory<Model, ModelView> { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ModelViewFactory.class); - - /** - * Factory object used for creation of {@link LayoutView} elements. - */ - @Autowired - private LayoutViewFactory layoutViewFactory; - - /** - * Factory object used for creation of {@link OverviewImageView} elements. - */ - @Autowired - private OverviewImageViewFactory overviewImageViewFactory; - - @Override - public ModelView create(Model model) { - ModelView result = new ModelView(model); - if (model == null) { - logger.warn("Empty model..."); - return result; - } - if (model.getProject() != null) { - result.setProjectId(model.getProject().getProjectId()); - } - result.setLayouts(new ArrayList<LayoutView>()); - result.setCustomLayouts(new ArrayList<LayoutView>()); - result.setVersion(model.getMapVersion()); - result.setName(model.getName()); - - result.setMinZoom(Configuration.MIN_ZOOM_LEVEL); - result.setMaxZoom(result.getMinZoom() + model.getZoomLevels()); - result.setTileSize(model.getTileSize()); - result.setPictureSize((int) Math.max(model.getWidth(), model.getHeight())); - // we have to add copies (originals contain reference to model which - // shouldn't be passed to simple structure) - for (Layout layout : model.getLayouts()) { - if (layout.isPublicLayout()) { - result.getLayouts().add(layoutViewFactory.create(layout)); - } - } - CoordinationConverter cConverter = new CoordinationConverter(model); - result.setCenterLatLng(cConverter.toLatLng(new Point2D.Double(result.getPictureSize() / 2, result.getPictureSize() / 2))); - result.setBottomRightLatLng(cConverter.toLatLng(new Point2D.Double(model.getWidth(), model.getHeight()))); - result.setTopLeftLatLng(cConverter.toLatLng(new Point2D.Double(0, 0))); - - result.setDescription(model.getNotes()); - - result.setCreationWarnings(model.getCreationWarnings()); - - List<ModelView> submodels = new ArrayList<ModelView>(); - for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { - submodels.add(create(connection.getSubmodel().getModel())); - } - result.setSubmodels(submodels); - result.setOverviewImageViews(overviewImageViewFactory.createList(model.getOverviewImages())); - if (result.getOverviewImageViews().size() > 0) { - result.setTopOverviewImage(overviewImageViewFactory.create(model.getTopOverviewImage())); - } - return result; - } - - @Override - public String createGson(ModelView object) { - return new Gson().toJson(object); - } - - @Override - public Model viewToObject(ModelView view) { - throw new NotImplementedException(); - } -} +package lcsb.mapviewer.services.view; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.model.map.layout.Layout; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; +import lcsb.mapviewer.services.utils.gmap.CoordinationConverter; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +import com.google.gson.Gson; + +/** + * Factory class for {@link ModelView} class. + * + * @author Piotr Gawron + * + */ +@Transactional(value = "txManager") +public class ModelViewFactory extends AbstractViewFactory<Model, ModelView> { + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ModelViewFactory.class); + + /** + * Factory object used for creation of {@link LayoutView} elements. + */ + @Autowired + private LayoutViewFactory layoutViewFactory; + + /** + * Factory object used for creation of {@link OverviewImageView} elements. + */ + @Autowired + private OverviewImageViewFactory overviewImageViewFactory; + + @Override + public ModelView create(Model model) { + ModelView result = new ModelView(model); + if (model == null) { + logger.warn("Empty model..."); + return result; + } + if (model.getProject() != null) { + result.setProjectId(model.getProject().getProjectId()); + } + result.setLayouts(new ArrayList<LayoutView>()); + result.setCustomLayouts(new ArrayList<LayoutView>()); + result.setVersion(model.getMapVersion()); + result.setName(model.getName()); + + result.setMinZoom(Configuration.MIN_ZOOM_LEVEL); + result.setMaxZoom(result.getMinZoom() + model.getZoomLevels()); + result.setTileSize(model.getTileSize()); + result.setPictureSize((int) Math.max(model.getWidth(), model.getHeight())); + // we have to add copies (originals contain reference to model which + // shouldn't be passed to simple structure) + for (Layout layout : model.getLayouts()) { + if (layout.isPublicLayout()) { + result.getLayouts().add(layoutViewFactory.create(layout)); + } + } + CoordinationConverter cConverter = new CoordinationConverter(model); + result.setCenterLatLng(cConverter.toLatLng(new Point2D.Double(result.getPictureSize() / 2, result.getPictureSize() / 2))); + result.setBottomRightLatLng(cConverter.toLatLng(new Point2D.Double(model.getWidth(), model.getHeight()))); + result.setTopLeftLatLng(cConverter.toLatLng(new Point2D.Double(0, 0))); + + result.setDescription(model.getNotes()); + + List<ModelView> submodels = new ArrayList<ModelView>(); + for (ModelSubmodelConnection connection : model.getSubmodelConnections()) { + submodels.add(create(connection.getSubmodel().getModel())); + } + result.setSubmodels(submodels); + result.setOverviewImageViews(overviewImageViewFactory.createList(model.getOverviewImages())); + if (result.getOverviewImageViews().size() > 0) { + result.setTopOverviewImage(overviewImageViewFactory.create(model.getTopOverviewImage())); + } + return result; + } + + @Override + public String createGson(ModelView object) { + return new Gson().toJson(object); + } + + @Override + public Model viewToObject(ModelView view) { + throw new NotImplementedException(); + } +} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/ProjectView.java b/service/src/main/java/lcsb/mapviewer/services/view/ProjectView.java index ae6a0f96420135d27ecf98bbe83d55c8821a341b..6e1ed975ea37398c6e56a39020d759674f3932f2 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/ProjectView.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/ProjectView.java @@ -1,551 +1,527 @@ -package lcsb.mapviewer.services.view; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import lcsb.mapviewer.common.comparator.IntegerComparator; -import lcsb.mapviewer.model.Project; - -/** - * This class is a client view that represents {@link Project} class. Right now - * this class highly entangles {@link Project} and - * {@link lcsb.mapviewer.model.map.model.db.model.map.Model Model}. In the - * future it should separate it. - * - * @author Piotr Gawron - * - */ -public class ProjectView extends AbstractView<Project> implements Comparable<ProjectView>, Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Identifier of the model that is represented in this project view (this must - * be refactorized in the future). - */ - private Integer modelId; - - /** - * List of layouts in the model (identified by {@link #modelId}). - */ - private List<LayoutView> layouts = new ArrayList<LayoutView>(); - - /** - * {@link Project#projectId Identifier} of the project. - */ - private String projectId; - - /** - * {@link Project#name Name} of the project. - */ - private String projectName; - - /** - * {@link Project#name newDiseaseName} of the project. - */ - private String newDiseaseName; - - /** - * {@link Project#organism newOrganismName} of the project. - */ - private String newOrganismName; - - /** - * {@link Project#disease Disease} of the project. - */ - private AnnotationView projectDiseaseLink; - - /** - * {@link Project#disease Disease name} of the project. - */ - private String diseaseName = "N/A"; - - /** - * {@link Project#organism Organism} of the project. - */ - private AnnotationView organismLink; - - /** - * Email used for notification obut the events connected to this project. - */ - private String notifyEmail; - - /** - * Status of the project processing. - */ - private String status; - - /** - * Errors that appeard in the project. - */ - private String errors; - - /** - * Progress of the project processng (value between 0..100). - */ - private Integer progress; - - /** - * List of warnings that appeard during model creation. - */ - private String creationWarnings; - - /** - * Short list of warnings that appeard during model creation. - */ - private String creationWarningsPreview; - - /** - * List of warnings that appeard during model creation. - */ - private List<String> warnings; - - /** - * Description of the model. - */ - private String description; - /** - * Version of the model. - */ - private String version; - - /** - * "true" if input file from which project was created is available, "false" - * otherwise. - */ - private String inputDataAvailable; - - /** - * List of data mining sets used to gernerate suggested connections. - */ - private List<DataMiningSetView> dataMiningSets = new ArrayList<DataMiningSetView>(); - - /** - * Default constructor. - * - * @param project - * {@link Project} for which this view is created - */ - protected ProjectView(Project project) { - super(project); - } - - /** - * Default constructor. Should be used only for deserialization. - */ - protected ProjectView() { - } - - /** - * Constructor that creates copy of the {@link ProjectView}. - * - * @param row - * original object - */ - public ProjectView(ProjectView row) { - super(null); - setIdObject(row.getIdObject()); - modelId = row.getModelId(); - layouts.addAll(row.getLayouts()); - projectId = row.getProjectId(); - projectName = row.getProjectName(); - newDiseaseName = row.getNewDiseaseName(); - newOrganismName = row.getNewOrganismName(); - projectDiseaseLink = row.getProjectDiseaseLink(); - organismLink = row.getOrganismLink(); - notifyEmail = row.getNotifyEmail(); - status = row.getStatus(); - progress = row.getProgress(); - description = row.getDescription(); - version = row.getVersion(); - errors = row.getErrors(); - creationWarnings = row.getCreationWarnings(); - creationWarningsPreview = row.getCreationWarningsPreview(); - warnings = row.getWarnings(); - for (DataMiningSetView view : row.getDataMiningSets()) { - dataMiningSets.add(new DataMiningSetView(view)); - } - inputDataAvailable = row.getInputDataAvailable(); - } - - @Override - public int compareTo(ProjectView o) { - if (o == null) { - new IntegerComparator().compare(getIdObject(), null); - } - return new IntegerComparator().compare(getIdObject(), o.getIdObject()); - } - - /** - * @return the modelId - * @see #modelId - */ - public Integer getModelId() { - return modelId; - } - - /** - * @param modelId - * the modelId to set - * @see #modelId - */ - public void setModelId(Integer modelId) { - this.modelId = modelId; - } - - /** - * @return the layouts - * @see #layouts - */ - public List<LayoutView> getLayouts() { - return layouts; - } - - /** - * @param layouts - * the layouts to set - * @see #layouts - */ - public void setLayouts(List<LayoutView> layouts) { - this.layouts = layouts; - } - - /** - * @return the name - * @see #projectId - */ - public String getProjectId() { - return projectId; - } - - /** - * @param projectId - * project identifier - * @see #projectId - */ - public void setProjectId(String projectId) { - this.projectId = projectId; - } - - /** - * @return the notifyEmail - * @see #notifyEmail - */ - public String getNotifyEmail() { - return notifyEmail; - } - - /** - * @param notifyEmail - * the notifyEmail to set - * @see #notifyEmail - */ - public void setNotifyEmail(String notifyEmail) { - this.notifyEmail = notifyEmail; - } - - /** - * @return the status - * @see #status - */ - public String getStatus() { - return status; - } - - /** - * @param status - * the status to set - * @see #status - */ - public void setStatus(String status) { - this.status = status; - } - - /** - * @return the progress - * @see #progress - */ - public Integer getProgress() { - return progress; - } - - /** - * @param progress - * the progress to set - * @see #progress - */ - public void setProgress(Integer progress) { - this.progress = progress; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the version - * @see #version - */ - public String getVersion() { - return version; - } - - /** - * @param version - * the version to set - * @see #version - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * Adds layout to the view. - * - * @param row - * layout to add - */ - public void addLayout(LayoutView row) { - layouts.add(row); - } - - /** - * @return the creationWarnings - * @see #creationWarnings - */ - public String getCreationWarnings() { - return creationWarnings; - } - - /** - * @param creationWarnings - * the creationWarnings to set - * @see #creationWarnings - */ - public void setCreationWarnings(String creationWarnings) { - this.creationWarnings = creationWarnings; - } - - /** - * @return the warnings - * @see #warnings - */ - public List<String> getWarnings() { - return warnings; - } - - /** - * @param warnings - * the warnings to set - * @see #warnings - */ - public void setWarnings(List<String> warnings) { - this.warnings = warnings; - } - - /** - * @return the errors - * @see #errors - */ - public String getErrors() { - return errors; - } - - /** - * @param errors - * the errors to set - * @see #errors - */ - public void setErrors(String errors) { - this.errors = errors; - } - - /** - * @return the dataMiningSets - * @see #dataMiningSets - */ - public List<DataMiningSetView> getDataMiningSets() { - return dataMiningSets; - } - - /** - * @param dataMiningSets - * the dataMiningSets to set - * @see #dataMiningSets - */ - public void setDataMiningSets(List<DataMiningSetView> dataMiningSets) { - this.dataMiningSets = dataMiningSets; - } - - /** - * Adds {@link DataMiningSetView} to {@link #dataMiningSets}. - * - * @param dataMiningSetView - * object to add - */ - public void addDataMiningSet(DataMiningSetView dataMiningSetView) { - dataMiningSets.add(dataMiningSetView); - } - - /** - * @return the creationWarningsPreview - * @see #creationWarningsPreview - */ - public String getCreationWarningsPreview() { - return creationWarningsPreview; - } - - /** - * @param creationWarningsPreview - * the creationWarningsPreview to set - * @see #creationWarningsPreview - */ - public void setCreationWarningsPreview(String creationWarningsPreview) { - this.creationWarningsPreview = creationWarningsPreview; - } - - /** - * @return the projectName - * @see #projectName - */ - public String getProjectName() { - return projectName; - } - - /** - * @param projectName - * the projectName to set - * @see #projectName - */ - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - /** - * @return project disease link - */ - public AnnotationView getProjectDiseaseLink() { - return projectDiseaseLink; - } - - /** - * @param projectDiseaseLink - * the link for the disease. - */ - public void setProjectDiseaseLink(AnnotationView projectDiseaseLink) { - this.projectDiseaseLink = projectDiseaseLink; - } - - /** - * @return this is used to update or add different disease association. - */ - public String getNewDiseaseName() { - return newDiseaseName; - } - - /** - * @param newDiseaseName - * this is used to update or add different disease association. - */ - public void setNewDiseaseName(String newDiseaseName) { - this.newDiseaseName = newDiseaseName; - } - - /** - * @return the diseaseName - * @see #diseaseName - */ - public String getDiseaseName() { - return diseaseName; - } - - /** - * @param diseaseName - * the diseaseName to set - * @see #diseaseName - */ - public void setDiseaseName(String diseaseName) { - this.diseaseName = diseaseName; - } - - /** - * @return the inputDataAvailable - * @see #inputDataAvailable - */ - public String getInputDataAvailable() { - return inputDataAvailable; - } - - /** - * @param inputDataAvailable - * the inputDataAvailable to set - * @see #inputDataAvailable - */ - public void setInputDataAvailable(String inputDataAvailable) { - this.inputDataAvailable = inputDataAvailable; - } - - /** - * @param value - * the inputDataAvailable to set - * @see #inputDataAvailable - */ - public void setInputDataAvailable(boolean value) { - if (value) { - this.inputDataAvailable = "true"; - } else { - this.inputDataAvailable = "false"; - } - - } - - /** - * @return the organismLink - * @see #organismLink - */ - public AnnotationView getOrganismLink() { - return organismLink; - } - - /** - * @param organismLink the organismLink to set - * @see #organismLink - */ - public void setOrganismLink(AnnotationView organismLink) { - this.organismLink = organismLink; - } - - /** - * @return the newOrganismName - * @see #newOrganismName - */ - public String getNewOrganismName() { - return newOrganismName; - } - - /** - * @param newOrganismName the newOrganismName to set - * @see #newOrganismName - */ - public void setNewOrganismName(String newOrganismName) { - this.newOrganismName = newOrganismName; - } - -} +package lcsb.mapviewer.services.view; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import lcsb.mapviewer.common.comparator.IntegerComparator; +import lcsb.mapviewer.model.Project; + +/** + * This class is a client view that represents {@link Project} class. Right now + * this class highly entangles {@link Project} and + * {@link lcsb.mapviewer.model.map.model.db.model.map.Model Model}. In the + * future it should separate it. + * + * @author Piotr Gawron + * + */ +public class ProjectView extends AbstractView<Project> implements Comparable<ProjectView>, Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Identifier of the model that is represented in this project view (this must + * be refactorized in the future). + */ + private Integer modelId; + + /** + * List of layouts in the model (identified by {@link #modelId}). + */ + private List<LayoutView> layouts = new ArrayList<LayoutView>(); + + /** + * {@link Project#projectId Identifier} of the project. + */ + private String projectId; + + /** + * {@link Project#name Name} of the project. + */ + private String projectName; + + /** + * {@link Project#name newDiseaseName} of the project. + */ + private String newDiseaseName; + + /** + * {@link Project#organism newOrganismName} of the project. + */ + private String newOrganismName; + + /** + * {@link Project#disease Disease} of the project. + */ + private AnnotationView projectDiseaseLink; + + /** + * {@link Project#disease Disease name} of the project. + */ + private String diseaseName = "N/A"; + + /** + * {@link Project#organism Organism} of the project. + */ + private AnnotationView organismLink; + + /** + * Email used for notification obut the events connected to this project. + */ + private String notifyEmail; + + /** + * Status of the project processing. + */ + private String status; + + /** + * Errors that appeard in the project. + */ + private String errors; + + /** + * Progress of the project processng (value between 0..100). + */ + private Integer progress; + + /** + * Short list of warnings that appeard during model creation. + */ + private String warningsPreview; + + /** + * List of warnings that appeard during model creation. + */ + private List<String> warnings; + + /** + * Description of the model. + */ + private String description; + /** + * Version of the model. + */ + private String version; + + /** + * "true" if input file from which project was created is available, "false" + * otherwise. + */ + private String inputDataAvailable; + + /** + * List of data mining sets used to gernerate suggested connections. + */ + private List<DataMiningSetView> dataMiningSets = new ArrayList<DataMiningSetView>(); + + /** + * Default constructor. + * + * @param project + * {@link Project} for which this view is created + */ + protected ProjectView(Project project) { + super(project); + } + + /** + * Default constructor. Should be used only for deserialization. + */ + protected ProjectView() { + } + + /** + * Constructor that creates copy of the {@link ProjectView}. + * + * @param row + * original object + */ + public ProjectView(ProjectView row) { + super(null); + setIdObject(row.getIdObject()); + modelId = row.getModelId(); + layouts.addAll(row.getLayouts()); + projectId = row.getProjectId(); + projectName = row.getProjectName(); + newDiseaseName = row.getNewDiseaseName(); + newOrganismName = row.getNewOrganismName(); + projectDiseaseLink = row.getProjectDiseaseLink(); + organismLink = row.getOrganismLink(); + notifyEmail = row.getNotifyEmail(); + status = row.getStatus(); + progress = row.getProgress(); + description = row.getDescription(); + version = row.getVersion(); + errors = row.getErrors(); + warningsPreview = row.getWarningsPreview(); + warnings = row.getWarnings(); + for (DataMiningSetView view : row.getDataMiningSets()) { + dataMiningSets.add(new DataMiningSetView(view)); + } + inputDataAvailable = row.getInputDataAvailable(); + } + + @Override + public int compareTo(ProjectView o) { + if (o == null) { + new IntegerComparator().compare(getIdObject(), null); + } + return new IntegerComparator().compare(getIdObject(), o.getIdObject()); + } + + /** + * @return the modelId + * @see #modelId + */ + public Integer getModelId() { + return modelId; + } + + /** + * @param modelId + * the modelId to set + * @see #modelId + */ + public void setModelId(Integer modelId) { + this.modelId = modelId; + } + + /** + * @return the layouts + * @see #layouts + */ + public List<LayoutView> getLayouts() { + return layouts; + } + + /** + * @param layouts + * the layouts to set + * @see #layouts + */ + public void setLayouts(List<LayoutView> layouts) { + this.layouts = layouts; + } + + /** + * @return the name + * @see #projectId + */ + public String getProjectId() { + return projectId; + } + + /** + * @param projectId + * project identifier + * @see #projectId + */ + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + /** + * @return the notifyEmail + * @see #notifyEmail + */ + public String getNotifyEmail() { + return notifyEmail; + } + + /** + * @param notifyEmail + * the notifyEmail to set + * @see #notifyEmail + */ + public void setNotifyEmail(String notifyEmail) { + this.notifyEmail = notifyEmail; + } + + /** + * @return the status + * @see #status + */ + public String getStatus() { + return status; + } + + /** + * @param status + * the status to set + * @see #status + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * @return the progress + * @see #progress + */ + public Integer getProgress() { + return progress; + } + + /** + * @param progress + * the progress to set + * @see #progress + */ + public void setProgress(Integer progress) { + this.progress = progress; + } + + /** + * @return the description + * @see #description + */ + public String getDescription() { + return description; + } + + /** + * @param description + * the description to set + * @see #description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the version + * @see #version + */ + public String getVersion() { + return version; + } + + /** + * @param version + * the version to set + * @see #version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Adds layout to the view. + * + * @param row + * layout to add + */ + public void addLayout(LayoutView row) { + layouts.add(row); + } + + /** + * @return the warnings + * @see #warnings + */ + public List<String> getWarnings() { + return warnings; + } + + /** + * @param warnings + * the warnings to set + * @see #warnings + */ + public void setWarnings(List<String> warnings) { + this.warnings = warnings; + } + + /** + * @return the errors + * @see #errors + */ + public String getErrors() { + return errors; + } + + /** + * @param errors + * the errors to set + * @see #errors + */ + public void setErrors(String errors) { + this.errors = errors; + } + + /** + * @return the dataMiningSets + * @see #dataMiningSets + */ + public List<DataMiningSetView> getDataMiningSets() { + return dataMiningSets; + } + + /** + * @param dataMiningSets + * the dataMiningSets to set + * @see #dataMiningSets + */ + public void setDataMiningSets(List<DataMiningSetView> dataMiningSets) { + this.dataMiningSets = dataMiningSets; + } + + /** + * Adds {@link DataMiningSetView} to {@link #dataMiningSets}. + * + * @param dataMiningSetView + * object to add + */ + public void addDataMiningSet(DataMiningSetView dataMiningSetView) { + dataMiningSets.add(dataMiningSetView); + } + + /** + * @return the projectName + * @see #projectName + */ + public String getProjectName() { + return projectName; + } + + /** + * @param projectName + * the projectName to set + * @see #projectName + */ + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + /** + * @return project disease link + */ + public AnnotationView getProjectDiseaseLink() { + return projectDiseaseLink; + } + + /** + * @param projectDiseaseLink + * the link for the disease. + */ + public void setProjectDiseaseLink(AnnotationView projectDiseaseLink) { + this.projectDiseaseLink = projectDiseaseLink; + } + + /** + * @return this is used to update or add different disease association. + */ + public String getNewDiseaseName() { + return newDiseaseName; + } + + /** + * @param newDiseaseName + * this is used to update or add different disease association. + */ + public void setNewDiseaseName(String newDiseaseName) { + this.newDiseaseName = newDiseaseName; + } + + /** + * @return the diseaseName + * @see #diseaseName + */ + public String getDiseaseName() { + return diseaseName; + } + + /** + * @param diseaseName + * the diseaseName to set + * @see #diseaseName + */ + public void setDiseaseName(String diseaseName) { + this.diseaseName = diseaseName; + } + + /** + * @return the inputDataAvailable + * @see #inputDataAvailable + */ + public String getInputDataAvailable() { + return inputDataAvailable; + } + + /** + * @param inputDataAvailable + * the inputDataAvailable to set + * @see #inputDataAvailable + */ + public void setInputDataAvailable(String inputDataAvailable) { + this.inputDataAvailable = inputDataAvailable; + } + + /** + * @param value + * the inputDataAvailable to set + * @see #inputDataAvailable + */ + public void setInputDataAvailable(boolean value) { + if (value) { + this.inputDataAvailable = "true"; + } else { + this.inputDataAvailable = "false"; + } + + } + + /** + * @return the organismLink + * @see #organismLink + */ + public AnnotationView getOrganismLink() { + return organismLink; + } + + /** + * @param organismLink the organismLink to set + * @see #organismLink + */ + public void setOrganismLink(AnnotationView organismLink) { + this.organismLink = organismLink; + } + + /** + * @return the newOrganismName + * @see #newOrganismName + */ + public String getNewOrganismName() { + return newOrganismName; + } + + /** + * @param newOrganismName the newOrganismName to set + * @see #newOrganismName + */ + public void setNewOrganismName(String newOrganismName) { + this.newOrganismName = newOrganismName; + } + + /** + * @return the warningsPreview + * @see #warningsPreview + */ + public String getWarningsPreview() { + return warningsPreview; + } + + /** + * @param warningsPreview the warningsPreview to set + * @see #warningsPreview + */ + public void setWarningsPreview(String warningsPreview) { + this.warningsPreview = warningsPreview; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/ProjectViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/ProjectViewFactory.java index 85e7784a551a5ec2c6dc5abc9ecfb9df2d6a9215..1d98eb8894d2cb3bb1e4ef4865aab8725b965989 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/ProjectViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/ProjectViewFactory.java @@ -1,122 +1,119 @@ -package lcsb.mapviewer.services.view; - -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; - -import com.google.gson.Gson; - -import lcsb.mapviewer.annotation.data.MeSH; -import lcsb.mapviewer.annotation.services.MeSHParser; -import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.Project; -import lcsb.mapviewer.model.map.graph.DataMiningSet; -import lcsb.mapviewer.model.map.layout.Layout; -import lcsb.mapviewer.model.map.model.ModelData; - -/** - * Factory class for {@link ProjectView} class. - * - * @author Piotr Gawron - * - */ -public class ProjectViewFactory extends AbstractViewFactory<Project, ProjectView> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ProjectViewFactory.class); - - /** - * Factory object for {@link LayoutView} elements. - */ - @Autowired - private LayoutViewFactory layoutViewFactory; - - /** - * Factory object used for creation of {@link AnnotationView} elements. - */ - @Autowired - private AnnotationViewFactory annotationViewFactory; - - /** - * Access object for information about mesh terms. - */ - @Autowired - private MeSHParser meSHParser; - - @Override - public ProjectView create(Project project) { - ProjectView result = new ProjectView(project); - if (project == null) { - return result; - } - result.setIdObject(project.getId()); - result.setErrors(project.getErrors()); - result.setProjectId(project.getProjectId()); - result.setProjectName(project.getName()); - if (project.getDisease() != null) { - result.setProjectDiseaseLink(annotationViewFactory.create(project.getDisease())); - result.setNewDiseaseName(project.getDisease().getResource()); - MeSH mesh; - try { - mesh = meSHParser.getMeSH(project.getDisease()); - if (mesh != null) { - result.setDiseaseName(mesh.getName()); - } - } catch (AnnotatorException e) { - logger.error("Problem with getting info about mesh entry: ", e); - } - } - - if (project.getOrganism() != null) { - result.setOrganismLink(annotationViewFactory.create(project.getOrganism())); - result.setNewOrganismName(project.getOrganism().getResource()); - } - result.setStatus(project.getStatus().toString()); - result.setProgress(Integer.valueOf((int) project.getProgress())); - result.setInputDataAvailable(project.getInputFileName() != null); - for (ModelData model : project.getModels()) { - result.setModelId(model.getId()); - result.setDescription(model.getNotes()); - result.getLayouts().clear(); - result.setVersion(model.getMapVersion()); - result.setNotifyEmail(model.getNotifyEmail()); - for (Layout layout : model.getLayouts()) { - LayoutView layoutRow = layoutViewFactory.create(layout); - result.addLayout(layoutRow); - } - StringBuilder warningBuilder = new StringBuilder(""); - - int warnCount = 0; - String warnPreview = ""; - for (String w : model.getCreationWarnings()) { - if (!"".equals(w)) { - warningBuilder.append(w + "\n"); - if (warnCount <= 2) { - warnPreview += w + "\n"; - } - warnCount++; - - } - } - result.setCreationWarnings(warningBuilder.toString()); - result.setCreationWarningsPreview(warnPreview); - result.setWarnings(model.getCreationWarnings()); - for (DataMiningSet dms : model.getDataMiningSets()) { - result.addDataMiningSet(new DataMiningSetView(dms)); - } - } - return result; - } - - @Override - public String createGson(ProjectView object) { - return new Gson().toJson(object); - } - - @Override - public Project viewToObject(ProjectView view) { - throw new NotImplementedException(); - } -} +package lcsb.mapviewer.services.view; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.gson.Gson; + +import lcsb.mapviewer.annotation.data.MeSH; +import lcsb.mapviewer.annotation.services.MeSHParser; +import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.Project; +import lcsb.mapviewer.model.map.graph.DataMiningSet; +import lcsb.mapviewer.model.map.layout.Layout; +import lcsb.mapviewer.model.map.model.ModelData; + +/** + * Factory class for {@link ProjectView} class. + * + * @author Piotr Gawron + * + */ +public class ProjectViewFactory extends AbstractViewFactory<Project, ProjectView> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ProjectViewFactory.class); + + /** + * Factory object for {@link LayoutView} elements. + */ + @Autowired + private LayoutViewFactory layoutViewFactory; + + /** + * Factory object used for creation of {@link AnnotationView} elements. + */ + @Autowired + private AnnotationViewFactory annotationViewFactory; + + /** + * Access object for information about mesh terms. + */ + @Autowired + private MeSHParser meSHParser; + + @Override + public ProjectView create(Project project) { + ProjectView result = new ProjectView(project); + if (project == null) { + return result; + } + result.setIdObject(project.getId()); + result.setErrors(project.getErrors()); + result.setProjectId(project.getProjectId()); + result.setProjectName(project.getName()); + if (project.getDisease() != null) { + result.setProjectDiseaseLink(annotationViewFactory.create(project.getDisease())); + result.setNewDiseaseName(project.getDisease().getResource()); + MeSH mesh; + try { + mesh = meSHParser.getMeSH(project.getDisease()); + if (mesh != null) { + result.setDiseaseName(mesh.getName()); + } + } catch (AnnotatorException e) { + logger.error("Problem with getting info about mesh entry: ", e); + } + } + + if (project.getOrganism() != null) { + result.setOrganismLink(annotationViewFactory.create(project.getOrganism())); + result.setNewOrganismName(project.getOrganism().getResource()); + } + result.setStatus(project.getStatus().toString()); + result.setProgress(Integer.valueOf((int) project.getProgress())); + result.setInputDataAvailable(project.getInputFileName() != null); + + int warnCount = 0; + String warnPreview = ""; + for (String w : project.getWarnings()) { + if (!"".equals(w)) { + if (warnCount <= 2) { + warnPreview += w + "\n"; + } + warnCount++; + } + } + result.setWarningsPreview(warnPreview); + result.setWarnings(project.getWarnings()); + + for (ModelData model : project.getModels()) { + result.setModelId(model.getId()); + result.setDescription(model.getNotes()); + result.getLayouts().clear(); + result.setVersion(model.getMapVersion()); + result.setNotifyEmail(model.getNotifyEmail()); + for (Layout layout : model.getLayouts()) { + LayoutView layoutRow = layoutViewFactory.create(layout); + result.addLayout(layoutRow); + } + for (DataMiningSet dms : model.getDataMiningSets()) { + result.addDataMiningSet(new DataMiningSetView(dms)); + } + } + return result; + } + + @Override + public String createGson(ProjectView object) { + return new Gson().toJson(object); + } + + @Override + public Project viewToObject(ProjectView view) { + throw new NotImplementedException(); + } +} diff --git a/service/src/test/java/lcsb/mapviewer/services/view/ModelViewFactoryTest.java b/service/src/test/java/lcsb/mapviewer/services/view/ModelViewFactoryTest.java index 7451dc126b2e6b2981d37fe4035d80e1a2d7a056..32a78c241c5fd296359e71eea7c5afe6211cb508 100644 --- a/service/src/test/java/lcsb/mapviewer/services/view/ModelViewFactoryTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/view/ModelViewFactoryTest.java @@ -1,77 +1,76 @@ -package lcsb.mapviewer.services.view; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; - -import lcsb.mapviewer.services.ServiceTestFunctions; - -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.primefaces.model.map.LatLng; -import org.springframework.beans.factory.annotation.Autowired; - -public class ModelViewFactoryTest extends ServiceTestFunctions{ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(ModelViewFactoryTest .class); - - @Autowired - ModelViewFactory modelViewFactory; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testCreateEmpty() throws Exception { - try { - Object object = modelViewFactory.create(null); - assertNotNull(object); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCreateJson() throws Exception { - try { - ModelView object = modelViewFactory.create(null); - String json = modelViewFactory.createGson(object); - assertNotNull(json); - - object.setCenterLatLng(new LatLng(1, 2)); - List<String> list = new ArrayList<String>(); - list.add("ASS"); - object.setCreationWarnings(list); - object.setDescription("ASDAS"); - object.setIdObject(2); - List<LayoutView> views = new ArrayList<LayoutView>(); - LayoutView view = new LayoutView(); - view.setCreator("AA"); - view.setDirectory("C:\\test\\directory/"); - views.add(view); - object.setLayouts(views); - object.setMaxZoom(4); - object.setMinZoom(3); - object.setPictureSize(123); - object.setTileSize(234); - object.setVersion("#$#$#"); - json = modelViewFactory.createGson(object); - assertNotNull(json); - - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.services.view; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import lcsb.mapviewer.services.ServiceTestFunctions; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.primefaces.model.map.LatLng; +import org.springframework.beans.factory.annotation.Autowired; + +public class ModelViewFactoryTest extends ServiceTestFunctions{ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(ModelViewFactoryTest .class); + + @Autowired + ModelViewFactory modelViewFactory; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testCreateEmpty() throws Exception { + try { + Object object = modelViewFactory.create(null); + assertNotNull(object); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCreateJson() throws Exception { + try { + ModelView object = modelViewFactory.create(null); + String json = modelViewFactory.createGson(object); + assertNotNull(json); + + object.setCenterLatLng(new LatLng(1, 2)); + List<String> list = new ArrayList<>(); + list.add("ASS"); + object.setDescription("ASDAS"); + object.setIdObject(2); + List<LayoutView> views = new ArrayList<LayoutView>(); + LayoutView view = new LayoutView(); + view.setCreator("AA"); + view.setDirectory("C:\\test\\directory/"); + views.add(view); + object.setLayouts(views); + object.setMaxZoom(4); + object.setMinZoom(3); + object.setPictureSize(123); + object.setTileSize(234); + object.setVersion("#$#$#"); + json = modelViewFactory.createGson(object); + assertNotNull(json); + + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/web/src/main/java/lcsb/mapviewer/bean/ProjectBean.java b/web/src/main/java/lcsb/mapviewer/bean/ProjectBean.java index 1d69c76afc2d5c6d757b4a3e7b58d8bcc123962c..834e15225e1668c50aadee9ca73b8566dc113d94 100644 --- a/web/src/main/java/lcsb/mapviewer/bean/ProjectBean.java +++ b/web/src/main/java/lcsb/mapviewer/bean/ProjectBean.java @@ -26,6 +26,7 @@ import javax.faces.bean.ViewScoped; import javax.faces.event.ActionEvent; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.primefaces.event.FileUploadEvent; import org.primefaces.event.TransferEvent; @@ -1092,7 +1093,7 @@ public class ProjectBean extends AbstractManagedBean implements Serializable { */ public void downloadWarnings() throws IOException { // and send it as response - sendFileAsResponse(selectedProject.getCreationWarnings(), "warnings.txt", MimeType.TEXT); + sendFileAsResponse(StringUtils.join(selectedProject.getWarnings(), "\n"), "warnings.txt", MimeType.TEXT); } /** diff --git a/web/src/main/webapp/admin/projects.xhtml b/web/src/main/webapp/admin/projects.xhtml index 7c743cf2c049a33e384c25e36f3fca401016ab43..a036465233728e14a31fb7ed97666ede4951fb0d 100644 --- a/web/src/main/webapp/admin/projects.xhtml +++ b/web/src/main/webapp/admin/projects.xhtml @@ -50,8 +50,8 @@ <p:commandLink update=":#{p:component('warningsDlg')}" id="warningButton" oncomplete="PF('warningsDialog').show()" - title="#{project.creationWarningsPreview}" - rendered="#{not empty project.creationWarnings}" > + title="#{project.warningsPreview}" + rendered="#{not empty project.warnings}" > <h:graphicImage library="images" name="icons/warning.png" width="24px" class="imgMiddle" /> <f:setPropertyActionListener value="#{project}" target="#{projectMB.selectedProject}" /> </p:commandLink >