diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java index 1213df96ac1b3cb495499cfb166636eb1a3ee052..766abbbdefe37d5c1744182d3ee59f13bbcde3c1 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java @@ -1,5 +1,7 @@ package lcsb.mapviewer.converter.model.celldesigner.species; +import java.awt.geom.Point2D; + import org.apache.log4j.Logger; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -23,151 +25,157 @@ import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType; */ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesignerAntisenseRna, AntisenseRna> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(AntisenseRnaXmlParser.class.getName()); + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(AntisenseRnaXmlParser.class.getName()); + + /** + * List of {@link CellDesignerElement celldesigner elements} obtained during + * parsing process. + */ + private CellDesignerElementCollection elements; - /** - * List of {@link CellDesignerElement celldesigner elements} obtained during - * parsing process. - */ - private CellDesignerElementCollection elements; + /** + * Default constructor. + * + * @param elements + * list of {@link CellDesignerElement celldesigner elements} obtained + * during parsing process + */ + public AntisenseRnaXmlParser(CellDesignerElementCollection elements) { + this.elements = elements; + } - /** - * Default constructor. - * - * @param elements - * list of {@link CellDesignerElement celldesigner elements} obtained - * during parsing process - */ - public AntisenseRnaXmlParser(CellDesignerElementCollection elements) { - this.elements = elements; - } + @Override + public Pair<String, CellDesignerAntisenseRna> parseXmlElement(Node antisenseRnaNode) + throws InvalidXmlSchemaException { + CellDesignerAntisenseRna antisenseRna = new CellDesignerAntisenseRna(); + String identifier = getNodeAttr("id", antisenseRnaNode); + antisenseRna.setName(decodeName(getNodeAttr("name", antisenseRnaNode))); + NodeList list = antisenseRnaNode.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equals("celldesigner:notes")) { + antisenseRna.setNotes(getRap().getNotes(node)); + } else if (node.getNodeName().equals("celldesigner:listOfRegions")) { + NodeList residueList = node.getChildNodes(); + for (int j = 0; j < residueList.getLength(); j++) { + Node residueNode = residueList.item(j); + if (residueNode.getNodeType() == Node.ELEMENT_NODE) { + if (residueNode.getNodeName().equalsIgnoreCase("celldesigner:region")) { + antisenseRna.addRegion(getAntisenseRnaRegion(residueNode)); + } else { + throw new InvalidXmlSchemaException( + "Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName()); + } + } + } + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:antisenseRna " + node.getNodeName()); + } + } + } + Pair<String, CellDesignerAntisenseRna> result = new Pair<String, CellDesignerAntisenseRna>(identifier, + antisenseRna); + return result; + } - @Override - public Pair<String, CellDesignerAntisenseRna> parseXmlElement(Node antisenseRnaNode) throws InvalidXmlSchemaException { - CellDesignerAntisenseRna antisenseRna = new CellDesignerAntisenseRna(); - String identifier = getNodeAttr("id", antisenseRnaNode); - antisenseRna.setName(decodeName(getNodeAttr("name", antisenseRnaNode))); - NodeList list = antisenseRnaNode.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equals("celldesigner:notes")) { - antisenseRna.setNotes(getRap().getNotes(node)); - } else if (node.getNodeName().equals("celldesigner:listOfRegions")) { - NodeList residueList = node.getChildNodes(); - for (int j = 0; j < residueList.getLength(); j++) { - Node residueNode = residueList.item(j); - if (residueNode.getNodeType() == Node.ELEMENT_NODE) { - if (residueNode.getNodeName().equalsIgnoreCase("celldesigner:region")) { - antisenseRna.addRegion(getAntisenseRnaRegion(residueNode)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName()); - } - } - } - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:antisenseRna " + node.getNodeName()); - } - } - } - Pair<String, CellDesignerAntisenseRna> result = new Pair<String, CellDesignerAntisenseRna>(identifier, antisenseRna); - return result; - } + @Override + public String toXml(AntisenseRna antisenseRna) { + String attributes = ""; + String result = ""; + attributes += " id=\"ar_" + elements.getElementId(antisenseRna) + "\""; + if (!antisenseRna.getName().equals("")) { + attributes += " name=\"" + escapeXml(encodeName(antisenseRna.getName())) + "\""; + } + result += "<celldesigner:AntisenseRNA" + attributes + ">"; + result += "<celldesigner:notes>"; + result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>"; - @Override - public String toXml(AntisenseRna antisenseRna) { - String attributes = ""; - String result = ""; - attributes += " id=\"ar_" + elements.getElementId(antisenseRna) + "\""; - if (!antisenseRna.getName().equals("")) { - attributes += " name=\"" + escapeXml(encodeName(antisenseRna.getName())) + "\""; - } - result += "<celldesigner:AntisenseRNA" + attributes + ">"; - result += "<celldesigner:notes>"; - result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>"; + RestAnnotationParser rap = new RestAnnotationParser(); + result += rap.createAnnotationString(antisenseRna); + result += antisenseRna.getNotes(); + result += "</body></html>"; + result += "</celldesigner:notes>"; + if (antisenseRna.getRegions().size() > 0) { + result += "<celldesigner:listOfRegions>"; + for (AntisenseRnaRegion region : antisenseRna.getRegions()) { + result += toXml(region); + } + result += "</celldesigner:listOfRegions>"; + } + result += "</celldesigner:AntisenseRNA>"; + return result; + } - RestAnnotationParser rap = new RestAnnotationParser(); - result += rap.createAnnotationString(antisenseRna); - result += antisenseRna.getNotes(); - result += "</body></html>"; - result += "</celldesigner:notes>"; - if (antisenseRna.getRegions().size() > 0) { - result += "<celldesigner:listOfRegions>"; - for (AntisenseRnaRegion region : antisenseRna.getRegions()) { - result += toXml(region); - } - result += "</celldesigner:listOfRegions>"; - } - result += "</celldesigner:AntisenseRNA>"; - return result; - } + /** + * Transforms AntisenseRnaRegion into CellDEsigner xml representation. + * + * @param region + * object to be transformed + * @return xml representation of the given region + */ + private String toXml(AntisenseRnaRegion region) { + String result = ""; + String attributes = ""; + if (!region.getIdAntisenseRnaRegion().equals("")) { + attributes += " id=\"" + region.getIdAntisenseRnaRegion() + "\""; + } + if (!region.getName().equals("")) { + attributes += " name=\"" + escapeXml(region.getName()) + "\""; + } + if (region.getSize() != 0) { + attributes += " size=\"" + region.getSize() + "\""; + } + if (region.getPosition() != null) { + double pos = (region.getPosition().getX() - region.getSpecies().getWidth()) + / (region.getSpecies().getWidth() * 3 / 4); - /** - * Transforms AntisenseRnaRegion into CellDEsigner xml representation. - * - * @param region - * object to be transformed - * @return xml representation of the given region - */ - private String toXml(AntisenseRnaRegion region) { - String result = ""; - String attributes = ""; - if (!region.getIdAntisenseRnaRegion().equals("")) { - attributes += " id=\"" + region.getIdAntisenseRnaRegion() + "\""; - } - if (!region.getName().equals("")) { - attributes += " name=\"" + escapeXml(region.getName()) + "\""; - } - if (region.getSize() != 0) { - attributes += " size=\"" + region.getSize() + "\""; - } - if (region.getPos() != 0) { - attributes += " pos=\"" + region.getPos() + "\""; - } - if (region.getType() != null) { - attributes += " type=\"" + region.getType().getName() + "\""; - } - result += "<celldesigner:region " + attributes + ">"; - result += "</celldesigner:region>"; + attributes += " pos=\"" + pos + "\""; + } + if (region.getType() != null) { + attributes += " type=\"" + region.getType().getName() + "\""; + } + result += "<celldesigner:region " + attributes + ">"; + result += "</celldesigner:region>"; - return result; - } + return result; + } - /** - * Method that parse xml node into AntisenseRnaRegion element. - * - * @param regionNode - * xml node to parse - * @return AntisenseRnaRegion object from xml node - * @throws InvalidXmlSchemaException - * thrown when input xml node doesn't follow defined schema - */ - private CellDesignerAntisenseRnaRegion getAntisenseRnaRegion(Node regionNode) throws InvalidXmlSchemaException { - CellDesignerAntisenseRnaRegion residue = new CellDesignerAntisenseRnaRegion(); - residue.setIdAntisenseRnaRegion(getNodeAttr("id", regionNode)); - residue.setName(getNodeAttr("name", regionNode)); - residue.setSize(getNodeAttr("size", regionNode)); - residue.setPos(getNodeAttr("pos", regionNode)); - String typeString = getNodeAttr("type", regionNode); - if (typeString != null) { - AntisenseRnaRegionType type = AntisenseRnaRegionType.getTypeByString(typeString); - if (type == null) { - throw new InvalidXmlSchemaException("Unknown antisense rna region type: " + typeString); - } - residue.setType(type); - } - NodeList list = regionNode.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:region " + node.getNodeName()); - } - } - return residue; - } + /** + * Method that parse xml node into AntisenseRnaRegion element. + * + * @param regionNode + * xml node to parse + * @return AntisenseRnaRegion object from xml node + * @throws InvalidXmlSchemaException + * thrown when input xml node doesn't follow defined schema + */ + private CellDesignerAntisenseRnaRegion getAntisenseRnaRegion(Node regionNode) throws InvalidXmlSchemaException { + CellDesignerAntisenseRnaRegion residue = new CellDesignerAntisenseRnaRegion(); + residue.setIdAntisenseRnaRegion(getNodeAttr("id", regionNode)); + residue.setName(getNodeAttr("name", regionNode)); + residue.setSize(getNodeAttr("size", regionNode)); + residue.setPos(getNodeAttr("pos", regionNode)); + String typeString = getNodeAttr("type", regionNode); + if (typeString != null) { + AntisenseRnaRegionType type = AntisenseRnaRegionType.getTypeByString(typeString); + if (type == null) { + throw new InvalidXmlSchemaException("Unknown antisense rna region type: " + typeString); + } + residue.setType(type); + } + NodeList list = regionNode.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:region " + node.getNodeName()); + } + } + return residue; + } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerAntisenseRna.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerAntisenseRna.java index e3456b1c883be2e35b467ce847c334b709a798fa..c69ba1a709b52ea2cfcb1ff8c4fae717c5075713 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerAntisenseRna.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerAntisenseRna.java @@ -1,150 +1,149 @@ -package lcsb.mapviewer.converter.model.celldesigner.structure; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion; -import lcsb.mapviewer.model.map.species.AntisenseRna; - -/** - * Class representing CellDesigner {@link AntisenseRna}. - * - * @author Piotr Gawron - * - */ -public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna> { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(CellDesignerAntisenseRna.class); - - /** - * List of antisense rna regions (some rna sequences) in this object. - */ - private List<CellDesignerAntisenseRnaRegion> regions = new ArrayList<CellDesignerAntisenseRnaRegion>(); - - /** - * Constructor that copies the data from species given in the argument. - * - * @param species - * parent species from which we want to copy data - */ - public CellDesignerAntisenseRna(CellDesignerSpecies<?> species) { - super(species); - if (species instanceof CellDesignerAntisenseRna) { - CellDesignerAntisenseRna asRna = (CellDesignerAntisenseRna) species; - for (CellDesignerAntisenseRnaRegion region : asRna.getRegions()) { - addRegion(new CellDesignerAntisenseRnaRegion(region)); - } - } - } - - /** - * Default constructor. - */ - public CellDesignerAntisenseRna() { - super(); - } - - @Override - public CellDesignerAntisenseRna copy() { - if (this.getClass() == CellDesignerAntisenseRna.class) { - return new CellDesignerAntisenseRna(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - - /** - * Addd antisense rna region (part of rna sequence that has some meaning) to - * the object. If the region with given id exists then the data of this region - * is copied to the one that is already in the - * {@link CellDesignerAntisenseRna}. - * - * - * @param region - * region to add - */ - public void addRegion(CellDesignerAntisenseRnaRegion region) { - for (CellDesignerAntisenseRnaRegion region2 : regions) { - if (region2.getIdAntisenseRnaRegion().equals(region.getIdAntisenseRnaRegion())) { - region2.update(region); - return; - } - } - - regions.add(region); - region.setSpecies(this); - } - - @Override - public void update(CellDesignerSpecies<?> sp) { - super.update(sp); - if (sp instanceof CellDesignerAntisenseRna) { - CellDesignerAntisenseRna rna = (CellDesignerAntisenseRna) sp; - for (CellDesignerAntisenseRnaRegion mr : getRegions()) { - mr.setState(null); - } - - for (CellDesignerAntisenseRnaRegion region : rna.getRegions()) { - updateRegion(region); - } - } - } - - /** - * Method update antisense rna region from the object in params (if the object - * with the same id already exists). If there is no object with given id then - * new object is added to antisense rna. - * - * @param param - * - object with new data from where update should be performed - */ - private void updateRegion(CellDesignerAntisenseRnaRegion param) { - for (CellDesignerAntisenseRnaRegion region : regions) { - if (region.getIdAntisenseRnaRegion().equals(param.getIdAntisenseRnaRegion())) { - region.update(param); - return; - } - } - regions.add(param); - } - - /** - * @return the regions - * @see #regions - */ - public List<CellDesignerAntisenseRnaRegion> getRegions() { - return regions; - } - - /** - * @param regions - * the regions to set - * @see #regions - */ - public void setRegions(List<CellDesignerAntisenseRnaRegion> regions) { - this.regions = regions; - } - - @Override - public AntisenseRna createModelElement(String aliasId) { - AntisenseRna result = new AntisenseRna(aliasId); - super.setModelObjectFields(result); - for (CellDesignerAntisenseRnaRegion region : regions) { - result.addRegion(region.createAntisenseRegionAlias()); - } - return result; - } - -} +package lcsb.mapviewer.converter.model.celldesigner.structure; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion; +import lcsb.mapviewer.model.map.species.AntisenseRna; + +/** + * Class representing CellDesigner {@link AntisenseRna}. + * + * @author Piotr Gawron + * + */ +public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna> { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(CellDesignerAntisenseRna.class); + + /** + * List of antisense rna regions (some rna sequences) in this object. + */ + private List<CellDesignerAntisenseRnaRegion> regions = new ArrayList<CellDesignerAntisenseRnaRegion>(); + + /** + * Constructor that copies the data from species given in the argument. + * + * @param species + * parent species from which we want to copy data + */ + public CellDesignerAntisenseRna(CellDesignerSpecies<?> species) { + super(species); + if (species instanceof CellDesignerAntisenseRna) { + CellDesignerAntisenseRna asRna = (CellDesignerAntisenseRna) species; + for (CellDesignerAntisenseRnaRegion region : asRna.getRegions()) { + addRegion(new CellDesignerAntisenseRnaRegion(region)); + } + } + } + + /** + * Default constructor. + */ + public CellDesignerAntisenseRna() { + super(); + } + + @Override + public CellDesignerAntisenseRna copy() { + if (this.getClass() == CellDesignerAntisenseRna.class) { + return new CellDesignerAntisenseRna(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + + /** + * Addd antisense rna region (part of rna sequence that has some meaning) to the + * object. If the region with given id exists then the data of this region is + * copied to the one that is already in the {@link CellDesignerAntisenseRna}. + * + * + * @param region + * region to add + */ + public void addRegion(CellDesignerAntisenseRnaRegion region) { + for (CellDesignerAntisenseRnaRegion region2 : regions) { + if (region2.getIdAntisenseRnaRegion().equals(region.getIdAntisenseRnaRegion())) { + region2.update(region); + return; + } + } + + regions.add(region); + region.setSpecies(this); + } + + @Override + public void update(CellDesignerSpecies<?> sp) { + super.update(sp); + if (sp instanceof CellDesignerAntisenseRna) { + CellDesignerAntisenseRna rna = (CellDesignerAntisenseRna) sp; + for (CellDesignerAntisenseRnaRegion mr : getRegions()) { + mr.setState(null); + } + + for (CellDesignerAntisenseRnaRegion region : rna.getRegions()) { + updateRegion(region); + } + } + } + + /** + * Method update antisense rna region from the object in params (if the object + * with the same id already exists). If there is no object with given id then + * new object is added to antisense rna. + * + * @param param + * - object with new data from where update should be performed + */ + private void updateRegion(CellDesignerAntisenseRnaRegion param) { + for (CellDesignerAntisenseRnaRegion region : regions) { + if (region.getIdAntisenseRnaRegion().equals(param.getIdAntisenseRnaRegion())) { + region.update(param); + return; + } + } + regions.add(param); + } + + /** + * @return the regions + * @see #regions + */ + public List<CellDesignerAntisenseRnaRegion> getRegions() { + return regions; + } + + /** + * @param regions + * the regions to set + * @see #regions + */ + public void setRegions(List<CellDesignerAntisenseRnaRegion> regions) { + this.regions = regions; + } + + @Override + public AntisenseRna createModelElement(String aliasId) { + AntisenseRna result = new AntisenseRna(aliasId); + super.setModelObjectFields(result); + for (CellDesignerAntisenseRnaRegion region : regions) { + result.addRegion(region.createAntisenseRegionAlias(result)); + } + return result; + } + +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerAntisenseRnaRegion.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerAntisenseRnaRegion.java index 36decddc98a49f81ef86a92f4431a0349825d4c2..ec607f2dfe74a03e05ba368aca803372a4b84339 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerAntisenseRnaRegion.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/fields/CellDesignerAntisenseRnaRegion.java @@ -1,5 +1,6 @@ package lcsb.mapviewer.converter.model.celldesigner.structure.fields; +import java.awt.geom.Point2D; import java.io.Serializable; import org.apache.log4j.Logger; @@ -7,6 +8,7 @@ import org.apache.log4j.Logger; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerAntisenseRna; +import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion; import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType; import lcsb.mapviewer.model.map.species.field.ModificationState; @@ -22,313 +24,316 @@ import lcsb.mapviewer.model.map.species.field.ModificationState; */ public class CellDesignerAntisenseRnaRegion implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default size of the object (in graphical representation). - */ - private static final double DEFAULT_SIZE = 0.1; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(CellDesignerAntisenseRnaRegion.class.getName()); - - /** - * Unique identifier in the database. - */ - private int id; - - /** - * String identifier of the element. Unique in the model. - */ - private String idAntisenseRnaRegion = ""; - - /** - * Name of the region. - */ - private String name = ""; - - /** - * Defines a state of the region (for instance ubiquitinated etc). - * - * @see ModificationState - */ - private ModificationState state = null; - - /** - * Type of the region in the rna. There are three possible values: - * <ul> - * <li>Coding region,</li> - * <li>Protein binding domain,</li> - * <li>Modification site.</li> - * </ul> - */ - private AntisenseRnaRegionType type; - - /** - * Size of the region in the graphic representation. - */ - private double size = DEFAULT_SIZE; - - /** - * Position on the species in graphic representation. - */ - private Double pos; - - /** - * Defines a species where the region belongs to. - */ - private CellDesignerAntisenseRna species; - - /** - * Default constructor. - */ - public CellDesignerAntisenseRnaRegion() { - - } - - /** - * Constructor that initialize object with the data from the parameter. - * - * @param original - * object from which we initialize data - */ - public CellDesignerAntisenseRnaRegion(CellDesignerAntisenseRnaRegion original) { - this.idAntisenseRnaRegion = original.idAntisenseRnaRegion; - this.name = original.name; - this.size = original.size; - this.pos = original.pos; - this.type = original.type; - } - - /** - * Creates a copy of current object. - * - * @return copy of the object - */ - public CellDesignerAntisenseRnaRegion copy() { - if (this.getClass() == CellDesignerAntisenseRnaRegion.class) { - return new CellDesignerAntisenseRnaRegion(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - - } - - /** - * Sets size from the string. - * - * @param text - * size to parse and set - * @see #size - */ - public void setSize(String text) { - try { - size = Double.parseDouble(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid angle: " + text, e); - } - } - - /** - * Sets position from the string. - * - * @param text - * position to parse and set - * @see #pos - */ - public void setPos(String text) { - try { - pos = Double.parseDouble(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid pos: " + text, e); - } - } - - /** - * Update data in this object from parameter (only if values in parameter - * object are valid). - * - * @param mr - * object from which we are updating data - */ - public void update(CellDesignerAntisenseRnaRegion mr) { - if (this.idAntisenseRnaRegion != null && !this.idAntisenseRnaRegion.equals("") && !this.idAntisenseRnaRegion.equals(mr.getIdAntisenseRnaRegion())) { - throw new InvalidArgumentException("Cannot update from mr with different id"); - } - this.size = mr.getSize(); - if (mr.getState() != null) { - this.state = mr.getState(); - } - if (mr.getName() != null) { - this.name = mr.getName(); - } - if (mr.getPos() != null) { - this.setPos(mr.getPos()); - } - - } - - @Override - public String toString() { - String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getType() + "," + getPos() + "," + getSize() + ","; - return result; - } - - /** - * @return the idAntisenseRnaRegion - * @see #idAntisenseRnaRegion - */ - public String getIdAntisenseRnaRegion() { - return idAntisenseRnaRegion; - } - - /** - * @param idAntisenseRnaRegion - * the id to set - * @see #idAntisenseRnaRegion - */ - public void setIdAntisenseRnaRegion(String idAntisenseRnaRegion) { - this.idAntisenseRnaRegion = idAntisenseRnaRegion; - } - - /** - * @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 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 type - * @see #type - */ - public AntisenseRnaRegionType getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(AntisenseRnaRegionType type) { - this.type = type; - } - - /** - * @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 pos - * @see #pos - */ - public Double getPos() { - return pos; - } - - /** - * @param pos - * the pos to set - * @see #pos - */ - public void setPos(Double pos) { - this.pos = pos; - } - - /** - * @return the species - * @see #species - */ - public CellDesignerAntisenseRna getSpecies() { - return species; - } - - /** - * @param species - * the species to set - * @see #species - */ - public void setSpecies(CellDesignerAntisenseRna species) { - this.species = species; - } - - /** - * @return the id - * @see #id - */ - public int getId() { - return id; - } - - /** - * @param id - * the id to set - * @see #id - */ - public void setId(int id) { - this.id = id; - } - - /** - * Creates model representation of {@link AntisenseRnaRegion}. - * - * @return {@link AntisenseRnaRegion} representing this object in a model - */ - public AntisenseRnaRegion createAntisenseRegionAlias() { - AntisenseRnaRegion result = new AntisenseRnaRegion(); - result.setIdAntisenseRnaRegion(idAntisenseRnaRegion); - result.setName(name); - result.setSize(size); - result.setPos(pos); - result.setType(type); - return result; - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default size of the object (in graphical representation). + */ + private static final double DEFAULT_SIZE = 0.1; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(CellDesignerAntisenseRnaRegion.class.getName()); + + /** + * Unique identifier in the database. + */ + private int id; + + /** + * String identifier of the element. Unique in the model. + */ + private String idAntisenseRnaRegion = ""; + + /** + * Name of the region. + */ + private String name = ""; + + /** + * Defines a state of the region (for instance ubiquitinated etc). + * + * @see ModificationState + */ + private ModificationState state = null; + + /** + * Type of the region in the rna. There are three possible values: + * <ul> + * <li>Coding region,</li> + * <li>Protein binding domain,</li> + * <li>Modification site.</li> + * </ul> + */ + private AntisenseRnaRegionType type; + + /** + * Size of the region in the graphic representation. + */ + private double size = DEFAULT_SIZE; + + /** + * Position on the species in graphic representation. + */ + private Double pos; + + /** + * Defines a species where the region belongs to. + */ + private CellDesignerAntisenseRna species; + + /** + * Default constructor. + */ + public CellDesignerAntisenseRnaRegion() { + + } + + /** + * Constructor that initialize object with the data from the parameter. + * + * @param original + * object from which we initialize data + */ + public CellDesignerAntisenseRnaRegion(CellDesignerAntisenseRnaRegion original) { + this.idAntisenseRnaRegion = original.idAntisenseRnaRegion; + this.name = original.name; + this.size = original.size; + this.pos = original.pos; + this.type = original.type; + } + + /** + * Creates a copy of current object. + * + * @return copy of the object + */ + public CellDesignerAntisenseRnaRegion copy() { + if (this.getClass() == CellDesignerAntisenseRnaRegion.class) { + return new CellDesignerAntisenseRnaRegion(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + + } + + /** + * Sets size from the string. + * + * @param text + * size to parse and set + * @see #size + */ + public void setSize(String text) { + try { + size = Double.parseDouble(text); + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid angle: " + text, e); + } + } + + /** + * Sets position from the string. + * + * @param text + * position to parse and set + * @see #pos + */ + public void setPos(String text) { + try { + pos = Double.parseDouble(text); + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid pos: " + text, e); + } + } + + /** + * Update data in this object from parameter (only if values in parameter object + * are valid). + * + * @param mr + * object from which we are updating data + */ + public void update(CellDesignerAntisenseRnaRegion mr) { + if (this.idAntisenseRnaRegion != null && !this.idAntisenseRnaRegion.equals("") + && !this.idAntisenseRnaRegion.equals(mr.getIdAntisenseRnaRegion())) { + throw new InvalidArgumentException("Cannot update from mr with different id"); + } + this.size = mr.getSize(); + if (mr.getState() != null) { + this.state = mr.getState(); + } + if (mr.getName() != null) { + this.name = mr.getName(); + } + if (mr.getPos() != null) { + this.setPos(mr.getPos()); + } + + } + + @Override + public String toString() { + String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getType() + "," + getPos() + "," + getSize() + + ","; + return result; + } + + /** + * @return the idAntisenseRnaRegion + * @see #idAntisenseRnaRegion + */ + public String getIdAntisenseRnaRegion() { + return idAntisenseRnaRegion; + } + + /** + * @param idAntisenseRnaRegion + * the id to set + * @see #idAntisenseRnaRegion + */ + public void setIdAntisenseRnaRegion(String idAntisenseRnaRegion) { + this.idAntisenseRnaRegion = idAntisenseRnaRegion; + } + + /** + * @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 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 type + * @see #type + */ + public AntisenseRnaRegionType getType() { + return type; + } + + /** + * @param type + * the type to set + * @see #type + */ + public void setType(AntisenseRnaRegionType type) { + this.type = type; + } + + /** + * @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 pos + * @see #pos + */ + public Double getPos() { + return pos; + } + + /** + * @param pos + * the pos to set + * @see #pos + */ + public void setPos(Double pos) { + this.pos = pos; + } + + /** + * @return the species + * @see #species + */ + public CellDesignerAntisenseRna getSpecies() { + return species; + } + + /** + * @param species + * the species to set + * @see #species + */ + public void setSpecies(CellDesignerAntisenseRna species) { + this.species = species; + } + + /** + * @return the id + * @see #id + */ + public int getId() { + return id; + } + + /** + * @param id + * the id to set + * @see #id + */ + public void setId(int id) { + this.id = id; + } + + /** + * Creates model representation of {@link AntisenseRnaRegion}. + * + * @return {@link AntisenseRnaRegion} representing this object in a model + */ + public AntisenseRnaRegion createAntisenseRegionAlias(Element element) { + AntisenseRnaRegion result = new AntisenseRnaRegion(); + result.setIdAntisenseRnaRegion(idAntisenseRnaRegion); + result.setName(name); + result.setSize(size); + + result.setPosition(new Point2D.Double(element.getX() + element.getWidth() * 3.0 / 4.0 * pos, element.getY())); + result.setType(type); + return result; + } } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java index f8b7777cdc7a41ecf1397b49f59c5ff9c86d61e8..f2ee56366f204beddcebf3bd30f791573ac36442 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java @@ -1,151 +1,144 @@ -package lcsb.mapviewer.converter.graphics.bioEntity.element.species; - -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Stroke; -import java.awt.geom.AffineTransform; -import java.awt.geom.Ellipse2D; -import java.awt.geom.GeneralPath; -import java.awt.geom.Path2D; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.commands.ColorExtractor; -import lcsb.mapviewer.converter.graphics.ConverterParams; -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.species.AntisenseRna; -import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion; -import lcsb.mapviewer.model.map.species.field.ModificationState; - -/** - * This class defines methods used for drawing {@link AntisenseRna} on the - * {@link Graphics2D} object. - * - * @author Piotr Gawron - * - */ - -public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(AntisenseRnaConverter.class.getName()); - - /** - * Default constructor. - * - * @param colorExtractor - * Object that helps to convert {@link ColorSchema} values into - * colors when drawing {@link Species} - */ - public AntisenseRnaConverter(ColorExtractor colorExtractor) { - super(colorExtractor); - } - - @Override - public void draw(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) { - GeneralPath path = getAntisenseRnaPath(antisenseRna); - Color c = graphics.getColor(); - graphics.setColor(antisenseRna.getColor()); - graphics.fill(path); - graphics.setColor(c); - Stroke stroke = graphics.getStroke(); - graphics.setStroke(getBorderLine(antisenseRna)); - graphics.draw(path); - graphics.setStroke(stroke); - - for (AntisenseRnaRegion mr : antisenseRna.getRegions()) { - drawRegion(antisenseRna, mr, graphics, false, false); - } - - drawText(antisenseRna, graphics, params); - } - - /** - * Returns {@link AntisenseRna} border as a {@link GeneralPath} object. - * - * @param antisenseRna - * {@link AntisenseRna} for which we want to get border - * @return border of the {@link AntisenseRna} - */ - private GeneralPath getAntisenseRnaPath(final AntisenseRna antisenseRna) { - // CHECKSTYLE:OFF - GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD, 4); - path.moveTo(antisenseRna.getX(), antisenseRna.getY()); - path.lineTo(antisenseRna.getX() + antisenseRna.getWidth() * 3 / 4, antisenseRna.getY()); - path.lineTo(antisenseRna.getX() + antisenseRna.getWidth(), antisenseRna.getY() + antisenseRna.getHeight()); - path.lineTo(antisenseRna.getX() + antisenseRna.getWidth() / 4, antisenseRna.getY() + antisenseRna.getHeight()); - // CHECKSTYLE:ON - path.closePath(); - return path; - } - - @Override - public PathIterator getBoundPathIterator(final AntisenseRna alias) { - return getAntisenseRnaPath(alias).getPathIterator(new AffineTransform()); - } - - /** - * This method draws antisense rna region for given alias. - * - * @param antisenseRna - * {@link AntisenseRna} on which region should be drawn - * @param region - * {@link AntisenseRnaRegion} to be drawn - * @param graphics - * {@link Graphics2D} where we draw region - * @param drawEmptyRegion - * flag determining if we shoudl draw empty regions - * @param drawDescription - * flag determining if we want to draw description as well - */ - private void drawRegion(final AntisenseRna antisenseRna, final AntisenseRnaRegion region, final Graphics2D graphics, final boolean drawEmptyRegion, - final boolean drawDescription) { - if ((!drawEmptyRegion) && (region.getState() == null)) { - return; - } - double diameter = DEFAULT_MODIFICATION_DIAMETER; - - double x = antisenseRna.getX(); - double y = antisenseRna.getY(); - - double width = antisenseRna.getWidth(); - - // CHECKSTYLE:OFF - // we draw modifier on the upper border of antisense rna (which is only in - // 3/4 of the width of alias) - Point2D p = new Point2D.Double(x + width * 3.0 / 4.0 * region.getPos(), y - diameter); - // CHECKSTYLE:ON - - Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter); - Color c = graphics.getColor(); - graphics.setColor(Color.WHITE); - graphics.fill(ellipse); - graphics.setColor(c); - graphics.draw(ellipse); - graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y); - - String text = region.getName(); - if (!text.equals("") && drawDescription) { - double textWidth = graphics.getFontMetrics().stringWidth(text); - Point2D p2 = new Point2D.Double(p.getX() - textWidth / 2, p.getY() - DEFAULT_SPECIES_MODIFIER_FONT_SIZE); - graphics.drawString(text, (int) p2.getX(), (int) p2.getY()); - } - ModificationState state = region.getState(); - if (state != null) { - String str = state.getAbbreviation(); - Font tmpFont = graphics.getFont(); - graphics.setFont(getStructuralFont()); - double textX = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2; - double textY = p.getY() + graphics.getFontMetrics().getAscent() / 2; - graphics.drawString(str, (int) textX, (int) textY); - graphics.setFont(tmpFont); - } - - } -} +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.commands.ColorExtractor; +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.species.AntisenseRna; +import lcsb.mapviewer.model.map.species.Species; +import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion; +import lcsb.mapviewer.model.map.species.field.ModificationState; + +/** + * This class defines methods used for drawing {@link AntisenseRna} on the + * {@link Graphics2D} object. + * + * @author Piotr Gawron + * + */ + +public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(AntisenseRnaConverter.class.getName()); + + /** + * Default constructor. + * + * @param colorExtractor + * Object that helps to convert {@link ColorSchema} values into colors + * when drawing {@link Species} + */ + public AntisenseRnaConverter(ColorExtractor colorExtractor) { + super(colorExtractor); + } + + @Override + public void draw(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) { + GeneralPath path = getAntisenseRnaPath(antisenseRna); + Color c = graphics.getColor(); + graphics.setColor(antisenseRna.getColor()); + graphics.fill(path); + graphics.setColor(c); + Stroke stroke = graphics.getStroke(); + graphics.setStroke(getBorderLine(antisenseRna)); + graphics.draw(path); + graphics.setStroke(stroke); + + for (AntisenseRnaRegion mr : antisenseRna.getRegions()) { + drawRegion(antisenseRna, mr, graphics, false, false); + } + + drawText(antisenseRna, graphics, params); + } + + /** + * Returns {@link AntisenseRna} border as a {@link GeneralPath} object. + * + * @param antisenseRna + * {@link AntisenseRna} for which we want to get border + * @return border of the {@link AntisenseRna} + */ + private GeneralPath getAntisenseRnaPath(final AntisenseRna antisenseRna) { + // CHECKSTYLE:OFF + GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD, 4); + path.moveTo(antisenseRna.getX(), antisenseRna.getY()); + path.lineTo(antisenseRna.getX() + antisenseRna.getWidth() * 3 / 4, antisenseRna.getY()); + path.lineTo(antisenseRna.getX() + antisenseRna.getWidth(), antisenseRna.getY() + antisenseRna.getHeight()); + path.lineTo(antisenseRna.getX() + antisenseRna.getWidth() / 4, antisenseRna.getY() + antisenseRna.getHeight()); + // CHECKSTYLE:ON + path.closePath(); + return path; + } + + @Override + public PathIterator getBoundPathIterator(final AntisenseRna alias) { + return getAntisenseRnaPath(alias).getPathIterator(new AffineTransform()); + } + + /** + * This method draws antisense rna region for given alias. + * + * @param antisenseRna + * {@link AntisenseRna} on which region should be drawn + * @param region + * {@link AntisenseRnaRegion} to be drawn + * @param graphics + * {@link Graphics2D} where we draw region + * @param drawEmptyRegion + * flag determining if we should draw empty regions + * @param drawDescription + * flag determining if we want to draw description as well + */ + private void drawRegion(final AntisenseRna antisenseRna, final AntisenseRnaRegion region, final Graphics2D graphics, + final boolean drawEmptyRegion, final boolean drawDescription) { + if ((!drawEmptyRegion) && (region.getState() == null)) { + return; + } + double diameter = DEFAULT_MODIFICATION_DIAMETER; + + double y = antisenseRna.getY(); + + Point2D p = new Point2D.Double(region.getPosition().getX(), region.getPosition().getY() - diameter); + + Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter); + Color c = graphics.getColor(); + graphics.setColor(Color.WHITE); + graphics.fill(ellipse); + graphics.setColor(c); + graphics.draw(ellipse); + graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y); + + String text = region.getName(); + if (!text.equals("") && drawDescription) { + double textWidth = graphics.getFontMetrics().stringWidth(text); + Point2D p2 = new Point2D.Double(p.getX() - textWidth / 2, p.getY() - DEFAULT_SPECIES_MODIFIER_FONT_SIZE); + graphics.drawString(text, (int) p2.getX(), (int) p2.getY()); + } + ModificationState state = region.getState(); + if (state != null) { + String str = state.getAbbreviation(); + Font tmpFont = graphics.getFont(); + graphics.setFont(getStructuralFont()); + double textX = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2; + double textY = p.getY() + graphics.getFontMetrics().getAscent() / 2; + graphics.drawString(str, (int) textX, (int) textY); + graphics.setFont(tmpFont); + } + + } +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java b/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java index 2208709e2dcc5975e740f76c339de0e5dedbf255..a7e3916c2ac693e2cc945458a86d253aa7058fef 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.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.AntisenseRnaRegion; - -/** - * Entity representing antisense rna element on the map. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("ANTISENSE_RNA_ALIAS") -public class AntisenseRna extends Species { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * List of {@link AntisenseRnaRegion regions} related to this - * {@link AntisenseRna}. - */ - @Cascade({ CascadeType.ALL }) - @OneToMany(mappedBy = "species") - @LazyCollection(LazyCollectionOption.FALSE) - private List<AntisenseRnaRegion> regions = new ArrayList<>(); - - /** - * Empty constructor required by hibernate. - */ - AntisenseRna() { - } - - /** - * Constructor that creates a copy of the element given in the parameter. - * - * @param original - * original object that will be used for creating copy - */ - public AntisenseRna(AntisenseRna original) { - super(original); - for (AntisenseRnaRegion region : original.getRegions()) { - addRegion(new AntisenseRnaRegion(region)); - } - } - - /** - * Default constructor. - * - * @param elementId - * uniqe (within model) element identifier - */ - public AntisenseRna(String elementId) { - setElementId(elementId); - } - - /** - * Adds {@link AntisenseRnaRegion} to the object. - * - * @param antisenseRnaRegion - * alement to be added - */ - public void addRegion(AntisenseRnaRegion antisenseRnaRegion) { - regions.add(antisenseRnaRegion); - antisenseRnaRegion.setSpecies(this); - } - - @Override - public AntisenseRna copy() { - if (this.getClass() == AntisenseRna.class) { - return new AntisenseRna(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - - /** - * @return the regions - * @see #regions - */ - public List<AntisenseRnaRegion> getRegions() { - return regions; - } - - /** - * @param regions - * the regions to set - * @see #regions - */ - public void setRegions(List<AntisenseRnaRegion> regions) { - this.regions = regions; - } - - @Override - public String getStringType() { - return "Antisense RNA"; - } - -} +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.AntisenseRnaRegion; + +/** + * Entity representing antisense rna element on the map. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("ANTISENSE_RNA_ALIAS") +public class AntisenseRna extends Species { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * List of {@link AntisenseRnaRegion regions} related to this + * {@link AntisenseRna}. + */ + @Cascade({ CascadeType.ALL }) + @OneToMany(mappedBy = "species") + @LazyCollection(LazyCollectionOption.FALSE) + private List<AntisenseRnaRegion> regions = new ArrayList<>(); + + /** + * Empty constructor required by hibernate. + */ + AntisenseRna() { + } + + /** + * Constructor that creates a copy of the element given in the parameter. + * + * @param original + * original object that will be used for creating copy + */ + public AntisenseRna(AntisenseRna original) { + super(original); + for (AntisenseRnaRegion region : original.getRegions()) { + addRegion(new AntisenseRnaRegion(region)); + } + } + + /** + * Default constructor. + * + * @param elementId + * unique (within model) element identifier + */ + public AntisenseRna(String elementId) { + setElementId(elementId); + } + + /** + * Adds {@link AntisenseRnaRegion} to the object. + * + * @param antisenseRnaRegion + * region to be added + */ + public void addRegion(AntisenseRnaRegion antisenseRnaRegion) { + regions.add(antisenseRnaRegion); + antisenseRnaRegion.setSpecies(this); + } + + @Override + public AntisenseRna copy() { + if (this.getClass() == AntisenseRna.class) { + return new AntisenseRna(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + + /** + * @return the regions + * @see #regions + */ + public List<AntisenseRnaRegion> getRegions() { + return regions; + } + + /** + * @param regions + * the regions to set + * @see #regions + */ + public void setRegions(List<AntisenseRnaRegion> regions) { + this.regions = regions; + } + + @Override + public String getStringType() { + return "Antisense RNA"; + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegion.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegion.java index ed51da8943b7682fb0ee357f8d9c5b7ee01377fc..fe74b066d00d68fd350c1238db92180091c96528 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegion.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegion.java @@ -1,341 +1,322 @@ -package lcsb.mapviewer.model.map.species.field; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import org.apache.log4j.Logger; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.AntisenseRna; - -/** - * This structure contains information about antisense rna region (rna fragment - * of interest) for a specific {@link AntisenseRna}. - * - * @author Piotr Gawron - * - */ -@Entity -@Table(name = "antisense_rna_region_table") -@org.hibernate.annotations.GenericGenerator(name = "test-increment-strategy", strategy = "increment") -public class AntisenseRnaRegion implements Serializable, ElementModification { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default size of the object (in graphical representation). - */ - private static final double DEFAULT_SIZE = 0.1; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(AntisenseRnaRegion.class); - - /** - * Unique identifier in the database. - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "iddb", unique = true, nullable = false) - private int id; - - /** - * String identifier of the element. Unique in the model. - */ - @Column(name = "idantisensernaregion") - private String idAntisenseRnaRegion = ""; - - /** - * Name of the region. - */ - @Column(name = "name") - private String name = ""; - - /** - * Defines a state of the region (for instance ubiquitinated etc). - * - * @see ModificationState - */ - @Column(name = "state") - private ModificationState state = null; - - /** - * Type of the region in the rna. There are three possible values: - * <ul> - * <li>Coding region,</li> - * <li>Protein binding domain,</li> - * <li>Modification site.</li> - * </ul> - */ - @Column(name = "type") - private AntisenseRnaRegionType type; - - /** - * Size of the region in the graphic representation. - */ - @Column(name = "size") - private double size = DEFAULT_SIZE; - - /** - * Position on the species in graphic representation. - */ - @Column(name = "pos") - private Double pos; - - /** - * Defines a species where the region belongs to. - */ - @Cascade({ CascadeType.ALL }) - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "idSpeciesDb") - private AntisenseRna species; - - /** - * Default constructor. - */ - public AntisenseRnaRegion() { - - } - - /** - * Constructor that initialize object with the data from the parameter. - * - * @param original - * object from which we initialize data - */ - public AntisenseRnaRegion(AntisenseRnaRegion original) { - this.idAntisenseRnaRegion = original.idAntisenseRnaRegion; - this.name = original.name; - this.size = original.size; - this.pos = original.pos; - this.type = original.type; - } - - /** - * Creates a copy of current object. - * - * @return copy of the object - */ - public AntisenseRnaRegion copy() { - if (this.getClass() == AntisenseRnaRegion.class) { - return new AntisenseRnaRegion(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - - } - - /** - * Sets size from the string. - * - * @param text - * size to parse and set - * @see #size - */ - public void setSize(String text) { - try { - size = Double.parseDouble(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid angle: " + text, e); - } - } - - /** - * Sets position from the string. - * - * @param text - * position to parse and set - * @see #pos - */ - public void setPos(String text) { - try { - pos = Double.parseDouble(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid pos: " + text, e); - } - } - - /** - * Update data in this object from parameter (only if values in parameter - * object are valid). - * - * @param mr - * object from which we are updating data - */ - public void update(AntisenseRnaRegion mr) { - if (this.idAntisenseRnaRegion != null && !this.idAntisenseRnaRegion.equals("") && !this.idAntisenseRnaRegion.equals(mr.getIdAntisenseRnaRegion())) { - throw new InvalidArgumentException("Cannot update from mr with different id"); - } - this.size = mr.getSize(); - if (mr.getState() != null) { - this.state = mr.getState(); - } - if (mr.getName() != null) { - this.name = mr.getName(); - } - if (mr.getPos() != null) { - this.setPos(mr.getPos()); - } - - } - - @Override - public String toString() { - String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getType() + "," + getPos() + "," + getSize() + ","; - return result; - } - - /** - * @return the idAntisenseRnaRegion - * @see #idAntisenseRnaRegion - */ - public String getIdAntisenseRnaRegion() { - return idAntisenseRnaRegion; - } - - /** - * @param idAntisenseRnaRegion - * the id to set - * @see #idAntisenseRnaRegion - */ - public void setIdAntisenseRnaRegion(String idAntisenseRnaRegion) { - this.idAntisenseRnaRegion = idAntisenseRnaRegion; - } - - /** - * @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 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 type - * @see #type - */ - public AntisenseRnaRegionType getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(AntisenseRnaRegionType type) { - this.type = type; - } - - /** - * @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 pos - * @see #pos - */ - public Double getPos() { - return pos; - } - - /** - * @param pos - * the pos to set - * @see #pos - */ - public void setPos(Double pos) { - this.pos = pos; - } - - /** - * @return the species - * @see #species - */ - public AntisenseRna getSpecies() { - return species; - } - - /** - * @param species - * the species to set - * @see #species - */ - public void setSpecies(AntisenseRna species) { - this.species = species; - } - - /** - * @return the id - * @see #id - */ - public int getId() { - return id; - } - - /** - * @param id - * the id to set - * @see #id - */ - public void setId(int id) { - this.id = id; - } - -} +package lcsb.mapviewer.model.map.species.field; + +import java.awt.geom.Point2D; +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.apache.log4j.Logger; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; +import org.hibernate.annotations.Type; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.species.AntisenseRna; + +/** + * This structure contains information about antisense rna region (rna fragment + * of interest) for a specific {@link AntisenseRna}. + * + * @author Piotr Gawron + * + */ +@Entity +@Table(name = "antisense_rna_region_table") +@org.hibernate.annotations.GenericGenerator(name = "test-increment-strategy", strategy = "increment") +public class AntisenseRnaRegion implements Serializable, ElementModification { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default size of the object (in graphical representation). + */ + private static final double DEFAULT_SIZE = 0.1; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(AntisenseRnaRegion.class); + + /** + * Unique identifier in the database. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "iddb", unique = true, nullable = false) + private int id; + + /** + * String identifier of the element. Unique in the model. + */ + @Column(name = "idantisensernaregion") + private String idAntisenseRnaRegion = ""; + + /** + * Name of the region. + */ + @Column(name = "name") + private String name = ""; + + /** + * Defines a state of the region (for instance ubiquitinated etc). + * + * @see ModificationState + */ + @Column(name = "state") + private ModificationState state = null; + + /** + * Type of the region in the rna. There are three possible values: + * <ul> + * <li>Coding region,</li> + * <li>Protein binding domain,</li> + * <li>Modification site.</li> + * </ul> + */ + @Column(name = "type") + private AntisenseRnaRegionType type; + + /** + * Size of the region in the graphic representation. + */ + @Column(name = "size") + private double size = DEFAULT_SIZE; + + /** + * Position on the species in graphic representation. + */ + @Column(name = "position") + @Type(type = "lcsb.mapviewer.persist.mapper.Point2DMapper") + private Point2D position; + + /** + * Defines a species where the region belongs to. + */ + @Cascade({ CascadeType.ALL }) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idSpeciesDb") + private AntisenseRna species; + + /** + * Default constructor. + */ + public AntisenseRnaRegion() { + + } + + /** + * Constructor that initialize object with the data from the parameter. + * + * @param original + * object from which we initialize data + */ + public AntisenseRnaRegion(AntisenseRnaRegion original) { + this.idAntisenseRnaRegion = original.idAntisenseRnaRegion; + this.name = original.name; + this.size = original.size; + this.type = original.type; + this.setPosition(original.getPosition()); + } + + /** + * Creates a copy of current object. + * + * @return copy of the object + */ + public AntisenseRnaRegion copy() { + if (this.getClass() == AntisenseRnaRegion.class) { + return new AntisenseRnaRegion(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + + } + + /** + * Sets size from the string. + * + * @param text + * size to parse and set + * @see #size + */ + public void setSize(String text) { + try { + size = Double.parseDouble(text); + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid angle: " + text, e); + } + } + + /** + * Update data in this object from parameter (only if values in parameter object + * are valid). + * + * @param mr + * object from which we are updating data + */ + public void update(AntisenseRnaRegion mr) { + if (this.idAntisenseRnaRegion != null && !this.idAntisenseRnaRegion.equals("") + && !this.idAntisenseRnaRegion.equals(mr.getIdAntisenseRnaRegion())) { + throw new InvalidArgumentException("Cannot update from mr with different id"); + } + this.size = mr.getSize(); + if (mr.getState() != null) { + this.state = mr.getState(); + } + if (mr.getName() != null) { + this.name = mr.getName(); + } + if (mr.getPosition() != null) { + this.setPosition(mr.getPosition()); + } + + } + + @Override + public String toString() { + String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getType() + "," + getPosition() + "," + + getSize() + ","; + return result; + } + + /** + * @return the idAntisenseRnaRegion + * @see #idAntisenseRnaRegion + */ + public String getIdAntisenseRnaRegion() { + return idAntisenseRnaRegion; + } + + /** + * @param idAntisenseRnaRegion + * the id to set + * @see #idAntisenseRnaRegion + */ + public void setIdAntisenseRnaRegion(String idAntisenseRnaRegion) { + this.idAntisenseRnaRegion = idAntisenseRnaRegion; + } + + /** + * @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 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 type + * @see #type + */ + public AntisenseRnaRegionType getType() { + return type; + } + + /** + * @param type + * the type to set + * @see #type + */ + public void setType(AntisenseRnaRegionType type) { + this.type = type; + } + + /** + * @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 AntisenseRna getSpecies() { + return species; + } + + /** + * @param species + * the species to set + * @see #species + */ + public void setSpecies(AntisenseRna species) { + this.species = species; + } + + /** + * @return the id + * @see #id + */ + public int getId() { + return id; + } + + /** + * @param id + * the id to set + * @see #id + */ + public void setId(int id) { + this.id = id; + } + + public Point2D getPosition() { + return position; + } + + public void setPosition(Point2D position) { + this.position = position; + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/AntisenseRnaComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/AntisenseRnaComparatorTest.java index 690e5c3e23d2e03934ca30e16ceeedd2feede7bd..3f8a0ab1488b511949afc0cc9b7cddc8212d8fd9 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/AntisenseRnaComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/AntisenseRnaComparatorTest.java @@ -4,6 +4,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.awt.geom.Point2D; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -81,7 +83,7 @@ public class AntisenseRnaComparatorTest { result.addRegion(region1); region1.setIdAntisenseRnaRegion("a"); region1.setName("name"); - region1.setPos("1"); + region1.setPosition(new Point2D.Double(0, 1)); region1.setSize("2"); region1.setType(AntisenseRnaRegionType.CODING_REGION); return result; diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java index a84a65a85391024557a6268a2551a156cd78bcf4..9f91ffb5ad4bff39f4fd1a5827c0237b8b0bf963 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java @@ -1,170 +1,164 @@ -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.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.modifier.Catalysis; -import lcsb.mapviewer.model.map.species.AntisenseRna; -import lcsb.mapviewer.model.map.species.Drug; - -public class AntisenseRnaRegionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new AntisenseRnaRegion()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor1() { - try { - AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); - AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(antisenseRna); - assertNotNull(antisenseRna2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate() { - try { - AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); - antisenseRna.setState(ModificationState.EMPTY); - antisenseRna.setName("as"); - antisenseRna.setPos(3.0); - AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); - antisenseRna2.update(antisenseRna); - assertEquals(antisenseRna.getState(), antisenseRna2.getState()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidUpdate() { - try { - AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); - AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); - antisenseRna.setIdAntisenseRnaRegion("@1"); - antisenseRna2.setIdAntisenseRnaRegion("@"); - antisenseRna2.update(antisenseRna); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - AntisenseRnaRegion region = new AntisenseRnaRegion(new AntisenseRnaRegion()); - int id = 91; - AntisenseRna species = new AntisenseRna("id"); - double pos = 4.6; - double size = 5.3; - AntisenseRnaRegionType type = AntisenseRnaRegionType.CODING_REGION; - String name = "nam"; - String idAntisenseRnaRegion = "iddd"; - - region.setId(id); - region.setSpecies(species); - region.setPos(pos); - region.setSize(size); - region.setType(type); - region.setName(name); - region.setIdAntisenseRnaRegion(idAntisenseRnaRegion); - region.setState(ModificationState.ACETYLATED); - - assertEquals(id, region.getId()); - assertEquals(species, region.getSpecies()); - assertEquals(pos, region.getPos(), Configuration.EPSILON); - assertEquals(size, region.getSize(), Configuration.EPSILON); - assertEquals(type, region.getType()); - assertEquals(name, region.getName()); - assertEquals(idAntisenseRnaRegion, region.getIdAntisenseRnaRegion()); - - assertEquals(ModificationState.ACETYLATED, region.getState()); - - try { - region.setSize("text"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - - try { - region.setPos("text"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - - region.setSize("1.0"); - region.setPos("1.0"); - assertEquals(1.0, region.getPos(), Configuration.EPSILON); - assertEquals(1.0, region.getSize(), Configuration.EPSILON); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToString() { - try { - assertNotNull(new AntisenseRnaRegion().toString()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - AntisenseRnaRegion degraded = new AntisenseRnaRegion().copy(); - assertNotNull(degraded); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - Mockito.mock(AntisenseRnaRegion.class, Mockito.CALLS_REAL_METHODS).copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +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 java.awt.geom.Point2D; + +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.Configuration; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.modifier.Catalysis; +import lcsb.mapviewer.model.map.species.AntisenseRna; +import lcsb.mapviewer.model.map.species.Drug; + +public class AntisenseRnaRegionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new AntisenseRnaRegion()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor1() { + try { + AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); + AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(antisenseRna); + assertNotNull(antisenseRna2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate() { + try { + AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); + antisenseRna.setState(ModificationState.EMPTY); + antisenseRna.setName("as"); + antisenseRna.setPosition(new Point2D.Double(10, 0)); + AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); + antisenseRna2.update(antisenseRna); + assertEquals(antisenseRna.getState(), antisenseRna2.getState()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidUpdate() { + try { + AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); + AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); + antisenseRna.setIdAntisenseRnaRegion("@1"); + antisenseRna2.setIdAntisenseRnaRegion("@"); + antisenseRna2.update(antisenseRna); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + AntisenseRnaRegion region = new AntisenseRnaRegion(new AntisenseRnaRegion()); + int id = 91; + AntisenseRna species = new AntisenseRna("id"); + Point2D position = new Point2D.Double(10, 20); + double size = 5.3; + AntisenseRnaRegionType type = AntisenseRnaRegionType.CODING_REGION; + String name = "nam"; + String idAntisenseRnaRegion = "iddd"; + + region.setId(id); + region.setSpecies(species); + region.setPosition(position); + region.setSize(size); + region.setType(type); + region.setName(name); + region.setIdAntisenseRnaRegion(idAntisenseRnaRegion); + region.setState(ModificationState.ACETYLATED); + + assertEquals(id, region.getId()); + assertEquals(species, region.getSpecies()); + assertEquals(position.distance(region.getPosition()), 0, Configuration.EPSILON); + assertEquals(size, region.getSize(), Configuration.EPSILON); + assertEquals(type, region.getType()); + assertEquals(name, region.getName()); + assertEquals(idAntisenseRnaRegion, region.getIdAntisenseRnaRegion()); + + assertEquals(ModificationState.ACETYLATED, region.getState()); + + try { + region.setSize("text"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + + region.setSize("1.0"); + assertEquals(1.0, region.getSize(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToString() { + try { + assertNotNull(new AntisenseRnaRegion().toString()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + AntisenseRnaRegion degraded = new AntisenseRnaRegion().copy(); + assertNotNull(degraded); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + Mockito.mock(AntisenseRnaRegion.class, Mockito.CALLS_REAL_METHODS).copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/persist/src/db/12.1.0~alpha.0/fix_db_20180705.sql b/persist/src/db/12.1.0~alpha.0/fix_db_20180705.sql new file mode 100644 index 0000000000000000000000000000000000000000..d7bfbb3822d9b7af353d10b4e91556e39c903273 --- /dev/null +++ b/persist/src/db/12.1.0~alpha.0/fix_db_20180705.sql @@ -0,0 +1,7 @@ +-- coordinates for antisense rna changed into absolute x,y + +alter table antisense_rna_region_table add column position varchar(255); +update antisense_rna_region_table set position=concat(element_table.x+(element_table.width*3/4*antisense_rna_region_table.pos),',',element_table.y) from element_table where element_table.iddb = antisense_rna_region_table.idspeciesdb and not pos is null; +update antisense_rna_region_table set position=concat(element_table.x,',',element_table.y) from element_table where element_table.iddb = antisense_rna_region_table.idspeciesdb and pos is null; +alter table antisense_rna_region_table drop column pos; +