Commit 14a66f69 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

ModificationSite and Residue classes extracted

parent 29a98a2a
......@@ -6,14 +6,17 @@ import org.w3c.dom.NodeList;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerGene;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
/**
* Class that performs parsing of the CellDesigner xml for
......@@ -89,12 +92,18 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
* @throws InvalidXmlSchemaException
* thrown when input xml node doesn't follow defined schema
*/
CellDesignerModificationResidue getModificationResidue(Node residueNode) throws InvalidXmlSchemaException {
CellDesignerModificationResidue residue = new CellDesignerModificationResidue();
CellDesignerGeneRegion getModificationResidue(Node residueNode) throws InvalidXmlSchemaException {
CellDesignerGeneRegion residue = new CellDesignerGeneRegion();
residue.setIdModificationResidue(getNodeAttr("id", residueNode));
residue.setName(getNodeAttr("name", residueNode));
residue.setSide(getNodeAttr("side", residueNode));
residue.setAngle(getNodeAttr("pos", residueNode));
String type = getNodeAttr("type", residueNode);
if (type.equals("Modification Site")) {
residue.setModificationType("MODIFICATION_SITE");
} else if (!type.equals("")) {
throw new NotImplementedException("Unknown type: " + type);
}
NodeList list = residueNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
......@@ -152,6 +161,9 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
if (!mr.getName().equals("")) {
attributes += " name=\"" + escapeXml(mr.getName()) + "\"";
}
if (mr instanceof ModificationSite) {
attributes += " type=\"Modification Site\"";
}
attributes += " pos=\"" + converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()) + "\"";
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>\n";
......
......@@ -161,6 +161,7 @@ public class ProteinXmlParser extends AbstractElementXmlParser<CellDesignerProte
residue.setName(getNodeAttr("name", residueNode));
residue.setSide(getNodeAttr("side", residueNode));
residue.setAngle(getNodeAttr("angle", residueNode));
residue.setModificationType("RESIDUE");
NodeList list = residueNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
......
......@@ -21,6 +21,7 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSimpleMolecule;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerSpecies;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerRnaRegion;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState;
......@@ -211,7 +212,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
attributesBuilder.append(" constant=\"" + species.getConstant().toString().toLowerCase() + "\"");
}
if (species.getBoundaryCondition() != null) {
attributesBuilder.append(" boundaryCondition=\"" + species.getBoundaryCondition().toString().toLowerCase() + "\"");
attributesBuilder
.append(" boundaryCondition=\"" + species.getBoundaryCondition().toString().toLowerCase() + "\"");
}
Compartment comp = null;
......@@ -444,7 +446,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
throw new NotImplementedException("StructuralState not supported in Gene");
}
for (CellDesignerModificationResidue mr : state.getModifications()) {
gene.addModificationResidue(mr);
gene.addModificationResidue(createGeneRegion(mr));
}
} else if (species instanceof CellDesignerProtein) {
CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species;
......@@ -490,6 +492,23 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
}
private CellDesignerGeneRegion createGeneRegion(CellDesignerModificationResidue mr) {
CellDesignerGeneRegion region = new CellDesignerGeneRegion();
region.setIdModificationResidue(mr.getIdModificationResidue());
if (mr.getSize() != null) {
region.setSize(mr.getSize());
}
region.setState(mr.getState());
region.setName(mr.getName());
if (mr.getAngle() != null) {
region.setAngle(mr.getAngle());
}
if (mr.getModificationType() != null) {
region.setModificationType(mr.getModificationType());
}
return region;
}
/**
* Creates {@link SpeciesState} from xml node.
*
......@@ -549,7 +568,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
}
/**
* Creates {@link CellDesignerModificationResidue} from the apropriate xml node.
* Creates {@link CellDesignerModificationResidue} from the appropriate xml
* node.
*
* @param rootNode
* xml node
......@@ -632,7 +652,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
*
* @param mr
* object from which we create {@link CellDesignerRnaRegion}
* @return {@link CellDesignerRnaRegion} object created from param
* @return {@link CellDesignerRnaRegion} object created from parameter
*/
public CellDesignerRnaRegion createRnaRegion(CellDesignerModificationResidue mr) {
CellDesignerRnaRegion result = new CellDesignerRnaRegion();
......
......@@ -4,9 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerGeneRegion;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Species;
......@@ -26,7 +25,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
/**
* List of modifications for the Gene.
*/
private List<CellDesignerModificationResidue> modificationResidues = new ArrayList<>();
private List<CellDesignerGeneRegion> modificationResidues = new ArrayList<>();
/**
* Constructor that initializes gene with the data passed in the argument.
......@@ -38,8 +37,8 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
super(species);
if (species instanceof CellDesignerGene) {
CellDesignerGene gene = (CellDesignerGene) species;
for (CellDesignerModificationResidue mr : gene.getModificationResidues()) {
addModificationResidue(new CellDesignerModificationResidue(mr));
for (CellDesignerGeneRegion mr : gene.getModificationResidues()) {
addModificationResidue(new CellDesignerGeneRegion(mr));
}
}
}
......@@ -50,7 +49,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
if (species instanceof CellDesignerGene) {
CellDesignerGene gene = (CellDesignerGene) species;
for (CellDesignerModificationResidue mr : gene.getModificationResidues()) {
for (CellDesignerGeneRegion mr : gene.getModificationResidues()) {
addModificationResidue(mr);
}
}
......@@ -76,10 +75,10 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
* Adds modification to the gene.
*
* @param modificationResidue
* modifiaction to add
* modification to add
*/
public void addModificationResidue(CellDesignerModificationResidue modificationResidue) {
for (CellDesignerModificationResidue mr : modificationResidues) {
public void addModificationResidue(CellDesignerGeneRegion modificationResidue) {
for (CellDesignerGeneRegion mr : modificationResidues) {
if (mr.getIdModificationResidue().equals(modificationResidue.getIdModificationResidue())) {
mr.update(modificationResidue);
return;
......@@ -94,7 +93,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
* @return the modificationResidues
* @see #modificationResidues
*/
public List<CellDesignerModificationResidue> getModificationResidues() {
public List<CellDesignerGeneRegion> getModificationResidues() {
return modificationResidues;
}
......@@ -103,7 +102,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
* the modificationResidues to set
* @see #modificationResidues
*/
public void setModificationResidues(List<CellDesignerModificationResidue> modificationResidues) {
public void setModificationResidues(List<CellDesignerGeneRegion> modificationResidues) {
this.modificationResidues = modificationResidues;
}
......@@ -116,8 +115,8 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
@Override
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerModificationResidue region : modificationResidues) {
((Gene) element).addModificationResidue(region.createModificationResidueAlias(element));
for (CellDesignerGeneRegion region : modificationResidues) {
((Gene) element).addModificationResidue(region.createGeneModification(element));
}
}
......
......@@ -152,7 +152,7 @@ public class CellDesignerProtein<T extends Protein> extends CellDesignerSpecies<
@Override
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerModificationResidue mr : modificationResidues) {
((Protein) element).addModificationResidue(mr.createModificationResidueAlias(element));
((Protein) element).addModificationResidue(mr.createProteinModification(element));
}
}
......
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.io.Serializable;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState;
/**
* This class represent modification residue in protein and gene. However, it is
* sometimes also used for storing information about AntisenseRna/Rna regions...
* (due to CellDesigner xml strange structure).
*
* @author Piotr Gawron
*
*/
public class CellDesignerGeneRegion implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(CellDesignerGeneRegion.class.getName());
/**
* Identifier of the modification. Must be unique in single map model.
*/
private String idModificationResidue = "";
/**
* Name of the modification.
*/
private String name = "";
private String modificationType;
/**
* Some strange parameter in CellDesigner. No idea what is it for.
*/
private String side = "";
/**
* State in which this modification is.
*/
private ModificationState state = null;
/**
* Where this modification is located (on which side of the border).
*/
private Double angle = null;
/**
* How big is this modification (used only for some types of the modification).
*/
private Double size = null;
/**
* Species to which this modification belong to.
*/
private CellDesignerSpecies<?> species;
/**
* Default constructor.
*/
public CellDesignerGeneRegion() {
}
/**
* Constructor that initialize object with the data taken from the parameter.
*
* @param mr
* original object from which data is taken
*/
public CellDesignerGeneRegion(CellDesignerGeneRegion mr) {
this.idModificationResidue = mr.idModificationResidue;
this.name = mr.name;
this.angle = mr.angle;
this.size = mr.size;
this.side = mr.side;
this.state = mr.state;
this.modificationType = mr.getModificationType();
logger.debug(this);
}
/**
* Constructor that creates object from model representation of modification.
*
* @param mr
* model representation of {@link ModificationResidue}
*/
public CellDesignerGeneRegion(ModificationResidue mr) {
CellDesignerAliasConverter converter = new CellDesignerAliasConverter(mr.getSpecies(), false);
this.setIdModificationResidue(mr.getIdModificationResidue());
this.name = mr.getName();
this.angle = converter.getAngleForPoint(mr.getSpecies(), mr.getPosition());
this.state = mr.getState();
if (mr instanceof ModificationSite) {
this.setModificationType("MODIFICATION_SITE");
} else {
throw new InvalidArgumentException("Unknown gene modification: " + mr.getClass());
}
logger.debug(this);
}
/**
* Default constructor.
*
* @param id
* identifier of the modification residue
*/
public CellDesignerGeneRegion(String id) {
this.idModificationResidue = id;
}
/**
* Updates fields in the object with the data given in the parameter
* modification.
*
* @param mr
* modification residue from which data will be used to update
*/
public void update(CellDesignerGeneRegion mr) {
if (mr.getName() != null && !mr.getName().equals("")) {
this.name = mr.name;
}
if (mr.getAngle() != null) {
this.angle = mr.angle;
}
if (mr.getSize() != null) {
this.size = mr.size;
}
if (mr.getSide() != null && !mr.getSide().equals("")) {
this.side = mr.side;
}
if (mr.getState() != null) {
this.state = mr.state;
}
if (mr.getModificationType() != null) {
this.setModificationType(mr.modificationType);
}
}
@Override
public String toString() {
String result = getIdModificationResidue() + "," + getName() + "," + getState() + "," + getAngle() + "," + getSize()
+ "," + getSide() + "," + getModificationType();
return result;
}
/**
* Creates copy of the object.
*
* @return copy of the object.
*/
public CellDesignerGeneRegion copy() {
if (this.getClass() == CellDesignerGeneRegion.class) {
return new CellDesignerGeneRegion(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
/**
* Sets {@link #angle} .
*
* @param text
* angle in text format
*/
public void setAngle(String text) {
try {
if (text != null && !text.equals("")) {
angle = Double.parseDouble(text);
} else {
angle = null;
}
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid angle: " + text, e);
}
}
/**
* Sets {@link #size}.
*
* @param text
* size in text format.
*/
public void setSize(String text) {
try {
if (text != null && !text.equals("")) {
size = Double.parseDouble(text);
} else {
size = null;
}
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid size: " + text, e);
}
}
/**
* @return the id
* @see #idModificationResidue
*/
public String getIdModificationResidue() {
return idModificationResidue;
}
/**
* @param idModificationResidue
* the id to set
* @see #idModificationResidue
*/
public void setIdModificationResidue(String idModificationResidue) {
this.idModificationResidue = idModificationResidue;
}
/**
* @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 side
* @see #side
*/
public String getSide() {
return side;
}
/**
* @param side
* the side to set
* @see #side
*/
public void setSide(String side) {
this.side = side;
}
/**
* @return the state
* @see #state
*/
public ModificationState getState() {
return state;
}
/**
* @param state
* the state to set
* @see #state
*/
public void setState(ModificationState state) {
this.state = state;
}
/**
* @return the angle
* @see #angle
*/
public Double getAngle() {
return angle;
}
/**
* @param angle
* the angle to set
* @see #angle
*/
public void setAngle(Double angle) {
this.angle = angle;
}
/**
* @return the size
* @see #size
*/
public Double getSize() {
return size;
}
/**
* @param size
* the size to set
* @see #size
*/
public void setSize(Double size) {
this.size = size;
}
/**
* @return the species
* @see #species
*/
public CellDesignerSpecies<?> getSpecies() {
return species;
}
/**
* @param species
* the species to set
* @see #species
*/
public void setSpecies(CellDesignerSpecies<?> species) {
this.species = species;
}
/**
* Creates model representation of {@link ModificationResidue}.
*
* @return {@link ModificationResidue} representing this object in a model
*/
public ModificationResidue createGeneModification(Element element) {
CellDesignerAliasConverter converter = new CellDesignerAliasConverter(element, false);