Commit 2f93cf65 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

ModificationType enum extracted

parent ba1088ea
......@@ -12,6 +12,7 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationPars
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerAntisenseRna;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
......@@ -174,16 +175,11 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
residue.setPos(getNodeAttr("pos", regionNode));
String typeString = getNodeAttr("type", regionNode);
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);
try {
residue.setModificationType(ModificationType.getByCellDesignerName(typeString));
} catch (InvalidArgumentException e) {
throw new InvalidXmlSchemaException(e);
}
}
NodeList list = regionNode.getChildNodes();
......
......@@ -5,14 +5,15 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
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.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
......@@ -98,10 +99,10 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
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);
try {
residue.setModificationType(ModificationType.getByCellDesignerName(type));
} catch (InvalidArgumentException e) {
throw new InvalidXmlSchemaException(e);
}
NodeList list = residueNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
......
......@@ -12,6 +12,7 @@ import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasCon
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerProtein;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
......@@ -161,7 +162,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");
residue.setModificationType(ModificationType.RESIDUE);
NodeList list = residueNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
......
......@@ -11,6 +11,7 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationPars
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType;
import lcsb.mapviewer.model.map.species.Rna;
/**
......@@ -95,16 +96,7 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna>
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);
residue.setModificationType(ModificationType.getByCellDesignerName(typeString));
}
NodeList list = residueNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
......
......@@ -44,7 +44,7 @@ public class CellDesignerModificationResidue implements Serializable {
*/
private String name = "";
private String modificationType;
private ModificationType modificationType;
/**
* Position on the species in graphic representation.
......@@ -110,16 +110,19 @@ public class CellDesignerModificationResidue implements Serializable {
this.idModificationResidue = mr.getIdModificationResidue();
this.name = mr.getName();
this.angle = converter.getAngleForPoint(mr.getSpecies(), mr.getPosition());
this.pos = this.angle;
if (mr instanceof Residue) {
this.modificationType = "RESIDUE";
this.modificationType = ModificationType.RESIDUE;
this.state = ((Residue) mr).getState();
} else if (mr instanceof ModificationSite) {
this.modificationType = "MODIFICATION_SITE";
this.modificationType = ModificationType.MODIFICATION_SITE;
this.state = ((ModificationSite) mr).getState();
} else if (mr instanceof CodingRegion) {
this.modificationType = "CODING_REGION";
this.size = ((CodingRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.modificationType = ModificationType.CODING_REGION;
} else if (mr instanceof ProteinBindingDomain) {
this.modificationType = "PROTEIN_BINDING_DOMAIN";
this.size = ((CodingRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.modificationType = ModificationType.PROTEIN_BINDING_DOMAIN;
} else {
throw new InvalidArgumentException("Unknown modification type: " + mr.getClass());
}
......@@ -352,13 +355,13 @@ public class CellDesignerModificationResidue implements Serializable {
if (modificationType == null) {
throw new InvalidArgumentException("No type information for modification: " + idModificationResidue);
} else if (modificationType.equals("RESIDUE")) {
} else if (modificationType.equals(ModificationType.RESIDUE)) {
return createResidue(element, converter);
} else if (modificationType.equals("MODIFICATION_SITE")) {
} else if (modificationType.equals(ModificationType.MODIFICATION_SITE)) {
return createModificationSite(element, converter);
} else if (modificationType.equals("CODING_REGION")) {
} else if (modificationType.equals(ModificationType.CODING_REGION)) {
return createCodingRegion(element, converter);
} else if (modificationType.equals("PROTEIN_BINDING_DOMAIN")) {
} else if (modificationType.equals(ModificationType.PROTEIN_BINDING_DOMAIN)) {
return createProteinBindingDomain(element, converter);
} else {
throw new InvalidArgumentException("Unknown modification type: " + modificationType);
......@@ -371,7 +374,7 @@ public class CellDesignerModificationResidue implements Serializable {
result.setWidth(element.getWidth() * size);
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, angle));
result.setPosition(converter.getResidueCoordinates(element, pos));
return result;
}
......@@ -380,7 +383,7 @@ public class CellDesignerModificationResidue implements Serializable {
result.setWidth(element.getWidth() * size);
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, angle));
result.setPosition(converter.getResidueCoordinates(element, pos));
return result;
}
......@@ -410,11 +413,11 @@ public class CellDesignerModificationResidue implements Serializable {
return result;
}
public String getModificationType() {
public ModificationType getModificationType() {
return modificationType;
}
public void setModificationType(String modificationType) {
public void setModificationType(ModificationType modificationType) {
this.modificationType = modificationType;
}
......
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
public enum ModificationType {
CODING_REGION("CodingRegion"), //
PROTEIN_BINDING_DOMAIN("proteinBindingDomain"), //
RESIDUE(null), //
MODIFICATION_SITE("Modification Site");//
private String cellDesignerName;
ModificationType(String cellDesignerName) {
this.cellDesignerName = cellDesignerName;
}
public String getCellDesignerName() {
return cellDesignerName;
}
public static ModificationType getByCellDesignerName(String name) {
for (ModificationType type : ModificationType.values()) {
if (type.getCellDesignerName() != null && type.getCellDesignerName().equals(name)) {
return type;
}
}
throw new InvalidArgumentException("Unknown CellDesigner name: " + name);
}
}
......@@ -23,6 +23,7 @@ import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerAntisenseRna;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType;
public class AntisenseRnaXmlParserTest extends CellDesignerTestFunctions {
protected Logger logger = Logger.getLogger(AntisenseRnaXmlParserTest.class.getName());
......@@ -57,7 +58,7 @@ public class AntisenseRnaXmlParserTest extends CellDesignerTestFunctions {
assertEquals("zzz", region.getName());
assertEquals(0.3, region.getSize(), 1e-6);
assertEquals(0.29999999999999993, region.getPos(), 1e-6);
assertEquals("CODING_REGION", region.getModificationType());
assertEquals(ModificationType.CODING_REGION, region.getModificationType());
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -99,7 +100,6 @@ public class AntisenseRnaXmlParserTest extends CellDesignerTestFunctions {
antisenseRnaParser.parseXmlElement(xmlString);
fail("Exception expected");
} catch (InvalidXmlSchemaException e) {
assertTrue(e.getMessage().contains("Unknown antisense rna region type"));
} catch (Exception e) {
e.printStackTrace();
throw e;
......
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