From 14a66f69b4162a27df505eafde1c1f79be141b5b Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 11 Jul 2018 14:08:01 +0200 Subject: [PATCH] ModificationSite and Residue classes extracted --- .../celldesigner/species/GeneXmlParser.java | 16 +- .../species/ProteinXmlParser.java | 1 + .../species/SpeciesSbmlParser.java | 28 +- .../structure/CellDesignerGene.java | 25 +- .../structure/CellDesignerProtein.java | 2 +- .../fields/CellDesignerGeneRegion.java | 372 ++++++++++++++ .../CellDesignerModificationResidue.java | 35 +- .../structure/fields/SpeciesState.java | 2 +- .../CellDesignerXmlParserTest.java | 5 +- .../species/GeneXmlParserTest.java | 3 +- .../celldesigner/structure/GeneTest.java | 257 +++++----- .../structure/SpeciesStateTest.java | 4 +- .../model/sbgnml/SbgnmlXmlParser.java | 3 +- .../model/sbgnml/SbgnmlXmlParserTest2.java | 4 +- .../mapviewer/model/map/species/Gene.java | 226 ++++----- .../mapviewer/model/map/species/Protein.java | 2 +- .../species/field/ElementModification.java | 2 + .../species/field/ModificationResidue.java | 28 +- .../map/species/field/ModificationSite.java | 39 ++ .../model/map/species/field/Residue.java | 39 ++ .../model/map/species/field/RnaRegion.java | 5 + .../model/map/species/GeneComparatorTest.java | 3 +- .../mapviewer/model/map/species/GeneTest.java | 181 +++---- .../map/species/ProteinComparatorTest.java | 4 +- .../model/map/species/ProteinTest.java | 211 ++++---- .../map/species/field/AllFieldTests.java | 2 +- .../field/ModificationResidueTest.java | 61 --- .../model/map/species/field/ResidueTest.java | 50 ++ .../wikipathway/XML/ModelContructor.java | 32 +- .../src/db/12.1.0~alpha.0/fix_db_20180711.sql | 5 + .../persist/dao/map/CommentDaoTest.java | 371 +++++++------- .../persist/dao/map/LayoutDaoTest.java | 460 +++++++++--------- .../persist/dao/map/ModelDaoTest.java | 7 +- .../dao/map/layout/alias/AliasDaoTest2.java | 4 +- .../elements/ElementRestImplTest.java | 5 +- 35 files changed, 1512 insertions(+), 982 deletions(-) create mode 100644 converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerGeneRegion.java create mode 100644 model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationSite.java create mode 100644 model/src/main/java/lcsb/mapviewer/model/map/species/field/Residue.java delete mode 100644 model/src/test/java/lcsb/mapviewer/model/map/species/field/ModificationResidueTest.java create mode 100644 model/src/test/java/lcsb/mapviewer/model/map/species/field/ResidueTest.java diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java index 5ff9dc7333..9810664c58 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java @@ -6,14 +6,17 @@ import org.w3c.dom.NodeList; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; +import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser; import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerGene; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; /** * Class that performs parsing of the CellDesigner xml for @@ -89,12 +92,18 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge * @throws InvalidXmlSchemaException * thrown when input xml node doesn't follow defined schema */ - CellDesignerModificationResidue getModificationResidue(Node residueNode) throws InvalidXmlSchemaException { - CellDesignerModificationResidue residue = new CellDesignerModificationResidue(); + CellDesignerGeneRegion getModificationResidue(Node residueNode) throws InvalidXmlSchemaException { + CellDesignerGeneRegion residue = new CellDesignerGeneRegion(); residue.setIdModificationResidue(getNodeAttr("id", residueNode)); residue.setName(getNodeAttr("name", residueNode)); residue.setSide(getNodeAttr("side", residueNode)); residue.setAngle(getNodeAttr("pos", residueNode)); + String type = getNodeAttr("type", residueNode); + if (type.equals("Modification Site")) { + residue.setModificationType("MODIFICATION_SITE"); + } else if (!type.equals("")) { + throw new NotImplementedException("Unknown type: " + type); + } NodeList list = residueNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); @@ -152,6 +161,9 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge if (!mr.getName().equals("")) { attributes += " name=\"" + escapeXml(mr.getName()) + "\""; } + if (mr instanceof ModificationSite) { + attributes += " type=\"Modification Site\""; + } attributes += " pos=\"" + converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()) + "\""; result += "<celldesigner:region " + attributes + ">"; result += "</celldesigner:region>\n"; diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java index 5e841c9319..6a54e8e212 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java @@ -161,6 +161,7 @@ public class ProteinXmlParser extends AbstractElementXmlParser<CellDesignerProte residue.setName(getNodeAttr("name", residueNode)); residue.setSide(getNodeAttr("side", residueNode)); residue.setAngle(getNodeAttr("angle", residueNode)); + residue.setModificationType("RESIDUE"); NodeList list = residueNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java index c573707a20..02fb359838 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java @@ -21,6 +21,7 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSimpleMolecule; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerRnaRegion; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState; @@ -211,7 +212,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec attributesBuilder.append(" constant=\"" + species.getConstant().toString().toLowerCase() + "\""); } if (species.getBoundaryCondition() != null) { - attributesBuilder.append(" boundaryCondition=\"" + species.getBoundaryCondition().toString().toLowerCase() + "\""); + attributesBuilder + .append(" boundaryCondition=\"" + species.getBoundaryCondition().toString().toLowerCase() + "\""); } Compartment comp = null; @@ -444,7 +446,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec throw new NotImplementedException("StructuralState not supported in Gene"); } for (CellDesignerModificationResidue mr : state.getModifications()) { - gene.addModificationResidue(mr); + gene.addModificationResidue(createGeneRegion(mr)); } } else if (species instanceof CellDesignerProtein) { CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; @@ -490,6 +492,23 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec } + private CellDesignerGeneRegion createGeneRegion(CellDesignerModificationResidue mr) { + CellDesignerGeneRegion region = new CellDesignerGeneRegion(); + region.setIdModificationResidue(mr.getIdModificationResidue()); + if (mr.getSize() != null) { + region.setSize(mr.getSize()); + } + region.setState(mr.getState()); + region.setName(mr.getName()); + if (mr.getAngle() != null) { + region.setAngle(mr.getAngle()); + } + if (mr.getModificationType() != null) { + region.setModificationType(mr.getModificationType()); + } + return region; + } + /** * Creates {@link SpeciesState} from xml node. * @@ -549,7 +568,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec } /** - * Creates {@link CellDesignerModificationResidue} from the apropriate xml node. + * Creates {@link CellDesignerModificationResidue} from the appropriate xml + * node. * * @param rootNode * xml node @@ -632,7 +652,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec * * @param mr * object from which we create {@link CellDesignerRnaRegion} - * @return {@link CellDesignerRnaRegion} object created from param + * @return {@link CellDesignerRnaRegion} object created from parameter */ public CellDesignerRnaRegion createRnaRegion(CellDesignerModificationResidue mr) { CellDesignerRnaRegion result = new CellDesignerRnaRegion(); diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGene.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGene.java index e7001e7286..c184bc570e 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGene.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGene.java @@ -4,9 +4,8 @@ import java.util.ArrayList; import java.util.List; import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; -import lcsb.mapviewer.model.map.species.AntisenseRna; import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.Species; @@ -26,7 +25,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { /** * List of modifications for the Gene. */ - private List<CellDesignerModificationResidue> modificationResidues = new ArrayList<>(); + private List<CellDesignerGeneRegion> modificationResidues = new ArrayList<>(); /** * Constructor that initializes gene with the data passed in the argument. @@ -38,8 +37,8 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { super(species); if (species instanceof CellDesignerGene) { CellDesignerGene gene = (CellDesignerGene) species; - for (CellDesignerModificationResidue mr : gene.getModificationResidues()) { - addModificationResidue(new CellDesignerModificationResidue(mr)); + for (CellDesignerGeneRegion mr : gene.getModificationResidues()) { + addModificationResidue(new CellDesignerGeneRegion(mr)); } } } @@ -50,7 +49,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { if (species instanceof CellDesignerGene) { CellDesignerGene gene = (CellDesignerGene) species; - for (CellDesignerModificationResidue mr : gene.getModificationResidues()) { + for (CellDesignerGeneRegion mr : gene.getModificationResidues()) { addModificationResidue(mr); } } @@ -76,10 +75,10 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { * Adds modification to the gene. * * @param modificationResidue - * modifiaction to add + * modification to add */ - public void addModificationResidue(CellDesignerModificationResidue modificationResidue) { - for (CellDesignerModificationResidue mr : modificationResidues) { + public void addModificationResidue(CellDesignerGeneRegion modificationResidue) { + for (CellDesignerGeneRegion mr : modificationResidues) { if (mr.getIdModificationResidue().equals(modificationResidue.getIdModificationResidue())) { mr.update(modificationResidue); return; @@ -94,7 +93,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { * @return the modificationResidues * @see #modificationResidues */ - public List<CellDesignerModificationResidue> getModificationResidues() { + public List<CellDesignerGeneRegion> getModificationResidues() { return modificationResidues; } @@ -103,7 +102,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { * the modificationResidues to set * @see #modificationResidues */ - public void setModificationResidues(List<CellDesignerModificationResidue> modificationResidues) { + public void setModificationResidues(List<CellDesignerGeneRegion> modificationResidues) { this.modificationResidues = modificationResidues; } @@ -116,8 +115,8 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> { @Override public void updateModelElementAfterLayoutAdded(Species element) { - for (CellDesignerModificationResidue region : modificationResidues) { - ((Gene) element).addModificationResidue(region.createModificationResidueAlias(element)); + for (CellDesignerGeneRegion region : modificationResidues) { + ((Gene) element).addModificationResidue(region.createGeneModification(element)); } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java index 6e80e6bb94..12892adc56 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java @@ -152,7 +152,7 @@ public class CellDesignerProtein<T extends Protein> extends CellDesignerSpecies< @Override public void updateModelElementAfterLayoutAdded(Species element) { for (CellDesignerModificationResidue mr : modificationResidues) { - ((Protein) element).addModificationResidue(mr.createModificationResidueAlias(element)); + ((Protein) element).addModificationResidue(mr.createProteinModification(element)); } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerGeneRegion.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerGeneRegion.java new file mode 100644 index 0000000000..732b54d238 --- /dev/null +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerGeneRegion.java @@ -0,0 +1,372 @@ +package lcsb.mapviewer.converter.model.celldesigner.structure.fields; + +import java.io.Serializable; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter; +import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies; +import lcsb.mapviewer.model.map.species.Element; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; +import lcsb.mapviewer.model.map.species.field.ModificationState; + +/** + * This class represent modification residue in protein and gene. However, it is + * sometimes also used for storing information about AntisenseRna/Rna regions... + * (due to CellDesigner xml strange structure). + * + * @author Piotr Gawron + * + */ +public class CellDesignerGeneRegion implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(CellDesignerGeneRegion.class.getName()); + + /** + * Identifier of the modification. Must be unique in single map model. + */ + private String idModificationResidue = ""; + + /** + * Name of the modification. + */ + private String name = ""; + + private String modificationType; + + /** + * Some strange parameter in CellDesigner. No idea what is it for. + */ + private String side = ""; + + /** + * State in which this modification is. + */ + private ModificationState state = null; + + /** + * Where this modification is located (on which side of the border). + */ + private Double angle = null; + + /** + * How big is this modification (used only for some types of the modification). + */ + private Double size = null; + + /** + * Species to which this modification belong to. + */ + private CellDesignerSpecies<?> species; + + /** + * Default constructor. + */ + public CellDesignerGeneRegion() { + } + + /** + * Constructor that initialize object with the data taken from the parameter. + * + * @param mr + * original object from which data is taken + */ + public CellDesignerGeneRegion(CellDesignerGeneRegion mr) { + this.idModificationResidue = mr.idModificationResidue; + this.name = mr.name; + this.angle = mr.angle; + this.size = mr.size; + this.side = mr.side; + this.state = mr.state; + this.modificationType = mr.getModificationType(); + + logger.debug(this); + } + + /** + * Constructor that creates object from model representation of modification. + * + * @param mr + * model representation of {@link ModificationResidue} + */ + public CellDesignerGeneRegion(ModificationResidue mr) { + CellDesignerAliasConverter converter = new CellDesignerAliasConverter(mr.getSpecies(), false); + this.setIdModificationResidue(mr.getIdModificationResidue()); + this.name = mr.getName(); + this.angle = converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()); + this.state = mr.getState(); + if (mr instanceof ModificationSite) { + this.setModificationType("MODIFICATION_SITE"); + } else { + throw new InvalidArgumentException("Unknown gene modification: " + mr.getClass()); + } + logger.debug(this); + } + + /** + * Default constructor. + * + * @param id + * identifier of the modification residue + */ + public CellDesignerGeneRegion(String id) { + this.idModificationResidue = id; + } + + /** + * Updates fields in the object with the data given in the parameter + * modification. + * + * @param mr + * modification residue from which data will be used to update + */ + public void update(CellDesignerGeneRegion mr) { + if (mr.getName() != null && !mr.getName().equals("")) { + this.name = mr.name; + } + if (mr.getAngle() != null) { + this.angle = mr.angle; + } + if (mr.getSize() != null) { + this.size = mr.size; + } + if (mr.getSide() != null && !mr.getSide().equals("")) { + this.side = mr.side; + } + if (mr.getState() != null) { + this.state = mr.state; + } + if (mr.getModificationType() != null) { + this.setModificationType(mr.modificationType); + } + } + + @Override + public String toString() { + String result = getIdModificationResidue() + "," + getName() + "," + getState() + "," + getAngle() + "," + getSize() + + "," + getSide() + "," + getModificationType(); + return result; + } + + /** + * Creates copy of the object. + * + * @return copy of the object. + */ + public CellDesignerGeneRegion copy() { + if (this.getClass() == CellDesignerGeneRegion.class) { + return new CellDesignerGeneRegion(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + + /** + * Sets {@link #angle} . + * + * @param text + * angle in text format + */ + public void setAngle(String text) { + try { + if (text != null && !text.equals("")) { + angle = Double.parseDouble(text); + } else { + angle = null; + } + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid angle: " + text, e); + } + + } + + /** + * Sets {@link #size}. + * + * @param text + * size in text format. + */ + public void setSize(String text) { + try { + if (text != null && !text.equals("")) { + size = Double.parseDouble(text); + } else { + size = null; + } + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid size: " + text, e); + } + } + + /** + * @return the id + * @see #idModificationResidue + */ + public String getIdModificationResidue() { + return idModificationResidue; + } + + /** + * @param idModificationResidue + * the id to set + * @see #idModificationResidue + */ + public void setIdModificationResidue(String idModificationResidue) { + this.idModificationResidue = idModificationResidue; + } + + /** + * @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 side + * @see #side + */ + public String getSide() { + return side; + } + + /** + * @param side + * the side to set + * @see #side + */ + public void setSide(String side) { + this.side = side; + } + + /** + * @return the state + * @see #state + */ + public ModificationState getState() { + return state; + } + + /** + * @param state + * the state to set + * @see #state + */ + public void setState(ModificationState state) { + this.state = state; + } + + /** + * @return the angle + * @see #angle + */ + public Double getAngle() { + return angle; + } + + /** + * @param angle + * the angle to set + * @see #angle + */ + public void setAngle(Double angle) { + this.angle = angle; + } + + /** + * @return the size + * @see #size + */ + public Double getSize() { + return size; + } + + /** + * @param size + * the size to set + * @see #size + */ + public void setSize(Double size) { + this.size = size; + } + + /** + * @return the species + * @see #species + */ + public CellDesignerSpecies<?> getSpecies() { + return species; + } + + /** + * @param species + * the species to set + * @see #species + */ + public void setSpecies(CellDesignerSpecies<?> species) { + this.species = species; + } + + /** + * Creates model representation of {@link ModificationResidue}. + * + * @return {@link ModificationResidue} representing this object in a model + */ + public ModificationResidue createGeneModification(Element element) { + CellDesignerAliasConverter converter = new CellDesignerAliasConverter(element, false); + ModificationResidue result; + + if (modificationType == null) { + logger.debug(this); + throw new InvalidArgumentException("Unknown gene modification type"); + } else if (modificationType.equals("MODIFICATION_SITE")) { + result = new ModificationSite(); + } else { + logger.debug(this); + throw new InvalidArgumentException("Unknown gene modification type: " + modificationType); + } + + result.setIdModificationResidue(this.getIdModificationResidue()); + result.setName(this.getName()); + if (angle == null) { + logger.warn("Angle is not defined using 0 as default"); + angle = 0.0; + } + result.setPosition(converter.getResidueCoordinates(element, angle)); + result.setState(this.getState()); + return result; + } + + public String getModificationType() { + return modificationType; + } + + public void setModificationType(String modificationType) { + if (modificationType == null) { + throw new NullPointerException(); + } + this.modificationType = modificationType; + } + +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerModificationResidue.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerModificationResidue.java index 00ed521672..341836fc7c 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerModificationResidue.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerModificationResidue.java @@ -10,7 +10,9 @@ import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasCon import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.ModificationState; +import lcsb.mapviewer.model.map.species.field.Residue; /** * This class represent modification residue in protein and gene. However, it is @@ -30,7 +32,6 @@ public class CellDesignerModificationResidue implements Serializable { /** * Default class logger. */ - @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(CellDesignerModificationResidue.class.getName()); /** @@ -43,6 +44,8 @@ public class CellDesignerModificationResidue implements Serializable { */ private String name = ""; + private String modificationType; + /** * Some strange parameter in CellDesigner. No idea what is it for. */ @@ -87,6 +90,7 @@ public class CellDesignerModificationResidue implements Serializable { this.size = mr.size; this.side = mr.side; this.state = mr.state; + this.modificationType = mr.modificationType; } /** @@ -101,6 +105,13 @@ public class CellDesignerModificationResidue implements Serializable { this.name = mr.getName(); this.angle = converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()); this.state = mr.getState(); + if (mr instanceof Residue) { + this.modificationType = "RESIDUE"; + } else if (mr instanceof ModificationSite) { + this.modificationType = "MODIFICATION_SITE"; + } else { + throw new InvalidArgumentException("Unknown modification type: " + mr.getClass()); + } } /** @@ -136,6 +147,9 @@ public class CellDesignerModificationResidue implements Serializable { if (mr.getState() != null) { this.state = mr.state; } + if (mr.getModificationType() != null) { + this.setModificationType(mr.modificationType); + } } @Override @@ -319,10 +333,17 @@ public class CellDesignerModificationResidue implements Serializable { * * @return {@link ModificationResidue} representing this object in a model */ - public ModificationResidue createModificationResidueAlias(Element element) { + public ModificationResidue createProteinModification(Element element) { CellDesignerAliasConverter converter = new CellDesignerAliasConverter(element, false); - ModificationResidue result = new ModificationResidue(); + ModificationResidue result = null; + if (modificationType == null) { + throw new InvalidArgumentException("No type information for modification: " + idModificationResidue); + } else if (modificationType.equals("RESIDUE")) { + result = new Residue(); + } else { + throw new InvalidArgumentException("Unknown protein modification type: " + modificationType); + } result.setIdModificationResidue(this.getIdModificationResidue()); result.setName(this.getName()); @@ -335,4 +356,12 @@ public class CellDesignerModificationResidue implements Serializable { return result; } + public String getModificationType() { + return modificationType; + } + + public void setModificationType(String modificationType) { + this.modificationType = modificationType; + } + } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/SpeciesState.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/SpeciesState.java index f830143a14..c94eff8a5f 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/SpeciesState.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/SpeciesState.java @@ -41,7 +41,7 @@ public class SpeciesState { /** * List of species modification. */ - private List<CellDesignerModificationResidue> modifications = new ArrayList<CellDesignerModificationResidue>(); + private List<CellDesignerModificationResidue> modifications = new ArrayList<>(); /** * Adds modification to the state. diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java index 6f97c0fbcd..362268ede5 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.mockito.Mockito; import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.InvalidInputDataExecption; @@ -120,8 +121,8 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { CellDesignerXmlParser parser = new CellDesignerXmlParser(); parser.createModel(new ConverterParams().filename("testFiles/invalid/sample10.xml")); fail("Exceptin expected"); - } catch (InvalidInputDataExecption e) { - assertTrue(e.getMessage().contains("Unknown element of model/listOfReactions")); + } catch (InvalidArgumentException e) { + assertTrue(e.getMessage().contains("No type information for modification")); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java index 1402647401..da9e20d35c 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java @@ -30,6 +30,7 @@ import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationState; +import lcsb.mapviewer.model.map.species.field.Residue; public class GeneXmlParserTest extends CellDesignerTestFunctions { Logger logger = Logger.getLogger(GeneXmlParserTest.class.getName()); @@ -155,7 +156,7 @@ public class GeneXmlParserTest extends CellDesignerTestFunctions { protein.setY(10); protein.setWidth(10); protein.setHeight(10); - ModificationResidue mr = new ModificationResidue(); + Residue mr = new Residue(); mr.setIdModificationResidue("i"); mr.setName("a"); mr.setPosition(new Point2D.Double(3.0, 2.0)); diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/GeneTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/GeneTest.java index d3ab45debf..d58377255b 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/GeneTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/GeneTest.java @@ -1,128 +1,129 @@ -package lcsb.mapviewer.converter.model.celldesigner.structure; - -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.List; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; -import lcsb.mapviewer.model.map.species.Gene; - -public class GeneTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new CellDesignerGene()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor1() { - try { - CellDesignerGene original = new CellDesignerGene(); - original.addModificationResidue(new CellDesignerModificationResidue()); - CellDesignerGene gene = new CellDesignerGene(original); - assertNotNull(gene); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - List<CellDesignerModificationResidue> modificationResidues = new ArrayList<>(); - CellDesignerGene gene = new CellDesignerGene(new CellDesignerSpecies<Gene>()); - gene.setModificationResidues(modificationResidues); - assertEquals(modificationResidues, gene.getModificationResidues()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - CellDesignerGene degraded = new CellDesignerGene().copy(); - assertNotNull(degraded); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - CellDesignerGene gene = Mockito.spy(CellDesignerGene.class); - gene.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate() { - try { - CellDesignerGene gene = new CellDesignerGene(); - CellDesignerGene gene2 = new CellDesignerGene(); - List<CellDesignerModificationResidue> residues = new ArrayList<>(); - residues.add(new CellDesignerModificationResidue()); - - gene2.setModificationResidues(residues); - - gene.update(gene2); - assertEquals(1, gene.getModificationResidues().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddModificationResidue() { - try { - CellDesignerGene gene = new CellDesignerGene(); - CellDesignerModificationResidue mr = new CellDesignerModificationResidue("id1"); - CellDesignerModificationResidue mr2 = new CellDesignerModificationResidue("id1"); - CellDesignerModificationResidue mr3 = new CellDesignerModificationResidue("id2"); - - gene.addModificationResidue(mr); - assertEquals(1, gene.getModificationResidues().size()); - gene.addModificationResidue(mr2); - assertEquals(1, gene.getModificationResidues().size()); - gene.addModificationResidue(mr3); - assertEquals(2, gene.getModificationResidues().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.converter.model.celldesigner.structure; + +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.List; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; +import lcsb.mapviewer.model.map.species.Gene; + +public class GeneTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new CellDesignerGene()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor1() { + try { + CellDesignerGene original = new CellDesignerGene(); + original.addModificationResidue(new CellDesignerGeneRegion()); + CellDesignerGene gene = new CellDesignerGene(original); + assertNotNull(gene); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + List<CellDesignerGeneRegion> modificationResidues = new ArrayList<>(); + CellDesignerGene gene = new CellDesignerGene(new CellDesignerSpecies<>()); + gene.setModificationResidues(modificationResidues); + assertEquals(modificationResidues, gene.getModificationResidues()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + CellDesignerGene degraded = new CellDesignerGene().copy(); + assertNotNull(degraded); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + CellDesignerGene gene = Mockito.spy(CellDesignerGene.class); + gene.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate() { + try { + CellDesignerGene gene = new CellDesignerGene(); + CellDesignerGene gene2 = new CellDesignerGene(); + List<CellDesignerGeneRegion> residues = new ArrayList<>(); + residues.add(new CellDesignerGeneRegion()); + + gene2.setModificationResidues(residues); + + gene.update(gene2); + assertEquals(1, gene.getModificationResidues().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddModificationResidue() { + try { + CellDesignerGene gene = new CellDesignerGene(); + CellDesignerGeneRegion mr = new CellDesignerGeneRegion("id1"); + CellDesignerGeneRegion mr2 = new CellDesignerGeneRegion("id1"); + CellDesignerGeneRegion mr3 = new CellDesignerGeneRegion("id2"); + + gene.addModificationResidue(mr); + assertEquals(1, gene.getModificationResidues().size()); + gene.addModificationResidue(mr2); + assertEquals(1, gene.getModificationResidues().size()); + gene.addModificationResidue(mr3); + assertEquals(2, gene.getModificationResidues().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesStateTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesStateTest.java index 99451f67ca..804c4f87c4 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesStateTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesStateTest.java @@ -16,7 +16,7 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState; import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.Rna; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.RnaRegion; public class SpeciesStateTest { @@ -62,7 +62,7 @@ public class SpeciesStateTest { Gene gene = new Gene("2"); gene.setWidth(60); gene.setHeight(10); - ModificationResidue mr = new ModificationResidue(); + ModificationSite mr = new ModificationSite(); mr.setPosition(new Point2D.Double(10, 40)); gene.addModificationResidue(mr); SpeciesState state = new SpeciesState(gene); diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java index 2aa1499af2..9bace29745 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java @@ -76,6 +76,7 @@ import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Unknown; import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationState; +import lcsb.mapviewer.model.map.species.field.Residue; /** * This class is a parser for SBGN-ML files. @@ -799,7 +800,7 @@ public class SbgnmlXmlParser { throw new Exception("Only macromolecule elements can have state variables."); } Protein protein = (Protein) newSpecies; - ModificationResidue mr = new ModificationResidue(); + ModificationResidue mr = new Residue(); mr.setSpecies(protein); mr.setIdModificationResidue(unitOfInformationGlyph.getId()); diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java index 8f40e4864b..c4c7f7f038 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java @@ -9,7 +9,7 @@ import org.junit.Test; import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.model.map.species.GenericProtein; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.Residue; public class SbgnmlXmlParserTest2 { @@ -23,7 +23,7 @@ public class SbgnmlXmlParserTest2 { protein.setHeight(30); protein.setX(200); protein.setX(300); - ModificationResidue mr = new ModificationResidue(); + Residue mr = new Residue(); Point2D position = new Point2D.Double(100, 20); mr.setPosition(position); protein.addModificationResidue(mr); diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Gene.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Gene.java index db6c9cb840..ae7a0cfc64 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Gene.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Gene.java @@ -1,113 +1,113 @@ -package lcsb.mapviewer.model.map.species; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.OneToMany; - -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; - -/** - * Entity representing gene element on the map. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("GENE_ALIAS") -public class Gene extends Species { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * List of modifications for the Gene. - */ - @Cascade({ CascadeType.ALL }) - @OneToMany(mappedBy = "species", orphanRemoval = true) - @LazyCollection(LazyCollectionOption.FALSE) - private List<ModificationResidue> modificationResidues = new ArrayList<>(); - - /** - * Empty constructor required by hibernate. - */ - Gene() { - } - - /** - * Constructor that creates a copy of the element given in the parameter. - * - * @param original - * original object that will be used for creating copy - */ - public Gene(Gene original) { - super(original); - for (ModificationResidue mr : original.getModificationResidues()) { - addModificationResidue(new ModificationResidue(mr)); - } - } - - /** - * Default constructor. - * - * @param elementId - * uniqe (within model) element identifier - */ - public Gene(String elementId) { - setElementId(elementId); - } - - /** - * Adds {@link ModificationResidue}. - * - * @param modificationResidue - * {@link ModificationResidue} to be added - */ - public void addModificationResidue(ModificationResidue modificationResidue) { - modificationResidues.add(modificationResidue); - modificationResidue.setSpecies(this); - - } - - @Override - public Gene copy() { - if (this.getClass() == Gene.class) { - return new Gene(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - - /** - * @return the modificationResidues - * @see #modificationResidues - */ - public List<ModificationResidue> getModificationResidues() { - return modificationResidues; - } - - /** - * @param modificationResidues - * the modificationResidues to set - * @see #modificationResidues - */ - public void setModificationResidues(List<ModificationResidue> modificationResidues) { - this.modificationResidues = modificationResidues; - } - - @Override - public String getStringType() { - return "Gene"; - } - -} +package lcsb.mapviewer.model.map.species; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; + +/** + * Entity representing gene element on the map. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("GENE_ALIAS") +public class Gene extends Species { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * List of modifications for the Gene. + */ + @Cascade({ CascadeType.ALL }) + @OneToMany(mappedBy = "species", orphanRemoval = true) + @LazyCollection(LazyCollectionOption.FALSE) + private List<ModificationResidue> modificationResidues = new ArrayList<>(); + + /** + * Empty constructor required by hibernate. + */ + Gene() { + } + + /** + * Constructor that creates a copy of the element given in the parameter. + * + * @param original + * original object that will be used for creating copy + */ + public Gene(Gene original) { + super(original); + for (ModificationResidue mr : original.getModificationResidues()) { + addModificationResidue(mr.copy()); + } + } + + /** + * Default constructor. + * + * @param elementId + * uniqe (within model) element identifier + */ + public Gene(String elementId) { + setElementId(elementId); + } + + /** + * Adds {@link ModificationResidue}. + * + * @param modificationResidue + * {@link ModificationResidue} to be added + */ + public void addModificationResidue(ModificationResidue modificationResidue) { + modificationResidues.add(modificationResidue); + modificationResidue.setSpecies(this); + + } + + @Override + public Gene copy() { + if (this.getClass() == Gene.class) { + return new Gene(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + + /** + * @return the modificationResidues + * @see #modificationResidues + */ + public List<ModificationResidue> getModificationResidues() { + return modificationResidues; + } + + /** + * @param modificationResidues + * the modificationResidues to set + * @see #modificationResidues + */ + public void setModificationResidues(List<ModificationResidue> modificationResidues) { + this.modificationResidues = modificationResidues; + } + + @Override + public String getStringType() { + return "Gene"; + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java index 9e891ddd9d..8f4cf0ecf0 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java @@ -58,7 +58,7 @@ public abstract class Protein extends Species { super(original); this.structuralState = original.getStructuralState(); for (ModificationResidue mr : original.getModificationResidues()) { - addModificationResidue(new ModificationResidue(mr)); + addModificationResidue(mr.copy()); } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/ElementModification.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/ElementModification.java index 97db98c8d9..e9bd63b9f5 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/ElementModification.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/ElementModification.java @@ -4,4 +4,6 @@ public interface ElementModification { ModificationState getState(); String getName(); + + ElementModification copy(); } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationResidue.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationResidue.java index 34d6a87ef9..c088c3f6f1 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationResidue.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationResidue.java @@ -4,7 +4,11 @@ import java.awt.geom.Point2D; import java.io.Serializable; import java.text.DecimalFormat; +import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -12,6 +16,8 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @@ -30,8 +36,12 @@ import lcsb.mapviewer.model.map.species.Species; * @author Piotr Gawron * */ + @Entity @Table(name = "modification_residue_table") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "modification_type", discriminatorType = DiscriminatorType.STRING) +@DiscriminatorValue("GENERIC_MODIFICATION_RESIDUE") @org.hibernate.annotations.GenericGenerator(name = "test-increment-strategy", strategy = "increment") public class ModificationResidue implements Serializable, ElementModification { @@ -77,7 +87,7 @@ public class ModificationResidue implements Serializable, ElementModification { /** * Species to which this modification belong to. */ - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "idSpeciesDb", nullable = false) private Species species; @@ -108,18 +118,6 @@ public class ModificationResidue implements Serializable, ElementModification { return result; } - /** - * Creates copy of the object. - * - * @return copy of the object. - */ - public ModificationResidue copy() { - if (this.getClass() == ModificationResidue.class) { - return new ModificationResidue(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } /** * @return the idModificationResidue @@ -213,5 +211,9 @@ public class ModificationResidue implements Serializable, ElementModification { public void setPosition(Point2D position) { this.position = position; } + + public ModificationResidue copy() { + throw new NotImplementedException(); + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationSite.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationSite.java new file mode 100644 index 0000000000..390c963779 --- /dev/null +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/ModificationSite.java @@ -0,0 +1,39 @@ +package lcsb.mapviewer.model.map.species.field; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +@Entity +@DiscriminatorValue("MODIFICATION_SITE") +public class ModificationSite extends ModificationResidue { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ModificationSite() { + super(); + } + + public ModificationSite(ModificationSite residue) { + super(residue); + } + + + /** + * Creates copy of the object. + * + * @return copy of the object. + */ + public ModificationSite copy() { + if (this.getClass() == ModificationSite.class) { + return new ModificationSite(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/Residue.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/Residue.java new file mode 100644 index 0000000000..b03b751004 --- /dev/null +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/Residue.java @@ -0,0 +1,39 @@ +package lcsb.mapviewer.model.map.species.field; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +@Entity +@DiscriminatorValue("RESIDUE") +public class Residue extends ModificationResidue { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public Residue() { + super(); + } + + public Residue(Residue residue) { + super(residue); + } + + + /** + * Creates copy of the object. + * + * @return copy of the object. + */ + public Residue copy() { + if (this.getClass() == Residue.class) { + return new Residue(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/RnaRegion.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/RnaRegion.java index 2d0cd9b20b..0b245815db 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/RnaRegion.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/RnaRegion.java @@ -278,4 +278,9 @@ public class RnaRegion implements Serializable, ElementModification { this.width = width; } + @Override + public RnaRegion copy() { + return new RnaRegion(this); + } + } diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java index 3a28ecf6ae..34dc67ef01 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java @@ -13,6 +13,7 @@ import org.mockito.Mockito; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.ModificationState; public class GeneComparatorTest { @@ -81,7 +82,7 @@ public class GeneComparatorTest { Gene result = new Gene(); result.setHypothetical(true); - ModificationResidue residue = new ModificationResidue(); + ModificationSite residue = new ModificationSite(); result.addModificationResidue(residue); residue.setIdModificationResidue("a"); diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/GeneTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/GeneTest.java index ec7c48dcd1..5dd200337e 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/GeneTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/GeneTest.java @@ -1,90 +1,91 @@ -package lcsb.mapviewer.model.map.species; - -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.List; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; - -public class GeneTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Gene()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor1() { - try { - Gene original = new Gene(); - original.addModificationResidue(new ModificationResidue()); - Gene gene = new Gene(original); - assertNotNull(gene); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - List<ModificationResidue> modificationResidues = new ArrayList<>(); - Gene gene = new Gene("id"); - assertNotNull(gene.getStringType()); - gene.setModificationResidues(modificationResidues); - assertEquals(modificationResidues, gene.getModificationResidues()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - Gene degraded = new Gene().copy(); - assertNotNull(degraded); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - Gene gene = Mockito.spy(Gene.class); - gene.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.species; + +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.List; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; + +public class GeneTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Gene()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor1() { + try { + Gene original = new Gene(); + original.addModificationResidue(new ModificationSite()); + Gene gene = new Gene(original); + assertNotNull(gene); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + List<ModificationResidue> modificationResidues = new ArrayList<>(); + Gene gene = new Gene("id"); + assertNotNull(gene.getStringType()); + gene.setModificationResidues(modificationResidues); + assertEquals(modificationResidues, gene.getModificationResidues()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + Gene degraded = new Gene().copy(); + assertNotNull(degraded); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + Gene gene = Mockito.spy(Gene.class); + gene.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinComparatorTest.java index a118f593ed..4f3a722d8d 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinComparatorTest.java @@ -12,8 +12,8 @@ import org.junit.Test; import org.mockito.Mockito; import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationState; +import lcsb.mapviewer.model.map.species.field.Residue; public class ProteinComparatorTest { @@ -123,7 +123,7 @@ public class ProteinComparatorTest { result.setStructuralState("id1"); result.setHypothetical(true); - ModificationResidue residue = new ModificationResidue(); + Residue residue = new Residue(); result.addModificationResidue(residue); residue.setIdModificationResidue("a"); diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinTest.java index 0a3a22c3db..6485005ac7 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/ProteinTest.java @@ -1,105 +1,106 @@ -package lcsb.mapviewer.model.map.species; - -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.List; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; - -public class ProteinTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new GenericProtein()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor1() { - try { - GenericProtein protein = new GenericProtein(); - protein.setStructuralState("srt"); - List<ModificationResidue> residues = new ArrayList<>(); - residues.add(new ModificationResidue()); - - protein.setModificationResidues(residues); - Protein protein2 = new GenericProtein(protein); - assertNotNull(protein2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetStructuralState() { - try { - GenericProtein protein = new GenericProtein(); - protein.setStructuralState("str"); - protein.setStructuralState("str1"); - - assertEquals("str1", protein.getStructuralState()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - GenericProtein protein = new GenericProtein("id"); - assertNotNull(protein.getStringType()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - GenericProtein protein = new GenericProtein().copy(); - assertNotNull(protein); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - GenericProtein mock = Mockito.spy(GenericProtein.class); - mock.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.species; + +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.List; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.Residue; + +public class ProteinTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new GenericProtein()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor1() { + try { + GenericProtein protein = new GenericProtein(); + protein.setStructuralState("srt"); + List<ModificationResidue> residues = new ArrayList<>(); + residues.add(new Residue()); + + protein.setModificationResidues(residues); + Protein protein2 = new GenericProtein(protein); + assertNotNull(protein2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetStructuralState() { + try { + GenericProtein protein = new GenericProtein(); + protein.setStructuralState("str"); + protein.setStructuralState("str1"); + + assertEquals("str1", protein.getStructuralState()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + GenericProtein protein = new GenericProtein("id"); + assertNotNull(protein.getStringType()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + GenericProtein protein = new GenericProtein().copy(); + assertNotNull(protein); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + GenericProtein mock = Mockito.spy(GenericProtein.class); + mock.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/field/AllFieldTests.java b/model/src/test/java/lcsb/mapviewer/model/map/species/field/AllFieldTests.java index 512ff1dab9..de4bd79233 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/field/AllFieldTests.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/field/AllFieldTests.java @@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses; @SuiteClasses({ AntisenseRnaRegionTest.class, // AntisenseRnaRegionTypeTest.class, // ModificationStateTest.class, // - ModificationResidueTest.class, // + ResidueTest.class, // PositionToCompartmentTest.class, // RnaRegionTest.class,// StructureTest.class,// diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/field/ModificationResidueTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/field/ModificationResidueTest.java deleted file mode 100644 index 6b839c1379..0000000000 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/field/ModificationResidueTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package lcsb.mapviewer.model.map.species.field; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.GenericProtein; -import lcsb.mapviewer.model.map.species.Species; - -public class ModificationResidueTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGetters() { - ModificationResidue mr = new ModificationResidue(); - Species species = new GenericProtein("id"); - int id = 94; - - mr.setSpecies(species); - mr.setId(id); - - assertEquals(species, mr.getSpecies()); - assertEquals(id, mr.getId()); - } - - @Test - public void testCopy() { - ModificationResidue mr = new ModificationResidue().copy(); - assertNotNull(mr); - } - - @Test - public void testInvalidCopy() { - ModificationResidue mr = Mockito.spy(ModificationResidue.class); - try { - mr.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - - } - } - -} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/field/ResidueTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/field/ResidueTest.java new file mode 100644 index 0000000000..ff9289bb27 --- /dev/null +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/field/ResidueTest.java @@ -0,0 +1,50 @@ +package lcsb.mapviewer.model.map.species.field; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.species.GenericProtein; +import lcsb.mapviewer.model.map.species.Species; + +public class ResidueTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetters() { + Residue mr = new Residue(); + Species species = new GenericProtein("id"); + int id = 94; + + mr.setSpecies(species); + mr.setId(id); + + assertEquals(species, mr.getSpecies()); + assertEquals(id, mr.getId()); + } + + @Test + public void testCopy() { + Residue mr = new Residue().copy(); + assertNotNull(mr); + } + +} 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 df349b05bb..90aed61065 100644 --- a/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java +++ b/pathvisio/src/main/java/lcsb/mapviewer/wikipathway/XML/ModelContructor.java @@ -60,6 +60,8 @@ import lcsb.mapviewer.model.map.species.SimpleMolecule; import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Unknown; import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; +import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.modelutils.map.ElementUtils; import lcsb.mapviewer.wikipathway.model.DataNode; import lcsb.mapviewer.wikipathway.model.Edge; @@ -309,8 +311,8 @@ public class ModelContructor { } alias.setX(rec.getX()); alias.setY(rec.getY()); - alias.setWidth((int)rec.getWidth()); - alias.setHeight((int)rec.getHeight()); + alias.setWidth((int) rec.getWidth()); + alias.setHeight((int) rec.getHeight()); alias.setColor(DEFAULT_COMPLEX_ALIAS_COLOR); data.id2alias.put(group.getGraphId(), alias); @@ -383,23 +385,27 @@ public class ModelContructor { // TODO this might not work Element species = data.id2alias.get(state.getGraphRef()); if (state.getType() != null) { - ModificationResidue mr = new ModificationResidue(); - mr.setIdModificationResidue(state.getGraphId()); - mr.setState(state.getType()); - - Double x = state.getRelX() * species.getWidth() / 2 + species.getCenterX(); - Double y = state.getRelY() * species.getHeight() / 2 + species.getCenterY(); - mr.setPosition(new Point2D.Double(x, y)); + ModificationResidue mr = null; if (species instanceof Protein) { + mr = new Residue(); ((Protein) species).addModificationResidue(mr); } else if (species instanceof Gene) { + mr = new ModificationSite(); ((Gene) species).addModificationResidue(mr); } else { logger.warn( state.getWarningPrefix() + "state for " + species.getClass().getSimpleName() + " is not supported."); } - adjustModificationCoordinates(species); + if (mr != null) { + mr.setIdModificationResidue(state.getGraphId()); + mr.setState(state.getType()); + + Double x = state.getRelX() * species.getWidth() / 2 + species.getCenterX(); + Double y = state.getRelY() * species.getHeight() / 2 + species.getCenterY(); + mr.setPosition(new Point2D.Double(x, y)); + adjustModificationCoordinates(species); + } } else if (state.getStructuralState() != null) { if (species instanceof Protein) { Protein protein = ((Protein) species); @@ -442,7 +448,7 @@ public class ModelContructor { mr.setPosition(converter.getResidueCoordinates(species, angle)); } } - + } } @@ -532,8 +538,8 @@ public class ModelContructor { Rectangle2D rec = gpmlElement.getRectangle(); alias.setX(rec.getX()); alias.setY(rec.getY()); - alias.setWidth((int)rec.getWidth()); - alias.setHeight((int)rec.getHeight()); + alias.setWidth((int) rec.getWidth()); + alias.setHeight((int) rec.getHeight()); alias.setColor(gpmlElement.getFillColor()); return alias; } diff --git a/persist/src/db/12.1.0~alpha.0/fix_db_20180711.sql b/persist/src/db/12.1.0~alpha.0/fix_db_20180711.sql index dad28041e7..095168533e 100644 --- a/persist/src/db/12.1.0~alpha.0/fix_db_20180711.sql +++ b/persist/src/db/12.1.0~alpha.0/fix_db_20180711.sql @@ -2,3 +2,8 @@ alter table rna_region_table add column width numeric(6,2); update rna_region_table set width=element_table.width*rna_region_table.size from element_table where element_table.iddb = rna_region_table.idspeciesdb and not size is null; alter table rna_region_table drop column size; + +--modifications includes different type of modification (that will be resolved to different classes) +alter table modification_residue_table add column modification_type varchar(255); +update modification_residue_table set modification_type='MODIFICATION_SITE' from element_table where modification_residue_table.idspeciesdb=element_table.iddb and element_type_db='GENE_ALIAS'; +update modification_residue_table set modification_type='RESIDUE' from element_table where modification_residue_table.idspeciesdb=element_table.iddb and modification_type is null; diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java index b18a7cba2a..e00f0b9d3a 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java @@ -1,185 +1,186 @@ -package lcsb.mapviewer.persist.dao.map; - -import static org.junit.Assert.assertEquals; - -import java.awt.Color; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.model.Project; -import lcsb.mapviewer.model.map.Comment; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamRelationType; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.compartment.Compartment; -import lcsb.mapviewer.model.map.layout.graphics.Layer; -import lcsb.mapviewer.model.map.layout.graphics.LayerRect; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelFullIndexed; -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.Complex; -import lcsb.mapviewer.model.map.species.GenericProtein; -import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; -import lcsb.mapviewer.persist.PersistTestFunctions; - -public class CommentDaoTest extends PersistTestFunctions { - int identifierCounter = 1; - - private Project project; - String projectId = "Some_id"; - - @Before - public void setUp() throws Exception { - project = projectDao.getProjectByProjectId(projectId); - if (project != null) { - projectDao.delete(project); - } - project = new Project(); - project.setProjectId(projectId); - projectDao.add(project); - } - - @After - public void tearDown() throws Exception { - projectDao.delete(project); - } - - @Test - public void testGetComments() { - try { - Model model = createModel(); - project.addModel(model); - modelDao.add(model); - projectDao.update(project); - - Comment comment = new Comment(); - comment.setDeleted(true); - comment.setModel(model); - commentDao.add(comment); - - Comment comment2 = new Comment(); - comment2.setPinned(true); - comment2.setModel(model); - commentDao.add(comment2); - - assertEquals(0, commentDao.getCommentByModel(model, true, true).size()); - assertEquals(1, commentDao.getCommentByModel(model, false, true).size()); - assertEquals(1, commentDao.getCommentByModel(model, null, true).size()); - assertEquals(1, commentDao.getCommentByModel(model, true, false).size()); - assertEquals(0, commentDao.getCommentByModel(model, false, false).size()); - assertEquals(1, commentDao.getCommentByModel(model, null, false).size()); - assertEquals(1, commentDao.getCommentByModel(model, true, null).size()); - assertEquals(1, commentDao.getCommentByModel(model, false, null).size()); - assertEquals(2, commentDao.getCommentByModel(model, null, null).size()); - - assertEquals(0, commentDao.getCommentByModel(model.getModelData(), true, true).size()); - assertEquals(1, commentDao.getCommentByModel(model.getModelData(), false, true).size()); - assertEquals(1, commentDao.getCommentByModel(model.getModelData(), null, true).size()); - assertEquals(1, commentDao.getCommentByModel(model.getModelData(), true, false).size()); - assertEquals(0, commentDao.getCommentByModel(model.getModelData(), false, false).size()); - assertEquals(1, commentDao.getCommentByModel(model.getModelData(), null, false).size()); - assertEquals(1, commentDao.getCommentByModel(model.getModelData(), true, null).size()); - assertEquals(1, commentDao.getCommentByModel(model.getModelData(), false, null).size()); - assertEquals(2, commentDao.getCommentByModel(model.getModelData(), null, null).size()); - - commentDao.delete(comment); - commentDao.delete(comment2); - modelDao.delete(model); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - private Model createModel() { - Model model = new ModelFullIndexed(null); - - GenericProtein alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2"); - model.addElement(alias); - alias = createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117"); - model.addElement(alias); - alias = createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119"); - model.addElement(alias); - alias = createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121"); - model.addElement(alias); - - alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422"); - Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419"); - Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152"); - alias3.addSpecies(alias); - alias3.addSpecies(alias2); - alias.setComplex(alias3); - alias2.setComplex(alias3); - - model.addElement(alias); - model.addElement(alias2); - model.addElement(alias3); - - Compartment cAlias = createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1"); - model.addElement(cAlias); - model.setWidth(2000); - model.setHeight(2000); - - Layer layer = new Layer(); - model.addLayer(layer); - - LayerRect lr = new LayerRect(); - lr.setColor(Color.YELLOW); - layer.addLayerRect(lr); - - Reaction reaction = new TransportReaction(); - reaction.addProduct(new Product(alias)); - reaction.addReactant(new Reactant(alias2)); - reaction.setIdReaction("re" + identifierCounter++); - model.addReaction(reaction); - - alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "pr1"); - model.addElement(alias); - - ModificationResidue mr = new ModificationResidue(); - mr.setName("mr"); - alias.addModificationResidue(mr); - - alias.addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, "c")); - return model; - } - - private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) { - Compartment alias = new Compartment(aliasId); - alias.setX(x); - alias.setY(y); - alias.setWidth(width); - alias.setHeight(height); - return alias; - } - - private GenericProtein createSpeciesAlias(double x, double y, double width, double height, String aliasId) { - GenericProtein alias = new GenericProtein(aliasId); - alias.setName("SNCA"); - alias.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA")); - alias.addMiriamData(new MiriamData(MiriamType.HGNC, "11138")); - alias.setX(x); - alias.setY(y); - alias.setWidth(width); - alias.setHeight(height); - return alias; - } - - private Complex createComplexAlias(double x, double y, double width, double height, String aliasId) { - Complex alias = new Complex(aliasId); - alias.setX(x); - alias.setY(y); - alias.setWidth(width); - alias.setHeight(height); - return alias; - } - -} +package lcsb.mapviewer.persist.dao.map; + +import static org.junit.Assert.assertEquals; + +import java.awt.Color; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.model.Project; +import lcsb.mapviewer.model.map.Comment; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamRelationType; +import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.compartment.Compartment; +import lcsb.mapviewer.model.map.layout.graphics.Layer; +import lcsb.mapviewer.model.map.layout.graphics.LayerRect; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; +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.Complex; +import lcsb.mapviewer.model.map.species.GenericProtein; +import lcsb.mapviewer.model.map.species.Species; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.Residue; +import lcsb.mapviewer.persist.PersistTestFunctions; + +public class CommentDaoTest extends PersistTestFunctions { + int identifierCounter = 1; + + private Project project; + String projectId = "Some_id"; + + @Before + public void setUp() throws Exception { + project = projectDao.getProjectByProjectId(projectId); + if (project != null) { + projectDao.delete(project); + } + project = new Project(); + project.setProjectId(projectId); + projectDao.add(project); + } + + @After + public void tearDown() throws Exception { + projectDao.delete(project); + } + + @Test + public void testGetComments() { + try { + Model model = createModel(); + project.addModel(model); + modelDao.add(model); + projectDao.update(project); + + Comment comment = new Comment(); + comment.setDeleted(true); + comment.setModel(model); + commentDao.add(comment); + + Comment comment2 = new Comment(); + comment2.setPinned(true); + comment2.setModel(model); + commentDao.add(comment2); + + assertEquals(0, commentDao.getCommentByModel(model, true, true).size()); + assertEquals(1, commentDao.getCommentByModel(model, false, true).size()); + assertEquals(1, commentDao.getCommentByModel(model, null, true).size()); + assertEquals(1, commentDao.getCommentByModel(model, true, false).size()); + assertEquals(0, commentDao.getCommentByModel(model, false, false).size()); + assertEquals(1, commentDao.getCommentByModel(model, null, false).size()); + assertEquals(1, commentDao.getCommentByModel(model, true, null).size()); + assertEquals(1, commentDao.getCommentByModel(model, false, null).size()); + assertEquals(2, commentDao.getCommentByModel(model, null, null).size()); + + assertEquals(0, commentDao.getCommentByModel(model.getModelData(), true, true).size()); + assertEquals(1, commentDao.getCommentByModel(model.getModelData(), false, true).size()); + assertEquals(1, commentDao.getCommentByModel(model.getModelData(), null, true).size()); + assertEquals(1, commentDao.getCommentByModel(model.getModelData(), true, false).size()); + assertEquals(0, commentDao.getCommentByModel(model.getModelData(), false, false).size()); + assertEquals(1, commentDao.getCommentByModel(model.getModelData(), null, false).size()); + assertEquals(1, commentDao.getCommentByModel(model.getModelData(), true, null).size()); + assertEquals(1, commentDao.getCommentByModel(model.getModelData(), false, null).size()); + assertEquals(2, commentDao.getCommentByModel(model.getModelData(), null, null).size()); + + commentDao.delete(comment); + commentDao.delete(comment2); + modelDao.delete(model); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + private Model createModel() { + Model model = new ModelFullIndexed(null); + + GenericProtein alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2"); + model.addElement(alias); + alias = createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117"); + model.addElement(alias); + alias = createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119"); + model.addElement(alias); + alias = createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121"); + model.addElement(alias); + + alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422"); + Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419"); + Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152"); + alias3.addSpecies(alias); + alias3.addSpecies(alias2); + alias.setComplex(alias3); + alias2.setComplex(alias3); + + model.addElement(alias); + model.addElement(alias2); + model.addElement(alias3); + + Compartment cAlias = createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1"); + model.addElement(cAlias); + model.setWidth(2000); + model.setHeight(2000); + + Layer layer = new Layer(); + model.addLayer(layer); + + LayerRect lr = new LayerRect(); + lr.setColor(Color.YELLOW); + layer.addLayerRect(lr); + + Reaction reaction = new TransportReaction(); + reaction.addProduct(new Product(alias)); + reaction.addReactant(new Reactant(alias2)); + reaction.setIdReaction("re" + identifierCounter++); + model.addReaction(reaction); + + alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "pr1"); + model.addElement(alias); + + ModificationResidue mr = new Residue(); + mr.setName("mr"); + alias.addModificationResidue(mr); + + alias.addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, "c")); + return model; + } + + private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) { + Compartment alias = new Compartment(aliasId); + alias.setX(x); + alias.setY(y); + alias.setWidth(width); + alias.setHeight(height); + return alias; + } + + private GenericProtein createSpeciesAlias(double x, double y, double width, double height, String aliasId) { + GenericProtein alias = new GenericProtein(aliasId); + alias.setName("SNCA"); + alias.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA")); + alias.addMiriamData(new MiriamData(MiriamType.HGNC, "11138")); + alias.setX(x); + alias.setY(y); + alias.setWidth(width); + alias.setHeight(height); + return alias; + } + + private Complex createComplexAlias(double x, double y, double width, double height, String aliasId) { + Complex alias = new Complex(aliasId); + alias.setX(x); + alias.setY(y); + alias.setWidth(width); + alias.setHeight(height); + return alias; + } + +} diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/LayoutDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/LayoutDaoTest.java index 8b67d43aa9..83572545fd 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/LayoutDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/LayoutDaoTest.java @@ -1,230 +1,230 @@ -package lcsb.mapviewer.persist.dao.map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.awt.Color; -import java.nio.charset.StandardCharsets; - -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import lcsb.mapviewer.model.Project; -import lcsb.mapviewer.model.cache.UploadedFileEntry; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamRelationType; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.compartment.Compartment; -import lcsb.mapviewer.model.map.layout.Layout; -import lcsb.mapviewer.model.map.layout.graphics.Layer; -import lcsb.mapviewer.model.map.layout.graphics.LayerRect; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelFullIndexed; -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.Complex; -import lcsb.mapviewer.model.map.species.GenericProtein; -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; -import lcsb.mapviewer.persist.PersistTestFunctions; - -public class LayoutDaoTest extends PersistTestFunctions { - - @Autowired - private LayoutDao layoutDao; - - final static Logger logger = Logger.getLogger(LayoutDaoTest.class); - - int identifierCounter = 0; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - /** - * After adding layouts to model. - * - * @throws Exception - */ - @Test - public void testLayoutsWithData() throws Exception { - try { - Model model = createModel(); - - Project project = new Project(); - project.addModel(model); - projectDao.add(project); - - modelDao.evict(model); - projectDao.evict(project); - - Layout layout = new Layout(); - layout.setDirectory("tmp"); - layout.setTitle("temporary name"); - - byte[] data = "test".getBytes(); - UploadedFileEntry fileEntry = new UploadedFileEntry(); - fileEntry.setFileContent(data); - - layout.setInputData(fileEntry); - model.addLayout(layout); - layoutDao.add(layout); - - layoutDao.evict(layout); - - layout = layoutDao.getById(layout.getId()); - - assertEquals("test", new String(layout.getInputData().getFileContent(), StandardCharsets.UTF_8)); - - project = projectDao.getById(project.getId()); - projectDao.delete(project); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - /** - * After adding layouts to model. - * - * @throws Exception - */ - @Test - public void testLayoutsWithoutData() throws Exception { - try { - Model model = createModel(); - String tempName = "temporary name"; - - createUser(); - - Project project = new Project(); - project.addModel(model); - projectDao.add(project); - - modelDao.evict(model); - projectDao.evict(project); - - assertEquals(0, layoutDao.getCountByUser(user)); - assertEquals(0, layoutDao.getLayoutsByModel(model).size()); - assertNull(layoutDao.getLayoutByName(model, tempName)); - - Layout layout = new Layout(); - layout.setDirectory("tmp"); - layout.setTitle(tempName); - layout.setCreator(user); - model.addLayout(layout); - layoutDao.add(layout); - - layoutDao.evict(layout); - - layout = layoutDao.getById(layout.getId()); - - assertEquals(1, layoutDao.getLayoutsByModel(model).size()); - assertNotNull(layoutDao.getLayoutByName(model, tempName)); - assertEquals(1, layoutDao.getCountByUser(user)); - - assertNull(layout.getInputData()); - - project = projectDao.getById(project.getId()); - projectDao.delete(project); - - userDao.delete(user); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - private Model createModel() { - Model model = new ModelFullIndexed(null); - - Species alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2"); - model.addElement(alias); - alias = createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117"); - model.addElement(alias); - alias = createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119"); - model.addElement(alias); - alias = createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121"); - model.addElement(alias); - - alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422"); - Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419"); - Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152"); - alias3.addSpecies(alias); - alias3.addSpecies(alias2); - alias.setComplex(alias3); - alias2.setComplex(alias3); - - model.addElement(alias); - model.addElement(alias2); - model.addElement(alias3); - - Compartment cAlias = createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1"); - model.addElement(cAlias); - model.setWidth(2000); - model.setHeight(2000); - - Layer layer = new Layer(); - model.addLayer(layer); - - LayerRect lr = new LayerRect(); - lr.setColor(Color.YELLOW); - layer.addLayerRect(lr); - - Reaction reaction = new TransportReaction(); - reaction.addProduct(new Product(alias)); - reaction.addReactant(new Reactant(alias2)); - reaction.setIdReaction("re" + identifierCounter++); - model.addReaction(reaction); - - Protein protein = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "pr1"); - model.addElement(protein); - - ModificationResidue mr = new ModificationResidue(); - mr.setName("mr"); - protein.addModificationResidue(mr); - - protein.addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, "c")); - return model; - } - - private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) { - Compartment alias = new Compartment(aliasId); - alias.setX(x); - alias.setY(y); - alias.setWidth(width); - alias.setHeight(height); - return alias; - } - - private Protein createSpeciesAlias(double x, double y, double width, double height, String aliasId) { - GenericProtein alias = new GenericProtein("s" + identifierCounter++); - alias.setElementId(aliasId); - alias.setX(x); - alias.setY(y); - alias.setWidth(width); - alias.setHeight(height); - return alias; - } - - private Complex createComplexAlias(double x, double y, double width, double height, String aliasId) { - Complex alias = new Complex(aliasId); - alias.setX(x); - alias.setY(y); - alias.setWidth(width); - alias.setHeight(height); - return alias; - } - -} +package lcsb.mapviewer.persist.dao.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.awt.Color; +import java.nio.charset.StandardCharsets; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import lcsb.mapviewer.model.Project; +import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamRelationType; +import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.compartment.Compartment; +import lcsb.mapviewer.model.map.layout.Layout; +import lcsb.mapviewer.model.map.layout.graphics.Layer; +import lcsb.mapviewer.model.map.layout.graphics.LayerRect; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; +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.Complex; +import lcsb.mapviewer.model.map.species.GenericProtein; +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.model.map.species.Species; +import lcsb.mapviewer.model.map.species.field.Residue; +import lcsb.mapviewer.persist.PersistTestFunctions; + +public class LayoutDaoTest extends PersistTestFunctions { + + @Autowired + private LayoutDao layoutDao; + + final static Logger logger = Logger.getLogger(LayoutDaoTest.class); + + int identifierCounter = 0; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + /** + * After adding layouts to model. + * + * @throws Exception + */ + @Test + public void testLayoutsWithData() throws Exception { + try { + Model model = createModel(); + + Project project = new Project(); + project.addModel(model); + projectDao.add(project); + + modelDao.evict(model); + projectDao.evict(project); + + Layout layout = new Layout(); + layout.setDirectory("tmp"); + layout.setTitle("temporary name"); + + byte[] data = "test".getBytes(); + UploadedFileEntry fileEntry = new UploadedFileEntry(); + fileEntry.setFileContent(data); + + layout.setInputData(fileEntry); + model.addLayout(layout); + layoutDao.add(layout); + + layoutDao.evict(layout); + + layout = layoutDao.getById(layout.getId()); + + assertEquals("test", new String(layout.getInputData().getFileContent(), StandardCharsets.UTF_8)); + + project = projectDao.getById(project.getId()); + projectDao.delete(project); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + /** + * After adding layouts to model. + * + * @throws Exception + */ + @Test + public void testLayoutsWithoutData() throws Exception { + try { + Model model = createModel(); + String tempName = "temporary name"; + + createUser(); + + Project project = new Project(); + project.addModel(model); + projectDao.add(project); + + modelDao.evict(model); + projectDao.evict(project); + + assertEquals(0, layoutDao.getCountByUser(user)); + assertEquals(0, layoutDao.getLayoutsByModel(model).size()); + assertNull(layoutDao.getLayoutByName(model, tempName)); + + Layout layout = new Layout(); + layout.setDirectory("tmp"); + layout.setTitle(tempName); + layout.setCreator(user); + model.addLayout(layout); + layoutDao.add(layout); + + layoutDao.evict(layout); + + layout = layoutDao.getById(layout.getId()); + + assertEquals(1, layoutDao.getLayoutsByModel(model).size()); + assertNotNull(layoutDao.getLayoutByName(model, tempName)); + assertEquals(1, layoutDao.getCountByUser(user)); + + assertNull(layout.getInputData()); + + project = projectDao.getById(project.getId()); + projectDao.delete(project); + + userDao.delete(user); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private Model createModel() { + Model model = new ModelFullIndexed(null); + + Species alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2"); + model.addElement(alias); + alias = createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117"); + model.addElement(alias); + alias = createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119"); + model.addElement(alias); + alias = createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121"); + model.addElement(alias); + + alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422"); + Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419"); + Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152"); + alias3.addSpecies(alias); + alias3.addSpecies(alias2); + alias.setComplex(alias3); + alias2.setComplex(alias3); + + model.addElement(alias); + model.addElement(alias2); + model.addElement(alias3); + + Compartment cAlias = createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1"); + model.addElement(cAlias); + model.setWidth(2000); + model.setHeight(2000); + + Layer layer = new Layer(); + model.addLayer(layer); + + LayerRect lr = new LayerRect(); + lr.setColor(Color.YELLOW); + layer.addLayerRect(lr); + + Reaction reaction = new TransportReaction(); + reaction.addProduct(new Product(alias)); + reaction.addReactant(new Reactant(alias2)); + reaction.setIdReaction("re" + identifierCounter++); + model.addReaction(reaction); + + Protein protein = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "pr1"); + model.addElement(protein); + + Residue mr = new Residue(); + mr.setName("mr"); + protein.addModificationResidue(mr); + + protein.addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, "c")); + return model; + } + + private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) { + Compartment alias = new Compartment(aliasId); + alias.setX(x); + alias.setY(y); + alias.setWidth(width); + alias.setHeight(height); + return alias; + } + + private Protein createSpeciesAlias(double x, double y, double width, double height, String aliasId) { + GenericProtein alias = new GenericProtein("s" + identifierCounter++); + alias.setElementId(aliasId); + alias.setX(x); + alias.setY(y); + alias.setWidth(width); + alias.setHeight(height); + return alias; + } + + private Complex createComplexAlias(double x, double y, double width, double height, String aliasId) { + Complex alias = new Complex(aliasId); + alias.setX(x); + alias.setY(y); + alias.setWidth(width); + alias.setHeight(height); + return alias; + } + +} 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 15b56dadff..02bf55c42b 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 @@ -41,7 +41,7 @@ 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.Species; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.persist.PersistTestFunctions; public class ModelDaoTest extends PersistTestFunctions { @@ -86,6 +86,9 @@ public class ModelDaoTest extends PersistTestFunctions { assertEquals(model.getLayers().size(), model2.getLayers().size()); assertEquals(model.getReactions().size(), model2.getReactions().size()); + ModelComparator comparator = new ModelComparator(); + assertEquals(0, comparator.compare(model, new ModelFullIndexed(model2))); + modelDao.delete(model2); model2 = modelDao.getById(model.getId()); assertNull(model2); @@ -424,7 +427,7 @@ public class ModelDaoTest extends PersistTestFunctions { alias = createSpecies(264.8333333333335, 517.75, 86.0, 46.0, "pr1"); model.addElement(alias); - ModificationResidue mr = new ModificationResidue(); + Residue mr = new Residue(); mr.setName("mr"); mr.setPosition(new Point2D.Double(10, 20)); alias.addModificationResidue(mr); diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java index 290777b975..0f264ff692 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java @@ -25,8 +25,8 @@ import lcsb.mapviewer.model.map.species.Rna; import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion; import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationState; +import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.model.map.species.field.RnaRegion; import lcsb.mapviewer.persist.PersistTestFunctions; @@ -106,7 +106,7 @@ public class AliasDaoTest2 extends PersistTestFunctions { try { Protein protein = new GenericProtein(testIdAlias); - ModificationResidue mr = new ModificationResidue(); + Residue mr = new Residue(); mr.setPosition(new Point2D.Double(10, 20)); mr.setName("name"); mr.setState(ModificationState.GLYCOSYLATED); diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java index a5e898655c..042a0eb395 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java @@ -28,9 +28,8 @@ import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.model.map.species.Rna; import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion; -import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationState; +import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.model.map.species.field.RnaRegion; import lcsb.mapviewer.services.interfaces.IModelService; @@ -116,7 +115,7 @@ public class ElementRestImplTest extends RestTestFunctions { try { String state = "asd"; GenericProtein protein = new GenericProtein("s1"); - ModificationResidue mr = new ModificationResidue(); + Residue mr = new Residue(); mr.setState(ModificationState.ACETYLATED); mr.setName("S250"); protein.addModificationResidue(mr); -- GitLab