Commit b2c643f0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

rna region is a subclass of modification residue

parent 1eff0b42
......@@ -18,7 +18,6 @@ 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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* This structure contains information about {@link CellDesignerElement
......@@ -117,7 +116,7 @@ public class CellDesignerElementCollection {
}
} else if (modelElement instanceof Rna) {
Rna asRna = ((Rna) modelElement);
for (RnaRegion region : asRna.getRegions()) {
for (ModificationResidue region : asRna.getRegions()) {
modifications += region.getState();
}
} else if (modelElement instanceof Complex) {
......
......@@ -14,7 +14,8 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner
import lcsb.mapviewer.model.map.species.Rna;
/**
* Class that performs parsing of the CellDesigner xml for {@link CellDesignerRna} object.
* Class that performs parsing of the CellDesigner xml for
* {@link CellDesignerRna} object.
*
* @author Piotr Gawron
*
......@@ -29,8 +30,8 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna>
private Logger logger = Logger.getLogger(RnaXmlParser.class.getName());
/**
* Collection of {@link CellDesignerElement cell designer elements} parsed
* from xml.
* Collection of {@link CellDesignerElement cell designer elements} parsed from
* xml.
*/
private CellDesignerElementCollection elements;
......@@ -65,7 +66,8 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna>
if (residueNode.getNodeName().equalsIgnoreCase("celldesigner:region")) {
rna.addRegion(getRnaRegion(residueNode));
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
throw new InvalidXmlSchemaException(
"Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
}
}
}
......@@ -91,7 +93,19 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna>
residue.setIdRnaRegion(getNodeAttr("id", residueNode));
residue.setSize(getNodeAttr("size", residueNode));
residue.setPos(getNodeAttr("pos", residueNode));
residue.setType(getNodeAttr("type", residueNode));
String typeString = getNodeAttr("type", residueNode);
if (typeString != 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);
}
NodeList list = residueNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
......
......@@ -168,7 +168,9 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
if (mr.getPos() != null) {
this.setPos(mr.getPos());
}
if (mr.getModificationType() != null) {
this.setModificationType(mr.getModificationType());
}
}
@Override
......@@ -308,7 +310,7 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
result = new ModificationSite();
} else if (modificationType.equals("CODING_REGION")) {
result = new CodingRegion();
((ProteinBindingDomain) result).setWidth(element.getWidth() * size);
((CodingRegion) result).setWidth(element.getWidth() * size);
} else if (modificationType.equals("PROTEIN_BINDING_DOMAIN")) {
result = new ProteinBindingDomain();
((ProteinBindingDomain) result).setWidth(element.getWidth() * size);
......
......@@ -9,9 +9,11 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.field.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;
import lcsb.mapviewer.model.map.species.field.Residue;
/**
......@@ -109,6 +111,10 @@ public class CellDesignerModificationResidue implements Serializable {
this.modificationType = "RESIDUE";
} else if (mr instanceof ModificationSite) {
this.modificationType = "MODIFICATION_SITE";
} else if (mr instanceof CodingRegion) {
this.modificationType = "CODING_REGION";
} else if (mr instanceof ProteinBindingDomain) {
this.modificationType = "PROTEIN_BINDING_DOMAIN";
} else {
throw new InvalidArgumentException("Unknown modification type: " + mr.getClass());
}
......
......@@ -8,8 +8,11 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna;
import lcsb.mapviewer.model.map.species.Rna;
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.RnaRegion;
import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain;
/**
* This structure contains information about rna region (rna fragment of
......@@ -44,15 +47,7 @@ public class CellDesignerRnaRegion implements Serializable {
*/
private String idRnaRegion = "";
/**
* 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 String type = "";
private String modificationType;
/**
* Defines a state of the region (for instance ubiquitinated etc).
......@@ -89,7 +84,7 @@ public class CellDesignerRnaRegion implements Serializable {
}
/**
* Creates object with the data taken from paramter region.
* Creates object with the data taken from parameter region.
*
* @param mr
* original {@link CellDesignerRnaRegion}
......@@ -98,7 +93,7 @@ public class CellDesignerRnaRegion implements Serializable {
this.idRnaRegion = mr.idRnaRegion;
this.size = mr.size;
setPos(mr.getPos());
this.type = mr.type;
this.modificationType = mr.modificationType;
this.state = mr.state;
this.name = mr.name;
}
......@@ -153,12 +148,16 @@ public class CellDesignerRnaRegion implements Serializable {
if (mr.getPos() != null) {
this.setPos(mr.getPos());
}
if (mr.getModificationType() != null) {
this.setModificationType(mr.getModificationType());
}
}
@Override
public String toString() {
String result = "" + getIdRnaRegion() + "," + getType() + "," + getPos() + "," + getSize() + "," + getState() + ",";
String result = "" + getIdRnaRegion() + "," + getModificationType() + "," + getPos() + "," + getSize() + ","
+ getState() + ",";
return result;
}
......@@ -180,23 +179,6 @@ public class CellDesignerRnaRegion implements Serializable {
this.idRnaRegion = id;
}
/**
* @return the type
* @see #type
*/
public String getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the state
* @see #state
......@@ -287,16 +269,36 @@ public class CellDesignerRnaRegion implements Serializable {
*
* @return {@link RnaRegion} representing this object in a model
*/
public RnaRegion createRnaRegionAlias(Rna element) {
RnaRegion result = new RnaRegion();
result.setIdRnaRegion(this.idRnaRegion);
result.setWidth(this.size * element.getWidth());
public ModificationResidue createRnaRegionAlias(Rna element) {
ModificationResidue result;
if (modificationType == null) {
throw new InvalidArgumentException("No type information for modification: " + idRnaRegion);
} else if (modificationType.equals("MODIFICATION_SITE")) {
result = new ModificationSite();
} else if (modificationType.equals("CODING_REGION")) {
result = new CodingRegion();
((CodingRegion) 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(this.idRnaRegion);
result.setPosition(new Point2D.Double(
element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * pos, element.getY()));
result.setType(this.getType());
result.setState(this.state);
result.setName(this.name);
return result;
}
public String getModificationType() {
return modificationType;
}
public void setModificationType(String modificationType) {
this.modificationType = modificationType;
}
}
......@@ -12,7 +12,6 @@ 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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* Structure for storing the state of the Species in CellDesigner format.
......@@ -84,11 +83,8 @@ public class SpeciesState {
setStructuralState(complex.getStructuralState());
} else if (species instanceof Rna) {
Rna rna = (Rna) species;
for (RnaRegion region : rna.getRegions()) {
CellDesignerModificationResidue mr = new CellDesignerModificationResidue();
mr.setIdModificationResidue(region.getIdRnaRegion());
mr.setSize(region.getWidth() / (rna.getWidth() * 3.0 / 4.0));
mr.setState(region.getState());
for (ModificationResidue region : rna.getRegions()) {
CellDesignerModificationResidue mr = new CellDesignerModificationResidue(region);
addModificationResidue(mr);
}
} else if (species instanceof Gene) {
......
......@@ -16,8 +16,8 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
public class SpeciesStateTest {
......@@ -52,7 +52,11 @@ public class SpeciesStateTest {
@Test
public void testConstructorFromRna() {
Rna rna = new Rna("1");
rna.addRegion(new RnaRegion());
rna.setWidth(60);
rna.setHeight(10);
CodingRegion mr = new CodingRegion();
mr.setPosition(new Point2D.Double(10, 40));
rna.addRegion(mr);
SpeciesState state = new SpeciesState(rna);
assertEquals(1, state.getModifications().size());
}
......
......@@ -21,7 +21,7 @@ import lcsb.mapviewer.persist.dao.map.ModelDao;
@Transactional(value = "txManager")
@ContextConfiguration(locations = { "/applicationContext-persist.xml", //
"/test-applicationContext.xml",//
"/test-applicationContext.xml", //
"/dataSource.xml", //
})
......@@ -37,7 +37,8 @@ public class DbSerializationTest {
private void makeDbSerializationTest(String filePath) throws Exception {
SbgnmlXmlParser parser = new SbgnmlXmlParser();
Model model = parser.createModel(new ConverterParams().filename("testFiles/sbgnmlParserTestFiles/sbgnmlFiles/".concat(filePath)));
Model model = parser
.createModel(new ConverterParams().filename("testFiles/sbgnmlParserTestFiles/sbgnmlFiles/".concat(filePath)));
modelDao.add(model);
modelDao.flush();
......
......@@ -25,8 +25,8 @@ import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* This class defines methods used for drawing {@link Rna} on the
......@@ -65,7 +65,7 @@ public class RnaConverter extends SpeciesConverter<Rna> {
graphics.draw(path);
graphics.setStroke(stroke);
for (RnaRegion mr : rna.getRegions()) {
for (ModificationResidue mr : rna.getRegions()) {
drawModification(rna, mr, graphics, false, false);
}
......@@ -113,7 +113,7 @@ public class RnaConverter extends SpeciesConverter<Rna> {
* flag that indicates if we should draw description of the
* modification
*/
private void drawModification(final Rna rna, final RnaRegion region, final Graphics2D graphics,
private void drawModification(final Rna rna, final ModificationResidue region, final Graphics2D graphics,
final boolean drawEmptyModification, final boolean drawDescription) {
if ((!drawEmptyModification) && (region.getState() == null)) {
return;
......
......@@ -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.RnaRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Entity representing rna element on the map.
......@@ -36,7 +36,7 @@ public class Rna extends Species {
@Cascade({ CascadeType.ALL })
@OneToMany(mappedBy = "species", orphanRemoval = true)
@LazyCollection(LazyCollectionOption.FALSE)
private List<RnaRegion> regions = new ArrayList<>();
private List<ModificationResidue> regions = new ArrayList<>();
/**
* Empty constructor required by hibernate.
......@@ -52,8 +52,8 @@ public class Rna extends Species {
*/
public Rna(Rna original) {
super(original);
for (RnaRegion region : original.getRegions()) {
addRegion(new RnaRegion(region));
for (ModificationResidue region : original.getRegions()) {
addRegion(region.copy());
}
}
......@@ -74,7 +74,7 @@ public class Rna extends Species {
* @param rnaRegion
* object to be added
*/
public void addRegion(RnaRegion rnaRegion) {
public void addRegion(ModificationResidue rnaRegion) {
regions.add(rnaRegion);
rnaRegion.setSpecies(this);
}
......@@ -92,7 +92,7 @@ public class Rna extends Species {
* @return the regions
* @see #regions
*/
public List<RnaRegion> getRegions() {
public List<ModificationResidue> getRegions() {
return regions;
}
......@@ -101,7 +101,7 @@ public class Rna extends Species {
* the regions to set
* @see #regions
*/
public void setRegions(List<RnaRegion> 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.RnaRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Comparator class used for comparing {@link Rna} objects.
......@@ -59,11 +59,11 @@ public class RnaComparator extends Comparator<Rna> {
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
for (RnaRegion region : arg0.getRegions()) {
for (ModificationResidue region : arg0.getRegions()) {
set1.add(region.toString());
}
for (RnaRegion region : arg1.getRegions()) {
for (ModificationResidue region : arg1.getRegions()) {
set2.add(region.toString());
}
......
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 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;
......@@ -50,47 +39,12 @@ public class ProteinBindingDomain extends ModificationResidue implements Seriali
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ProteinBindingDomain.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 = "";
/**
* Width of the region in the graphic representation.
*/
@Column(name = "width")
private double width = 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.
*/
......@@ -105,13 +59,7 @@ public class ProteinBindingDomain extends ModificationResidue implements Seriali
* object from which we initialize data
*/
public ProteinBindingDomain(ProteinBindingDomain original) {
this.idAntisenseRnaRegion = original.idAntisenseRnaRegion;
this.name = original.name;
Point2D position = new Point2D.Double();
if (original.getPosition() != null) {
position.setLocation(original.getPosition());
}
this.setPosition(position);
super(original);
this.setWidth(original.getWidth());
}
......@@ -137,13 +85,13 @@ public class ProteinBindingDomain extends ModificationResidue implements Seriali
* object from which we are updating data
*/
public void update(ProteinBindingDomain mr) {
if (this.idAntisenseRnaRegion != null && !this.idAntisenseRnaRegion.equals("")
&& !this.idAntisenseRnaRegion.equals(mr.getIdAntisenseRnaRegion())) {
if (this.getIdModificationResidue() != null && !this.getIdModificationResidue().equals("")
&& !this.getIdModificationResidue().equals(mr.getIdModificationResidue())) {
throw new InvalidArgumentException("Cannot update from mr with different id");
}
this.setWidth(mr.getWidth());
if (mr.getName() != null) {
this.name = mr.getName();
this.setName(mr.getName());
}
if (mr.getPosition() != null) {
this.setPosition(mr.getPosition());
......@@ -153,94 +101,10 @@ public class ProteinBindingDomain extends ModificationResidue implements Seriali
@Override
public String toString() {
String result = getIdAntisenseRnaRegion() + "," + getName() + "," + getPosition() + "," + getWidth() + ",";
String result = getIdModificationResidue() + "," + getName() + "," + getPosition() + "," + getWidth() + ",";
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
*/