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
*
......@@ -22,105 +23,118 @@ import lcsb.mapviewer.model.map.species.Rna;
public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(RnaXmlParser.class.getName());
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(RnaXmlParser.class.getName());
/**
* Collection of {@link CellDesignerElement cell designer elements} parsed
* from xml.
*/
private CellDesignerElementCollection elements;
/**
* Collection of {@link CellDesignerElement cell designer elements} parsed from
* xml.
*/
private CellDesignerElementCollection elements;
/**
* Default constructor. Model is required because some nodes require access to
* other parts of the model.
*
* @param elements
* collection of {@link CellDesignerElement cell designer elements}
* parsed from xml
*/
public RnaXmlParser(CellDesignerElementCollection elements) {
this.elements = elements;
}
/**
* Default constructor. Model is required because some nodes require access to
* other parts of the model.
*
* @param elements
* collection of {@link CellDesignerElement cell designer elements}
* parsed from xml
*/
public RnaXmlParser(CellDesignerElementCollection elements) {
this.elements = elements;
}
@Override
public Pair<String, CellDesignerRna> parseXmlElement(Node rnaNode) throws InvalidXmlSchemaException {
CellDesignerRna rna = new CellDesignerRna();
String identifier = getNodeAttr("id", rnaNode);
rna.setName(decodeName(getNodeAttr("name", rnaNode)));
NodeList list = rnaNode.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")) {
rna.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")) {
rna.addRegion(getRnaRegion(residueNode));
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
}
}
}
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:rna " + node.getNodeName());
}
}
}
return new Pair<String, CellDesignerRna>(identifier, rna);
}
@Override
public Pair<String, CellDesignerRna> parseXmlElement(Node rnaNode) throws InvalidXmlSchemaException {
CellDesignerRna rna = new CellDesignerRna();
String identifier = getNodeAttr("id", rnaNode);
rna.setName(decodeName(getNodeAttr("name", rnaNode)));
NodeList list = rnaNode.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")) {
rna.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")) {
rna.addRegion(getRnaRegion(residueNode));
} else {
throw new InvalidXmlSchemaException(
"Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
}
}
}
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:rna " + node.getNodeName());
}
}
}
return new Pair<String, CellDesignerRna>(identifier, rna);
}
/**
* Parses CellDesigner xml node for RnaRegion.
*
* @param residueNode
* xml node to parse
* @return {@link CellDesignerRnaRegion} object created from the node
* @throws InvalidXmlSchemaException
* thrown when input xml node doesn't follow defined schema
*/
private CellDesignerRnaRegion getRnaRegion(Node residueNode) throws InvalidXmlSchemaException {
CellDesignerRnaRegion residue = new CellDesignerRnaRegion();
residue.setIdRnaRegion(getNodeAttr("id", residueNode));
residue.setSize(getNodeAttr("size", residueNode));
residue.setPos(getNodeAttr("pos", residueNode));
residue.setType(getNodeAttr("type", residueNode));
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;
}
/**
* Parses CellDesigner xml node for RnaRegion.
*
* @param residueNode
* xml node to parse
* @return {@link CellDesignerRnaRegion} object created from the node
* @throws InvalidXmlSchemaException
* thrown when input xml node doesn't follow defined schema
*/
private CellDesignerRnaRegion getRnaRegion(Node residueNode) throws InvalidXmlSchemaException {
CellDesignerRnaRegion residue = new CellDesignerRnaRegion();
residue.setIdRnaRegion(getNodeAttr("id", residueNode));
residue.setSize(getNodeAttr("size", residueNode));
residue.setPos(getNodeAttr("pos", 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);
if (node.getNodeType() == Node.ELEMENT_NODE) {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:region " + node.getNodeName());
}
}
return residue;
}
@Override
public String toXml(Rna rna) {
String attributes = "";
String result = "";
attributes += " id=\"r_" + elements.getElementId(rna) + "\"";
if (!rna.getName().equals("")) {
attributes += " name=\"" + escapeXml(encodeName(rna.getName())) + "\"";
}
result += "<celldesigner:RNA" + attributes + ">";
result += "<celldesigner:notes>";
result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>";
RestAnnotationParser rap = new RestAnnotationParser();
result += rap.createAnnotationString(rna);
result += rna.getNotes();
result += "</body></html>";
result += "</celldesigner:notes>";
@Override
public String toXml(Rna rna) {
String attributes = "";
String result = "";
attributes += " id=\"r_" + elements.getElementId(rna) + "\"";
if (!rna.getName().equals("")) {
attributes += " name=\"" + escapeXml(encodeName(rna.getName())) + "\"";
}
result += "<celldesigner:RNA" + attributes + ">";
result += "<celldesigner:notes>";
result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>";
RestAnnotationParser rap = new RestAnnotationParser();
result += rap.createAnnotationString(rna);
result += rna.getNotes();
result += "</body></html>";
result += "</celldesigner:notes>";
result += "</celldesigner:RNA>";
return result;
}
result += "</celldesigner:RNA>";
return result;
}
}
......@@ -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());
}
......
package lcsb.mapviewer.converter.model.sbgnml;
import static org.junit.Assert.assertEquals;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.persist.DbUtils;
import lcsb.mapviewer.persist.dao.map.ModelDao;
@Transactional(value = "txManager")
@ContextConfiguration(locations = { "/applicationContext-persist.xml", //
"/test-applicationContext.xml",//
"/dataSource.xml", //
})
@RunWith(SpringJUnit4ClassRunner.class)
public class DbSerializationTest {
@Autowired
ModelDao modelDao;
@Autowired
DbUtils dbUtils;
Logger logger = Logger.getLogger(DbSerializationTest.class.getName());
private void makeDbSerializationTest(String filePath) throws Exception {
SbgnmlXmlParser parser = new SbgnmlXmlParser();
Model model = parser.createModel(new ConverterParams().filename("testFiles/sbgnmlParserTestFiles/sbgnmlFiles/".concat(filePath)));
modelDao.add(model);
modelDao.flush();
modelDao.commit();
modelDao.evict(model);
Model model2 = new ModelFullIndexed(modelDao.getById(model.getId()));
ModelComparator comparator = new ModelComparator();
assertEquals(0, comparator.compare(model, model2));
modelDao.delete(model2);
}
@Before
public void setUp() throws Exception {
// we use custom threads because in layoutservice there is commit method
// called, and because of that hibernate session injected by spring
// cannot
// commit at the end of the test case
dbUtils.createSessionForCurrentThread();
}
@After
public void tearDown() throws Exception {
// close session
dbUtils.closeSessionForCurrentThread();
}
@Test
public void VANTEDdiagramTest() throws Exception {
makeDbSerializationTest("VANTEDdiagram.sbgn");
}
@Test
public void activatedStat1AlphaTest() throws Exception {
makeDbSerializationTest("activated_stat1alpha_induction_of_the_irf1_gene.sbgn");
}
@Test
public void adhTest() throws Exception {
makeDbSerializationTest("adh.sbgn");
}
@Test
public void cloneMarkerTest() throws Exception {