Commit 1eff0b42 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

antesense rna region is a subclass of modification residue

parent 14a66f69
......@@ -17,7 +17,6 @@ import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Protein;
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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
......@@ -102,7 +101,7 @@ public class CellDesignerElementCollection {
String modifications = "";
if (modelElement instanceof AntisenseRna) {
AntisenseRna asAntisenseRna = ((AntisenseRna) modelElement);
for (AntisenseRnaRegion region : asAntisenseRna.getRegions()) {
for (ModificationResidue region : asAntisenseRna.getRegions()) {
modifications += region.getState();
}
} else if (modelElement instanceof Gene) {
......@@ -135,7 +134,8 @@ public class CellDesignerElementCollection {
if (!isCyclicNesting(((Species) modelElement).getComplex())) {
complexId = getElementId(((Species) modelElement).getComplex());
} else {
throw new InvalidArgumentException("Cycling nested structure found in element: " + modelElement.getElementId());
throw new InvalidArgumentException(
"Cycling nested structure found in element: " + modelElement.getElementId());
}
} else {
complexId = ((Species) modelElement).getComplex().getName();
......@@ -159,8 +159,8 @@ public class CellDesignerElementCollection {
// name, compartment, modifications, homodimer, state, complex where it's
// located,
// children of the complex
String sbmlId = compartmenName + "\n" + modelElement.getName() + "\n" + modelElement.getStringType() + "\n" + modifications + "\n" + complexId + "\n"
+ homodimer + "\n" + childrenId;
String sbmlId = compartmenName + "\n" + modelElement.getName() + "\n" + modelElement.getStringType() + "\n"
+ modifications + "\n" + complexId + "\n" + homodimer + "\n" + childrenId;
return sbmlId;
}
......@@ -170,8 +170,8 @@ public class CellDesignerElementCollection {
*
* @param complex
* complex for which data is checked
* @return true if parent of the complex is also a (grand)child of this
* complex, false otherwise
* @return true if parent of the complex is also a (grand)child of this complex,
* false otherwise
*/
private boolean isCyclicNesting(Complex complex) {
Set<Complex> foundComplexes = new HashSet<>();
......@@ -218,15 +218,15 @@ public class CellDesignerElementCollection {
*/
public void addElement(CellDesignerElement<?> element, String id) {
if (elementById.get(id) != null) {
throw new InvalidArgumentException(
"[" + element.getClass().getSimpleName() + " " + element.getElementId() + "]\t" + "Element with given id alread exists. ID: " + id);
throw new InvalidArgumentException("[" + element.getClass().getSimpleName() + " " + element.getElementId() + "]\t"
+ "Element with given id alread exists. ID: " + id);
}
elementById.put(id, element);
}
/**
* Adds CellDesigner structure in a way that it would be accessed via
* identifier for model structure. Method used only for unit test.
* Adds CellDesigner structure in a way that it would be accessed via identifier
* for model structure. Method used only for unit test.
*
* @param modelElement
* model element that will create identifier
......
......@@ -5,6 +5,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
......@@ -12,8 +13,10 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerAntisen
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain;
/**
* Class that performs parsing of the CellDesigner xml for AntisenseRna object.
......@@ -100,7 +103,7 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
result += "</celldesigner:notes>";
if (antisenseRna.getRegions().size() > 0) {
result += "<celldesigner:listOfRegions>";
for (AntisenseRnaRegion region : antisenseRna.getRegions()) {
for (ModificationResidue region : antisenseRna.getRegions()) {
result += toXml(region);
}
result += "</celldesigner:listOfRegions>";
......@@ -116,17 +119,30 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
* object to be transformed
* @return xml representation of the given region
*/
private String toXml(AntisenseRnaRegion region) {
private String toXml(ModificationResidue region) {
String result = "";
String attributes = "";
if (!region.getIdAntisenseRnaRegion().equals("")) {
attributes += " id=\"" + region.getIdAntisenseRnaRegion() + "\"";
if (!region.getIdModificationResidue().equals("")) {
attributes += " id=\"" + region.getIdModificationResidue() + "\"";
}
if (!region.getName().equals("")) {
attributes += " name=\"" + escapeXml(region.getName()) + "\"";
}
if (region.getWidth() != 0) {
attributes += " size=\"" + region.getWidth() / region.getSpecies().getWidth() + "\"";
double width = 0;
String type = null;
if (region instanceof CodingRegion) {
width = ((CodingRegion) region).getWidth();
type = "CodingRegion";
} else if (region instanceof ModificationSite) {
type = "Modification Site";
} else if (region instanceof ProteinBindingDomain) {
width = ((ProteinBindingDomain) region).getWidth();
type = "proteinBindingDomain";
} else {
throw new InvalidArgumentException("Unknown modificatin type: " + region.getClass());
}
if (width != 0) {
attributes += " size=\"" + width / region.getSpecies().getWidth() + "\"";
}
if (region.getPosition() != null) {
double pos = (region.getPosition().getX() - region.getSpecies().getWidth())
......@@ -134,9 +150,7 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
attributes += " pos=\"" + pos + "\"";
}
if (region.getType() != null) {
attributes += " type=\"" + region.getType().getName() + "\"";
}
attributes += " type=\"" + type + "\"";
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>";
......@@ -160,12 +174,18 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
residue.setPos(getNodeAttr("pos", regionNode));
String typeString = getNodeAttr("type", regionNode);
if (typeString != null) {
AntisenseRnaRegionType type = AntisenseRnaRegionType.getTypeByString(typeString);
if (type == null) {
String type;
if (typeString.equals("CodingRegion")) {
type = "CODING_REGION";
} else if (typeString.equals("Modification Site")) {
type = "MODIFICATION_SITE";
} else if (typeString.equals("proteinBindingDomain")) {
type = "PROTEIN_BINDING_DOMAIN";
} else
throw new InvalidXmlSchemaException("Unknown antisense rna region type: " + typeString);
residue.setModificationType(type);
}
residue.setType(type);
}
NodeList list = regionNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
......
......@@ -9,9 +9,11 @@ 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.CodingRegion;
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.ProteinBindingDomain;
/**
* This structure contains information about antisense rna region (rna fragment
......@@ -62,15 +64,7 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
*/
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;
private String modificationType;
/**
* Size of the region in the graphic representation.
......@@ -105,7 +99,7 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
this.name = original.name;
this.size = original.size;
this.pos = original.pos;
this.type = original.type;
this.modificationType = original.modificationType;
}
/**
......@@ -179,8 +173,8 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
@Override
public String toString() {
String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getType() + "," + getPos() + "," + getSize()
+ ",";
String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getModificationType() + "," + getPos() + ","
+ getSize() + ",";
return result;
}
......@@ -235,23 +229,6 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
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
......@@ -325,15 +302,33 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
*
* @return {@link AntisenseRnaRegion} representing this object in a model
*/
public AntisenseRnaRegion createAntisenseRegionAlias(Element element) {
AntisenseRnaRegion result = new AntisenseRnaRegion();
result.setIdAntisenseRnaRegion(idAntisenseRnaRegion);
public ModificationResidue createAntisenseRegionAlias(Element element) {
ModificationResidue result;
if (modificationType.equals("MODIFICATION_SITE")) {
result = new ModificationSite();
} else if (modificationType.equals("CODING_REGION")) {
result = new CodingRegion();
((ProteinBindingDomain) result).setWidth(element.getWidth() * size);
} else if (modificationType.equals("PROTEIN_BINDING_DOMAIN")) {
result = new ProteinBindingDomain();
((ProteinBindingDomain) result).setWidth(element.getWidth() * size);
} else {
throw new InvalidArgumentException("Unknown antisense rna modification type: " + modificationType);
}
result.setIdModificationResidue(idAntisenseRnaRegion);
result.setName(name);
result.setWidth(element.getWidth()*size);
result.setPosition(new Point2D.Double(element.getX() + element.getWidth() * 3.0 / 4.0 * pos, element.getY()));
result.setType(type);
return result;
}
public String getModificationType() {
return modificationType;
}
public void setModificationType(String modificationType) {
this.modificationType = modificationType;
}
}
......@@ -23,7 +23,6 @@ import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerAntisenseRna;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType;
public class AntisenseRnaXmlParserTest extends CellDesignerTestFunctions {
protected Logger logger = Logger.getLogger(AntisenseRnaXmlParserTest.class.getName());
......@@ -58,7 +57,7 @@ public class AntisenseRnaXmlParserTest extends CellDesignerTestFunctions {
assertEquals("zzz", region.getName());
assertEquals(0.3, region.getSize(), 1e-6);
assertEquals(0.29999999999999993, region.getPos(), 1e-6);
assertEquals(AntisenseRnaRegionType.CODING_REGION, region.getType());
assertEquals("CODING_REGION", region.getModificationType());
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -149,7 +148,7 @@ public class AntisenseRnaXmlParserTest extends CellDesignerTestFunctions {
assertEquals(region.getName(), region2.getName());
assertEquals(region.getSize(), region2.getSize(), 1e-6);
assertEquals(region.getPos(), region2.getPos(), 1e-6);
assertEquals(region.getType(), region2.getType());
assertEquals(region.getModificationType(), region2.getModificationType());
} catch (Exception e) {
e.printStackTrace();
......
......@@ -13,7 +13,6 @@ import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType;
import lcsb.mapviewer.model.map.species.field.ModificationState;
public class AntisenseRnaRegionTest {
......@@ -88,7 +87,7 @@ public class AntisenseRnaRegionTest {
CellDesignerAntisenseRna species = new CellDesignerAntisenseRna();
double pos = 4.6;
double size = 5.3;
AntisenseRnaRegionType type = AntisenseRnaRegionType.CODING_REGION;
String type = "CODING_REGION";
String name = "nam";
String idAntisenseRnaRegion = "iddd";
......@@ -96,7 +95,7 @@ public class AntisenseRnaRegionTest {
region.setSpecies(species);
region.setPos(pos);
region.setSize(size);
region.setType(type);
region.setModificationType(type);
region.setName(name);
region.setIdAntisenseRnaRegion(idAntisenseRnaRegion);
region.setState(ModificationState.ACETYLATED);
......@@ -105,7 +104,7 @@ public class AntisenseRnaRegionTest {
assertEquals(species, region.getSpecies());
assertEquals(pos, region.getPos(), Configuration.EPSILON);
assertEquals(size, region.getSize(), Configuration.EPSILON);
assertEquals(type, region.getType());
assertEquals(type, region.getModificationType());
assertEquals(name, region.getName());
assertEquals(idAntisenseRnaRegion, region.getIdAntisenseRnaRegion());
......
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;
......@@ -18,8 +17,7 @@ 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;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* This class defines methods used for drawing {@link AntisenseRna} on the
......@@ -59,7 +57,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> {
graphics.draw(path);
graphics.setStroke(stroke);
for (AntisenseRnaRegion mr : antisenseRna.getRegions()) {
for (ModificationResidue mr : antisenseRna.getRegions()) {
drawRegion(antisenseRna, mr, graphics, false);
}
......@@ -102,7 +100,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> {
* @param drawDescription
* flag determining if we want to draw description as well
*/
private void drawRegion(final AntisenseRna antisenseRna, final AntisenseRnaRegion region, final Graphics2D graphics,
private void drawRegion(final AntisenseRna antisenseRna, final ModificationResidue region, final Graphics2D graphics,
final boolean drawDescription) {
double diameter = DEFAULT_MODIFICATION_DIAMETER;
......
......@@ -13,7 +13,7 @@ import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Entity representing antisense rna element on the map.
......@@ -37,7 +37,7 @@ public class AntisenseRna extends Species {
@Cascade({ CascadeType.ALL })
@OneToMany(mappedBy = "species")
@LazyCollection(LazyCollectionOption.FALSE)
private List<AntisenseRnaRegion> regions = new ArrayList<>();
private List<ModificationResidue> regions = new ArrayList<>();
/**
* Empty constructor required by hibernate.
......@@ -53,8 +53,8 @@ public class AntisenseRna extends Species {
*/
public AntisenseRna(AntisenseRna original) {
super(original);
for (AntisenseRnaRegion region : original.getRegions()) {
addRegion(new AntisenseRnaRegion(region));
for (ModificationResidue region : original.getRegions()) {
addRegion(region.copy());
}
}
......@@ -74,7 +74,7 @@ public class AntisenseRna extends Species {
* @param antisenseRnaRegion
* region to be added
*/
public void addRegion(AntisenseRnaRegion antisenseRnaRegion) {
public void addRegion(ModificationResidue antisenseRnaRegion) {
regions.add(antisenseRnaRegion);
antisenseRnaRegion.setSpecies(this);
}
......@@ -92,7 +92,7 @@ public class AntisenseRna extends Species {
* @return the regions
* @see #regions
*/
public List<AntisenseRnaRegion> getRegions() {
public List<ModificationResidue> getRegions() {
return regions;
}
......@@ -101,7 +101,7 @@ public class AntisenseRna extends Species {
* the regions to set
* @see #regions
*/
public void setRegions(List<AntisenseRnaRegion> regions) {
public void setRegions(List<ModificationResidue> regions) {
this.regions = regions;
}
......
......@@ -8,7 +8,7 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Comparator class used for comparing {@link AntisenseRna} objects.
......@@ -59,11 +59,11 @@ public class AntisenseRnaComparator extends Comparator<AntisenseRna> {
Set<String> set1 = new HashSet<String>();
Set<String> set2 = new HashSet<String>();
for (AntisenseRnaRegion region : arg0.getRegions()) {
for (ModificationResidue region : arg0.getRegions()) {
set1.add(region.toString());
}
for (AntisenseRnaRegion region : arg1.getRegions()) {
for (ModificationResidue region : arg1.getRegions()) {
set2.add(region.toString());
}
......
package lcsb.mapviewer.model.map.species.field;
import lcsb.mapviewer.model.map.species.AntisenseRna;
/**
* Enum that enlists types of available modification regions in
* {@link AntisenseRna}.
*
* @author Piotr Gawron
*
*/
public enum AntisenseRnaRegionType {
/**
* Modification site.
*/
MODIFICATION_SITE("Modification Site"), //
/**
* Coding region.
*/
CODING_REGION("CodingRegion"), //
/**
* Protein binding domain.
*/
PROTEIN_BINDING_DOMAIN("proteinBindingDomain");
/**
* Name of the type.
*/
private String name;
/**
* Default constructor.
*
* @param name
* name of the type
*/
AntisenseRnaRegionType(String name) {
this.name = name;
}
/**
* @return the name
* @see #name
*/
public String getName() {
return name;
}
/**
* Returns {@link AntisenseRnaRegionType} identified by name.
*
* @param name
* name of the region
* @return {@link AntisenseRnaRegionType} identified by name
*/
public static AntisenseRnaRegionType getTypeByString(String name) {
for (AntisenseRnaRegionType type : values()) {
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
}
\ No newline at end of file
package lcsb.mapviewer.model.map.species.field;
import java.awt.geom.Point2D;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.apache.log4j.Logger;
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
@DiscriminatorValue("MODIFICATION_SITE")
public class CodingRegion extends ModificationResidue implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default size of the object (in graphical representation).
*/
private static final double DEFAULT_SIZE = 10;