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

BindingRegion data model is supported

parent 994a828e
...@@ -15,8 +15,10 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerGene; ...@@ -15,8 +15,10 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerGene;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType;
import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.Gene;
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.RegulatoryRegion;
/** /**
* Class that performs parsing of the CellDesigner xml for * Class that performs parsing of the CellDesigner xml for
...@@ -97,6 +99,8 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge ...@@ -97,6 +99,8 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
residue.setIdModificationResidue(getNodeAttr("id", residueNode)); residue.setIdModificationResidue(getNodeAttr("id", residueNode));
residue.setName(getNodeAttr("name", residueNode)); residue.setName(getNodeAttr("name", residueNode));
residue.setSide(getNodeAttr("side", residueNode)); residue.setSide(getNodeAttr("side", residueNode));
residue.setSize(getNodeAttr("size", residueNode));
residue.setActive(getNodeAttr("active", residueNode));
residue.setAngle(getNodeAttr("pos", residueNode)); residue.setAngle(getNodeAttr("pos", residueNode));
String type = getNodeAttr("type", residueNode); String type = getNodeAttr("type", residueNode);
try { try {
...@@ -161,9 +165,19 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge ...@@ -161,9 +165,19 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
if (!mr.getName().equals("")) { if (!mr.getName().equals("")) {
attributes += " name=\"" + escapeXml(mr.getName()) + "\""; attributes += " name=\"" + escapeXml(mr.getName()) + "\"";
} }
String type = null;
if (mr instanceof ModificationSite) { if (mr instanceof ModificationSite) {
attributes += " type=\"Modification Site\""; type = ModificationType.MODIFICATION_SITE.getCellDesignerName();
} else if (mr instanceof RegulatoryRegion) {
type = ModificationType.REGULATORY_REGION.getCellDesignerName();
attributes += " size=\"" + ((RegulatoryRegion) mr).getWidth() / mr.getSpecies().getWidth() + "\"";
} else if (mr instanceof CodingRegion) {
type = ModificationType.CODING_REGION.getCellDesignerName();
attributes += " size=\"" + ((RegulatoryRegion) mr).getWidth() / mr.getSpecies().getWidth() + "\"";
} else {
throw new InvalidArgumentException("Don't know how to handle: " + mr.getClass());
} }
attributes += " type=\"" + type + "\"";
attributes += " pos=\"" + converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()) + "\""; attributes += " pos=\"" + converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()) + "\"";
result += "<celldesigner:region " + attributes + ">"; result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>\n"; result += "</celldesigner:region>\n";
......
...@@ -16,6 +16,7 @@ import lcsb.mapviewer.model.map.species.field.ModificationResidue; ...@@ -16,6 +16,7 @@ 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.ProteinBindingDomain;
import lcsb.mapviewer.model.map.species.field.RegulatoryRegion;
import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.model.map.species.field.Residue;
/** /**
...@@ -46,6 +47,8 @@ public class CellDesignerModificationResidue implements Serializable { ...@@ -46,6 +47,8 @@ public class CellDesignerModificationResidue implements Serializable {
*/ */
private String name = ""; private String name = "";
private Boolean active = null;
private ModificationType modificationType; private ModificationType modificationType;
/** /**
...@@ -125,16 +128,20 @@ public class CellDesignerModificationResidue implements Serializable { ...@@ -125,16 +128,20 @@ public class CellDesignerModificationResidue implements Serializable {
} else if (mr instanceof ProteinBindingDomain) { } else if (mr instanceof ProteinBindingDomain) {
this.size = ((CodingRegion) mr).getWidth() / mr.getSpecies().getWidth(); this.size = ((CodingRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.modificationType = ModificationType.PROTEIN_BINDING_DOMAIN; this.modificationType = ModificationType.PROTEIN_BINDING_DOMAIN;
} else if (mr instanceof RegulatoryRegion) {
this.size = ((RegulatoryRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.modificationType = ModificationType.REGULATORY_REGION;
} else if (mr instanceof BindingRegion) { } else if (mr instanceof BindingRegion) {
this.modificationType = ModificationType.BINDING_REGION; this.modificationType = ModificationType.BINDING_REGION;
if (Math.abs(mr.getPosition().getX() - mr.getSpecies().getX()) < Configuration.EPSILON) { if (Math.abs(mr.getPosition().getX() - mr.getSpecies().getX()) < Configuration.EPSILON) {
this.size = ((BindingRegion) mr).getHeight() / mr.getSpecies().getHeight(); this.size = ((BindingRegion) mr).getHeight() / mr.getSpecies().getHeight();
} else if (Math.abs(mr.getPosition().getX() - mr.getSpecies().getX() - mr.getSpecies().getWidth()) < Configuration.EPSILON) { } else if (Math
.abs(mr.getPosition().getX() - mr.getSpecies().getX() - mr.getSpecies().getWidth()) < Configuration.EPSILON) {
this.size = ((BindingRegion) mr).getHeight() / mr.getSpecies().getHeight(); this.size = ((BindingRegion) mr).getHeight() / mr.getSpecies().getHeight();
} else { } else {
this.size = ((BindingRegion) mr).getWidth() / mr.getSpecies().getWidth(); this.size = ((BindingRegion) mr).getWidth() / mr.getSpecies().getWidth();
} }
} else { } else {
throw new InvalidArgumentException("Unknown modification type: " + mr.getClass()); throw new InvalidArgumentException("Unknown modification type: " + mr.getClass());
} }
...@@ -377,6 +384,8 @@ public class CellDesignerModificationResidue implements Serializable { ...@@ -377,6 +384,8 @@ public class CellDesignerModificationResidue implements Serializable {
return createCodingRegion(element, converter); return createCodingRegion(element, converter);
} else if (modificationType.equals(ModificationType.PROTEIN_BINDING_DOMAIN)) { } else if (modificationType.equals(ModificationType.PROTEIN_BINDING_DOMAIN)) {
return createProteinBindingDomain(element, converter); return createProteinBindingDomain(element, converter);
} else if (modificationType.equals(ModificationType.REGULATORY_REGION)) {
return createRegulatoryRegion(element, converter);
} else { } else {
throw new InvalidArgumentException("Unknown modification type: " + modificationType); throw new InvalidArgumentException("Unknown modification type: " + modificationType);
} }
...@@ -416,6 +425,15 @@ public class CellDesignerModificationResidue implements Serializable { ...@@ -416,6 +425,15 @@ public class CellDesignerModificationResidue implements Serializable {
return result; return result;
} }
private RegulatoryRegion createRegulatoryRegion(Element element, CellDesignerAliasConverter converter) {
RegulatoryRegion result = new RegulatoryRegion();
result.setWidth(element.getWidth() * size);
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, angle));
return result;
}
private ModificationSite createModificationSite(Element element, CellDesignerAliasConverter converter) { private ModificationSite createModificationSite(Element element, CellDesignerAliasConverter converter) {
ModificationSite result = new ModificationSite(); ModificationSite result = new ModificationSite();
result.setState(this.getState()); result.setState(this.getState());
...@@ -482,4 +500,20 @@ public class CellDesignerModificationResidue implements Serializable { ...@@ -482,4 +500,20 @@ public class CellDesignerModificationResidue implements Serializable {
this.pos = pos; this.pos = pos;
} }
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public void setActive(String text) {
if (text == null) {
this.active = null;
} else {
this.active = "true".equalsIgnoreCase(text);
}
}
} }
...@@ -7,6 +7,7 @@ public enum ModificationType { ...@@ -7,6 +7,7 @@ public enum ModificationType {
CODING_REGION("CodingRegion"), // CODING_REGION("CodingRegion"), //
PROTEIN_BINDING_DOMAIN("proteinBindingDomain"), // PROTEIN_BINDING_DOMAIN("proteinBindingDomain"), //
RESIDUE(null), // RESIDUE(null), //
REGULATORY_REGION("RegulatoryRegion"), //
MODIFICATION_SITE("Modification Site");// MODIFICATION_SITE("Modification Site");//
private String cellDesignerName; private String cellDesignerName;
......
...@@ -52,6 +52,7 @@ import lcsb.mapviewer.model.map.species.SimpleMolecule; ...@@ -52,6 +52,7 @@ import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.BindingRegion; import lcsb.mapviewer.model.map.species.field.BindingRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RegulatoryRegion;
public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
Logger logger = Logger.getLogger(CellDesignerXmlParserTest.class); Logger logger = Logger.getLogger(CellDesignerXmlParserTest.class);
...@@ -1019,7 +1020,33 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { ...@@ -1019,7 +1020,33 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
String xml = parser.toXml(model); String xml = parser.toXml(model);
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8")); InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
Model model2 = parser.createModel(new ConverterParams().inputStream(is)); Model model2 = parser.createModel(new ConverterParams().inputStream(is));
model.setName(null);
ModelComparator comparator = new ModelComparator();
assertEquals(0, comparator.compare(model, model2));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testRegulatoryRegion() throws Exception {
try {
CellDesignerXmlParser parser = new CellDesignerXmlParser();
Model model = parser.createModel(new ConverterParams().filename("testFiles/gene_with_regulatory_region.xml"));
Gene gene = model.getElementByElementId("sa1");
assertEquals(1, gene.getModificationResidues().size());
ModificationResidue residue = gene.getModificationResidues().get(0);
assertTrue(residue instanceof RegulatoryRegion);
RegulatoryRegion bindingRegion = (RegulatoryRegion) residue;
assertEquals(bindingRegion.getPosition().getY(), gene.getY(), Configuration.EPSILON);
assertTrue(bindingRegion.getWidth() > bindingRegion.getHeight());
String xml = parser.toXml(model);
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
Model model2 = parser.createModel(new ConverterParams().inputStream(is));
model.setName(null); model.setName(null);
ModelComparator comparator = new ModelComparator(); ModelComparator comparator = new ModelComparator();
assertEquals(0, comparator.compare(model, model2)); assertEquals(0, comparator.compare(model, model2));
......
...@@ -151,12 +151,12 @@ public class GeneXmlParserTest extends CellDesignerTestFunctions { ...@@ -151,12 +151,12 @@ public class GeneXmlParserTest extends CellDesignerTestFunctions {
@Test @Test
public void testModificationResidueToXml() throws Exception { public void testModificationResidueToXml() throws Exception {
try { try {
Protein protein = new GenericProtein("id"); Gene protein = new Gene("id");
protein.setX(10); protein.setX(10);
protein.setY(10); protein.setY(10);
protein.setWidth(10); protein.setWidth(10);
protein.setHeight(10); protein.setHeight(10);
Residue mr = new Residue(); ModificationSite mr = new ModificationSite();
mr.setIdModificationResidue("i"); mr.setIdModificationResidue("i");
mr.setName("a"); mr.setName("a");
mr.setPosition(new Point2D.Double(3.0, 2.0)); mr.setPosition(new Point2D.Double(3.0, 2.0));
......
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
<model metaid="untitled" id="untitled">
<annotation>
<celldesigner:extension>
<celldesigner:modelVersion>4.0</celldesigner:modelVersion>
<celldesigner:modelDisplay sizeX="600" sizeY="400"/>
<celldesigner:listOfCompartmentAliases/>
<celldesigner:listOfComplexSpeciesAliases/>
<celldesigner:listOfSpeciesAliases>
<celldesigner:speciesAlias id="sa1" species="s1">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="224.0" y="259.5" w="70.0" h="25.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="70.0" height="25.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffffff66" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
</celldesigner:listOfSpeciesAliases>
<celldesigner:listOfGroups/>
<celldesigner:listOfProteins/>
<celldesigner:listOfGenes>
<celldesigner:gene id="gn1" name="s1" type="GENE">
<celldesigner:listOfRegions>
<celldesigner:region id="tr1" name="xx" size="0.78" pos="0.0" type="RegulatoryRegion" active="false"/>
</celldesigner:listOfRegions>
</celldesigner:gene>
</celldesigner:listOfGenes>
<celldesigner:listOfRNAs/>
<celldesigner:listOfAntisenseRNAs/>
<celldesigner:listOfLayers/>
<celldesigner:listOfBlockDiagrams/>
</celldesigner:extension>
</annotation>
<listOfUnitDefinitions>
<unitDefinition metaid="substance" id="substance" name="substance">
<listOfUnits>
<unit metaid="CDMT00001" kind="mole"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="volume" id="volume" name="volume">
<listOfUnits>
<unit metaid="CDMT00002" kind="litre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="area" id="area" name="area">
<listOfUnits>
<unit metaid="CDMT00003" kind="metre" exponent="2"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="length" id="length" name="length">
<listOfUnits>
<unit metaid="CDMT00004" kind="metre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="time" id="time" name="time">
<listOfUnits>
<unit metaid="CDMT00005" kind="second"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>
<listOfCompartments>
<compartment metaid="default" id="default" size="1" units="volume"/>
</listOfCompartments>
<listOfSpecies>
<species metaid="s1" id="s1" name="s1" compartment="default" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>GENE</celldesigner:class>
<celldesigner:geneReference>gn1</celldesigner:geneReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
</listOfSpecies>
</model>
</sbml>
...@@ -8,18 +8,14 @@ import javax.persistence.Entity; ...@@ -8,18 +8,14 @@ import javax.persistence.Entity;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.species.AntisenseRna; import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
/** /**
* This structure contains information about Coding Region for one of the * This structure contains information about Binding Region for one of the
* following {@link Species}: * following {@link Species}:
* <ul> * <ul>
* <li>{@link Rna}</li> * <li>{@link Protein}</li>
* <li>{@link AntisenseRna}</li>
* <li>{@link Gene}</li>
* </ul> * </ul>
* *
* @author Piotr Gawron * @author Piotr Gawron
......
package lcsb.mapviewer.model.map.species.field;
import java.io.Serializable;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Species;
/**
* This structure contains information about Regulatory Region for one of the
* following {@link Species}:
* <ul>
* <li>{@link Gene}</li>
* </ul>
*
* @author Piotr Gawron
*
*/
@Entity
@DiscriminatorValue("MODIFICATION_SITE")
public class RegulatoryRegion extends AbstractRegionModification implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(RegulatoryRegion.class);
/**
* Default constructor.
*/
public RegulatoryRegion() {
}
/**
* Constructor that initialize object with the data from the parameter.
*
* @param original
* object from which we initialize data
*/
public RegulatoryRegion(RegulatoryRegion original) {
super(original);
}
/**
* Creates a copy of current object.
*
* @return copy of the object
*/
public RegulatoryRegion copy() {
if (this.getClass() == RegulatoryRegion.class) {
return new RegulatoryRegion(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment