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; ...@@ -18,7 +18,6 @@ import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna; import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/** /**
* This structure contains information about {@link CellDesignerElement * This structure contains information about {@link CellDesignerElement
...@@ -117,7 +116,7 @@ public class CellDesignerElementCollection { ...@@ -117,7 +116,7 @@ public class CellDesignerElementCollection {
} }
} else if (modelElement instanceof Rna) { } else if (modelElement instanceof Rna) {
Rna asRna = ((Rna) modelElement); Rna asRna = ((Rna) modelElement);
for (RnaRegion region : asRna.getRegions()) { for (ModificationResidue region : asRna.getRegions()) {
modifications += region.getState(); modifications += region.getState();
} }
} else if (modelElement instanceof Complex) { } else if (modelElement instanceof Complex) {
......
...@@ -14,7 +14,8 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner ...@@ -14,7 +14,8 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner
import lcsb.mapviewer.model.map.species.Rna; 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 * @author Piotr Gawron
* *
...@@ -22,105 +23,118 @@ import lcsb.mapviewer.model.map.species.Rna; ...@@ -22,105 +23,118 @@ import lcsb.mapviewer.model.map.species.Rna;
public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> { public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> {
/** /**
* Default class logger. * Default class logger.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Logger logger = Logger.getLogger(RnaXmlParser.class.getName()); private Logger logger = Logger.getLogger(RnaXmlParser.class.getName());
/** /**
* Collection of {@link CellDesignerElement cell designer elements} parsed * Collection of {@link CellDesignerElement cell designer elements} parsed from
* from xml. * xml.
*/ */
private CellDesignerElementCollection elements; private CellDesignerElementCollection elements;
/** /**
* Default constructor. Model is required because some nodes require access to * Default constructor. Model is required because some nodes require access to
* other parts of the model. * other parts of the model.
* *
* @param elements * @param elements
* collection of {@link CellDesignerElement cell designer elements} * collection of {@link CellDesignerElement cell designer elements}
* parsed from xml * parsed from xml
*/ */
public RnaXmlParser(CellDesignerElementCollection elements) { public RnaXmlParser(CellDesignerElementCollection elements) {
this.elements = elements; this.elements = elements;
} }
@Override @Override
public Pair<String, CellDesignerRna> parseXmlElement(Node rnaNode) throws InvalidXmlSchemaException { public Pair<String, CellDesignerRna> parseXmlElement(Node rnaNode) throws InvalidXmlSchemaException {
CellDesignerRna rna = new CellDesignerRna(); CellDesignerRna rna = new CellDesignerRna();
String identifier = getNodeAttr("id", rnaNode); String identifier = getNodeAttr("id", rnaNode);
rna.setName(decodeName(getNodeAttr("name", rnaNode))); rna.setName(decodeName(getNodeAttr("name", rnaNode)));
NodeList list = rnaNode.getChildNodes(); NodeList list = rnaNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) { for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i); Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("celldesigner:notes")) { if (node.getNodeName().equals("celldesigner:notes")) {
rna.setNotes(getRap().getNotes(node)); rna.setNotes(getRap().getNotes(node));
} else if (node.getNodeName().equals("celldesigner:listOfRegions")) { } else if (node.getNodeName().equals("celldesigner:listOfRegions")) {
NodeList residueList = node.getChildNodes(); NodeList residueList = node.getChildNodes();
for (int j = 0; j < residueList.getLength(); j++) { for (int j = 0; j < residueList.getLength(); j++) {
Node residueNode = residueList.item(j); Node residueNode = residueList.item(j);
if (residueNode.getNodeType() == Node.ELEMENT_NODE) { if (residueNode.getNodeType() == Node.ELEMENT_NODE) {
if (residueNode.getNodeName().equalsIgnoreCase("celldesigner:region")) { if (residueNode.getNodeName().equalsIgnoreCase("celldesigner:region")) {
rna.addRegion(getRnaRegion(residueNode)); rna.addRegion(getRnaRegion(residueNode));
} else { } else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName()); throw new InvalidXmlSchemaException(
} "Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
} }
} }
} else { }
throw new InvalidXmlSchemaException("Unknown element of celldesigner:rna " + node.getNodeName()); } else {
} throw new InvalidXmlSchemaException("Unknown element of celldesigner:rna " + node.getNodeName());
} }
} }
return new Pair<String, CellDesignerRna>(identifier, rna); }
} return new Pair<String, CellDesignerRna>(identifier, rna);
}
/** /**
* Parses CellDesigner xml node for RnaRegion. * Parses CellDesigner xml node for RnaRegion.
* *
* @param residueNode * @param residueNode
* xml node to parse * xml node to parse
* @return {@link CellDesignerRnaRegion} object created from the node * @return {@link CellDesignerRnaRegion} object created from the node
* @throws InvalidXmlSchemaException * @throws InvalidXmlSchemaException
* thrown when input xml node doesn't follow defined schema * thrown when input xml node doesn't follow defined schema
*/ */
private CellDesignerRnaRegion getRnaRegion(Node residueNode) throws InvalidXmlSchemaException { private CellDesignerRnaRegion getRnaRegion(Node residueNode) throws InvalidXmlSchemaException {
CellDesignerRnaRegion residue = new CellDesignerRnaRegion(); CellDesignerRnaRegion residue = new CellDesignerRnaRegion();
residue.setIdRnaRegion(getNodeAttr("id", residueNode)); residue.setIdRnaRegion(getNodeAttr("id", residueNode));
residue.setSize(getNodeAttr("size", residueNode)); residue.setSize(getNodeAttr("size", residueNode));
residue.setPos(getNodeAttr("pos", residueNode)); residue.setPos(getNodeAttr("pos", residueNode));
residue.setType(getNodeAttr("type", residueNode)); String typeString = getNodeAttr("type", residueNode);
NodeList list = residueNode.getChildNodes(); if (typeString != null) {
for (int i = 0; i < list.getLength(); i++) { String type;
Node node = list.item(i); if (typeString.equals("CodingRegion")) {
if (node.getNodeType() == Node.ELEMENT_NODE) { type = "CODING_REGION";
throw new InvalidXmlSchemaException("Unknown element of celldesigner:region " + node.getNodeName()); } else if (typeString.equals("Modification Site")) {
} type = "MODIFICATION_SITE";
} } else if (typeString.equals("proteinBindingDomain")) {
return residue; 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);
if (node.getNodeType() == Node.ELEMENT_NODE) {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:region " + node.getNodeName());
}
}
return residue;
}
@Override @Override
public String toXml(Rna rna) { public String toXml(Rna rna) {
String attributes = ""; String attributes = "";
String result = ""; String result = "";
attributes += " id=\"r_" + elements.getElementId(rna) + "\""; attributes += " id=\"r_" + elements.getElementId(rna) + "\"";
if (!rna.getName().equals("")) { if (!rna.getName().equals("")) {
attributes += " name=\"" + escapeXml(encodeName(rna.getName())) + "\""; attributes += " name=\"" + escapeXml(encodeName(rna.getName())) + "\"";
} }
result += "<celldesigner:RNA" + attributes + ">"; result += "<celldesigner:RNA" + attributes + ">";
result += "<celldesigner:notes>"; result += "<celldesigner:notes>";
result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>"; result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>";
RestAnnotationParser rap = new RestAnnotationParser(); RestAnnotationParser rap = new RestAnnotationParser();
result += rap.createAnnotationString(rna); result += rap.createAnnotationString(rna);
result += rna.getNotes(); result += rna.getNotes();
result += "</body></html>"; result += "</body></html>";
result += "</celldesigner:notes>"; result += "</celldesigner:notes>";
result += "</celldesigner:RNA>"; result += "</celldesigner:RNA>";
return result; return result;
} }
} }
...@@ -168,7 +168,9 @@ public class CellDesignerAntisenseRnaRegion implements Serializable { ...@@ -168,7 +168,9 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
if (mr.getPos() != null) { if (mr.getPos() != null) {
this.setPos(mr.getPos()); this.setPos(mr.getPos());
} }
if (mr.getModificationType() != null) {
this.setModificationType(mr.getModificationType());
}
} }
@Override @Override
...@@ -308,7 +310,7 @@ public class CellDesignerAntisenseRnaRegion implements Serializable { ...@@ -308,7 +310,7 @@ public class CellDesignerAntisenseRnaRegion implements Serializable {
result = new ModificationSite(); result = new ModificationSite();
} else if (modificationType.equals("CODING_REGION")) { } else if (modificationType.equals("CODING_REGION")) {
result = new CodingRegion(); result = new CodingRegion();
((ProteinBindingDomain) result).setWidth(element.getWidth() * size); ((CodingRegion) result).setWidth(element.getWidth() * size);
} else if (modificationType.equals("PROTEIN_BINDING_DOMAIN")) { } else if (modificationType.equals("PROTEIN_BINDING_DOMAIN")) {
result = new ProteinBindingDomain(); result = new ProteinBindingDomain();
((ProteinBindingDomain) result).setWidth(element.getWidth() * size); ((ProteinBindingDomain) result).setWidth(element.getWidth() * size);
......
...@@ -9,9 +9,11 @@ import lcsb.mapviewer.common.exception.NotImplementedException; ...@@ -9,9 +9,11 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter; import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies;
import lcsb.mapviewer.model.map.species.Element; 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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState; import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain;
import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.model.map.species.field.Residue;
/** /**
...@@ -109,6 +111,10 @@ public class CellDesignerModificationResidue implements Serializable { ...@@ -109,6 +111,10 @@ public class CellDesignerModificationResidue implements Serializable {
this.modificationType = "RESIDUE"; this.modificationType = "RESIDUE";
} else if (mr instanceof ModificationSite) { } else if (mr instanceof ModificationSite) {
this.modificationType = "MODIFICATION_SITE"; this.modificationType = "MODIFICATION_SITE";
} else if (mr instanceof CodingRegion) {
this.modificationType = "CODING_REGION";
} else if (mr instanceof ProteinBindingDomain) {
this.modificationType = "PROTEIN_BINDING_DOMAIN";
} else { } else {
throw new InvalidArgumentException("Unknown modification type: " + mr.getClass()); throw new InvalidArgumentException("Unknown modification type: " + mr.getClass());
} }
......
...@@ -8,8 +8,11 @@ import org.apache.log4j.Logger; ...@@ -8,8 +8,11 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna;
import lcsb.mapviewer.model.map.species.Rna; 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.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 * This structure contains information about rna region (rna fragment of
...@@ -44,15 +47,7 @@ public class CellDesignerRnaRegion implements Serializable { ...@@ -44,15 +47,7 @@ public class CellDesignerRnaRegion implements Serializable {
*/ */
private String idRnaRegion = ""; private String idRnaRegion = "";
/** private String modificationType;
* 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 = "";
/** /**
* Defines a state of the region (for instance ubiquitinated etc). * Defines a state of the region (for instance ubiquitinated etc).
...@@ -89,7 +84,7 @@ public class CellDesignerRnaRegion implements Serializable { ...@@ -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 * @param mr
* original {@link CellDesignerRnaRegion} * original {@link CellDesignerRnaRegion}
...@@ -98,7 +93,7 @@ public class CellDesignerRnaRegion implements Serializable { ...@@ -98,7 +93,7 @@ public class CellDesignerRnaRegion implements Serializable {
this.idRnaRegion = mr.idRnaRegion; this.idRnaRegion = mr.idRnaRegion;
this.size = mr.size; this.size = mr.size;
setPos(mr.getPos()); setPos(mr.getPos());
this.type = mr.type; this.modificationType = mr.modificationType;
this.state = mr.state; this.state = mr.state;
this.name = mr.name; this.name = mr.name;
} }
...@@ -153,12 +148,16 @@ public class CellDesignerRnaRegion implements Serializable { ...@@ -153,12 +148,16 @@ public class CellDesignerRnaRegion implements Serializable {
if (mr.getPos() != null) { if (mr.getPos() != null) {
this.setPos(mr.getPos()); this.setPos(mr.getPos());
} }
if (mr.getModificationType() != null) {
this.setModificationType(mr.getModificationType());
}
} }
@Override @Override
public String toString() { public String toString() {
String result = "" + getIdRnaRegion() + "," + getType() + "," + getPos() + "," + getSize() + "," + getState() + ","; String result = "" + getIdRnaRegion() + "," + getModificationType() + "," + getPos() + "," + getSize() + ","
+ getState() + ",";
return result; return result;
} }
...@@ -180,23 +179,6 @@ public class CellDesignerRnaRegion implements Serializable { ...@@ -180,23 +179,6 @@ public class CellDesignerRnaRegion implements Serializable {
this.idRnaRegion = id; 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 * @return the state
* @see #state * @see #state
...@@ -287,16 +269,36 @@ public class CellDesignerRnaRegion implements Serializable { ...@@ -287,16 +269,36 @@ public class CellDesignerRnaRegion implements Serializable {
* *
* @return {@link RnaRegion} representing this object in a model * @return {@link RnaRegion} representing this object in a model
*/ */
public RnaRegion createRnaRegionAlias(Rna element) { public ModificationResidue createRnaRegionAlias(Rna element) {
RnaRegion result = new RnaRegion(); ModificationResidue result;
result.setIdRnaRegion(this.idRnaRegion); if (modificationType == null) {
result.setWidth(this.size * element.getWidth()); 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( result.setPosition(new Point2D.Double(
element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * pos, element.getY())); element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * pos, element.getY()));
result.setType(this.getType());
result.setState(this.state); result.setState(this.state);
result.setName(this.name); result.setName(this.name);
return result; 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; ...@@ -12,7 +12,6 @@ import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna; import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.ModificationResidue; 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. * Structure for storing the state of the Species in CellDesigner format.
...@@ -84,11 +83,8 @@ public class SpeciesState { ...@@ -84,11 +83,8 @@ public class SpeciesState {
setStructuralState(complex.getStructuralState()); setStructuralState(complex.getStructuralState());
} else if (species instanceof Rna) { } else if (species instanceof Rna) {
Rna rna = (Rna) species; Rna rna = (Rna) species;
for (RnaRegion region : rna.getRegions()) { for (ModificationResidue region : rna.getRegions()) {
CellDesignerModificationResidue mr = new CellDesignerModificationResidue(); CellDesignerModificationResidue mr = new CellDesignerModificationResidue(region);
mr.setIdModificationResidue(region.getIdRnaRegion());
mr.setSize(region.getWidth() / (rna.getWidth() * 3.0 / 4.0));
mr.setState(region.getState());
addModificationResidue(mr); addModificationResidue(mr);
} }
} else if (species instanceof Gene) { } else if (species instanceof Gene) {
......
...@@ -16,8 +16,8 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner ...@@ -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.converter.model.celldesigner.structure.fields.SpeciesState;
import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Rna; 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.ModificationSite;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
public class SpeciesStateTest { public class SpeciesStateTest {
...@@ -52,7 +52,11 @@ public class SpeciesStateTest { ...@@ -52,7 +52,11 @@ public class SpeciesStateTest {
@Test @Test
public void testConstructorFromRna() { public void testConstructorFromRna() {
Rna rna = new Rna("1"); Rna rna = new Rna("1");
rna.addRegion(new RnaRegion()); rna.setWidth(60);