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

coordinates of antisense rna region are absolute x,y values

parent 48fb447c
package lcsb.mapviewer.converter.model.celldesigner.species;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
......@@ -23,151 +25,157 @@ import lcsb.mapviewer.model.map.species.field.AntisenseRnaRegionType;
*/
public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesignerAntisenseRna, AntisenseRna> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(AntisenseRnaXmlParser.class.getName());
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(AntisenseRnaXmlParser.class.getName());
/**
* List of {@link CellDesignerElement celldesigner elements} obtained during
* parsing process.
*/
private CellDesignerElementCollection elements;
/**
* List of {@link CellDesignerElement celldesigner elements} obtained during
* parsing process.
*/
private CellDesignerElementCollection elements;
/**
* Default constructor.
*
* @param elements
* list of {@link CellDesignerElement celldesigner elements} obtained
* during parsing process
*/
public AntisenseRnaXmlParser(CellDesignerElementCollection elements) {
this.elements = elements;
}
/**
* Default constructor.
*
* @param elements
* list of {@link CellDesignerElement celldesigner elements} obtained
* during parsing process
*/
public AntisenseRnaXmlParser(CellDesignerElementCollection elements) {
this.elements = elements;
}
@Override
public Pair<String, CellDesignerAntisenseRna> parseXmlElement(Node antisenseRnaNode)
throws InvalidXmlSchemaException {
CellDesignerAntisenseRna antisenseRna = new CellDesignerAntisenseRna();
String identifier = getNodeAttr("id", antisenseRnaNode);
antisenseRna.setName(decodeName(getNodeAttr("name", antisenseRnaNode)));
NodeList list = antisenseRnaNode.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")) {
antisenseRna.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")) {
antisenseRna.addRegion(getAntisenseRnaRegion(residueNode));
} else {
throw new InvalidXmlSchemaException(
"Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
}
}
}
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:antisenseRna " + node.getNodeName());
}
}
}
Pair<String, CellDesignerAntisenseRna> result = new Pair<String, CellDesignerAntisenseRna>(identifier,
antisenseRna);
return result;
}
@Override
public Pair<String, CellDesignerAntisenseRna> parseXmlElement(Node antisenseRnaNode) throws InvalidXmlSchemaException {
CellDesignerAntisenseRna antisenseRna = new CellDesignerAntisenseRna();
String identifier = getNodeAttr("id", antisenseRnaNode);
antisenseRna.setName(decodeName(getNodeAttr("name", antisenseRnaNode)));
NodeList list = antisenseRnaNode.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")) {
antisenseRna.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")) {
antisenseRna.addRegion(getAntisenseRnaRegion(residueNode));
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfRegions " + residueNode.getNodeName());
}
}
}
} else {
throw new InvalidXmlSchemaException("Unknown element of celldesigner:antisenseRna " + node.getNodeName());
}
}
}
Pair<String, CellDesignerAntisenseRna> result = new Pair<String, CellDesignerAntisenseRna>(identifier, antisenseRna);
return result;
}
@Override
public String toXml(AntisenseRna antisenseRna) {
String attributes = "";
String result = "";
attributes += " id=\"ar_" + elements.getElementId(antisenseRna) + "\"";
if (!antisenseRna.getName().equals("")) {
attributes += " name=\"" + escapeXml(encodeName(antisenseRna.getName())) + "\"";
}
result += "<celldesigner:AntisenseRNA" + attributes + ">";
result += "<celldesigner:notes>";
result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>";
@Override
public String toXml(AntisenseRna antisenseRna) {
String attributes = "";
String result = "";
attributes += " id=\"ar_" + elements.getElementId(antisenseRna) + "\"";
if (!antisenseRna.getName().equals("")) {
attributes += " name=\"" + escapeXml(encodeName(antisenseRna.getName())) + "\"";
}
result += "<celldesigner:AntisenseRNA" + attributes + ">";
result += "<celldesigner:notes>";
result += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>";
RestAnnotationParser rap = new RestAnnotationParser();
result += rap.createAnnotationString(antisenseRna);
result += antisenseRna.getNotes();
result += "</body></html>";
result += "</celldesigner:notes>";
if (antisenseRna.getRegions().size() > 0) {
result += "<celldesigner:listOfRegions>";
for (AntisenseRnaRegion region : antisenseRna.getRegions()) {
result += toXml(region);
}
result += "</celldesigner:listOfRegions>";
}
result += "</celldesigner:AntisenseRNA>";
return result;
}
RestAnnotationParser rap = new RestAnnotationParser();
result += rap.createAnnotationString(antisenseRna);
result += antisenseRna.getNotes();
result += "</body></html>";
result += "</celldesigner:notes>";
if (antisenseRna.getRegions().size() > 0) {
result += "<celldesigner:listOfRegions>";
for (AntisenseRnaRegion region : antisenseRna.getRegions()) {
result += toXml(region);
}
result += "</celldesigner:listOfRegions>";
}
result += "</celldesigner:AntisenseRNA>";
return result;
}
/**
* Transforms AntisenseRnaRegion into CellDEsigner xml representation.
*
* @param region
* object to be transformed
* @return xml representation of the given region
*/
private String toXml(AntisenseRnaRegion region) {
String result = "";
String attributes = "";
if (!region.getIdAntisenseRnaRegion().equals("")) {
attributes += " id=\"" + region.getIdAntisenseRnaRegion() + "\"";
}
if (!region.getName().equals("")) {
attributes += " name=\"" + escapeXml(region.getName()) + "\"";
}
if (region.getSize() != 0) {
attributes += " size=\"" + region.getSize() + "\"";
}
if (region.getPosition() != null) {
double pos = (region.getPosition().getX() - region.getSpecies().getWidth())
/ (region.getSpecies().getWidth() * 3 / 4);
/**
* Transforms AntisenseRnaRegion into CellDEsigner xml representation.
*
* @param region
* object to be transformed
* @return xml representation of the given region
*/
private String toXml(AntisenseRnaRegion region) {
String result = "";
String attributes = "";
if (!region.getIdAntisenseRnaRegion().equals("")) {
attributes += " id=\"" + region.getIdAntisenseRnaRegion() + "\"";
}
if (!region.getName().equals("")) {
attributes += " name=\"" + escapeXml(region.getName()) + "\"";
}
if (region.getSize() != 0) {
attributes += " size=\"" + region.getSize() + "\"";
}
if (region.getPos() != 0) {
attributes += " pos=\"" + region.getPos() + "\"";
}
if (region.getType() != null) {
attributes += " type=\"" + region.getType().getName() + "\"";
}
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>";
attributes += " pos=\"" + pos + "\"";
}
if (region.getType() != null) {
attributes += " type=\"" + region.getType().getName() + "\"";
}
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>";
return result;
}
return result;
}
/**
* Method that parse xml node into AntisenseRnaRegion element.
*
* @param regionNode
* xml node to parse
* @return AntisenseRnaRegion object from xml node
* @throws InvalidXmlSchemaException
* thrown when input xml node doesn't follow defined schema
*/
private CellDesignerAntisenseRnaRegion getAntisenseRnaRegion(Node regionNode) throws InvalidXmlSchemaException {
CellDesignerAntisenseRnaRegion residue = new CellDesignerAntisenseRnaRegion();
residue.setIdAntisenseRnaRegion(getNodeAttr("id", regionNode));
residue.setName(getNodeAttr("name", regionNode));
residue.setSize(getNodeAttr("size", regionNode));
residue.setPos(getNodeAttr("pos", regionNode));
String typeString = getNodeAttr("type", regionNode);
if (typeString != null) {
AntisenseRnaRegionType type = AntisenseRnaRegionType.getTypeByString(typeString);
if (type == null) {
throw new InvalidXmlSchemaException("Unknown antisense rna region type: " + typeString);
}
residue.setType(type);
}
NodeList list = regionNode.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;
}
/**
* Method that parse xml node into AntisenseRnaRegion element.
*
* @param regionNode
* xml node to parse
* @return AntisenseRnaRegion object from xml node
* @throws InvalidXmlSchemaException
* thrown when input xml node doesn't follow defined schema
*/
private CellDesignerAntisenseRnaRegion getAntisenseRnaRegion(Node regionNode) throws InvalidXmlSchemaException {
CellDesignerAntisenseRnaRegion residue = new CellDesignerAntisenseRnaRegion();
residue.setIdAntisenseRnaRegion(getNodeAttr("id", regionNode));
residue.setName(getNodeAttr("name", regionNode));
residue.setSize(getNodeAttr("size", regionNode));
residue.setPos(getNodeAttr("pos", regionNode));
String typeString = getNodeAttr("type", regionNode);
if (typeString != null) {
AntisenseRnaRegionType type = AntisenseRnaRegionType.getTypeByString(typeString);
if (type == null) {
throw new InvalidXmlSchemaException("Unknown antisense rna region type: " + typeString);
}
residue.setType(type);
}
NodeList list = regionNode.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;
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.AntisenseRna;
/**
* Class representing CellDesigner {@link AntisenseRna}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerAntisenseRna.class);
/**
* List of antisense rna regions (some rna sequences) in this object.
*/
private List<CellDesignerAntisenseRnaRegion> regions = new ArrayList<CellDesignerAntisenseRnaRegion>();
/**
* Constructor that copies the data from species given in the argument.
*
* @param species
* parent species from which we want to copy data
*/
public CellDesignerAntisenseRna(CellDesignerSpecies<?> species) {
super(species);
if (species instanceof CellDesignerAntisenseRna) {
CellDesignerAntisenseRna asRna = (CellDesignerAntisenseRna) species;
for (CellDesignerAntisenseRnaRegion region : asRna.getRegions()) {
addRegion(new CellDesignerAntisenseRnaRegion(region));
}
}
}
/**
* Default constructor.
*/
public CellDesignerAntisenseRna() {
super();
}
@Override
public CellDesignerAntisenseRna copy() {
if (this.getClass() == CellDesignerAntisenseRna.class) {
return new CellDesignerAntisenseRna(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
/**
* Addd antisense rna region (part of rna sequence that has some meaning) to
* the object. If the region with given id exists then the data of this region
* is copied to the one that is already in the
* {@link CellDesignerAntisenseRna}.
*
*
* @param region
* region to add
*/
public void addRegion(CellDesignerAntisenseRnaRegion region) {
for (CellDesignerAntisenseRnaRegion region2 : regions) {
if (region2.getIdAntisenseRnaRegion().equals(region.getIdAntisenseRnaRegion())) {
region2.update(region);
return;
}
}
regions.add(region);
region.setSpecies(this);
}
@Override
public void update(CellDesignerSpecies<?> sp) {
super.update(sp);
if (sp instanceof CellDesignerAntisenseRna) {
CellDesignerAntisenseRna rna = (CellDesignerAntisenseRna) sp;
for (CellDesignerAntisenseRnaRegion mr : getRegions()) {
mr.setState(null);
}
for (CellDesignerAntisenseRnaRegion region : rna.getRegions()) {
updateRegion(region);
}
}
}
/**
* Method update antisense rna region from the object in params (if the object
* with the same id already exists). If there is no object with given id then
* new object is added to antisense rna.
*
* @param param
* - object with new data from where update should be performed
*/
private void updateRegion(CellDesignerAntisenseRnaRegion param) {
for (CellDesignerAntisenseRnaRegion region : regions) {
if (region.getIdAntisenseRnaRegion().equals(param.getIdAntisenseRnaRegion())) {
region.update(param);
return;
}
}
regions.add(param);
}
/**
* @return the regions
* @see #regions
*/
public List<CellDesignerAntisenseRnaRegion> getRegions() {
return regions;
}
/**
* @param regions
* the regions to set
* @see #regions
*/
public void setRegions(List<CellDesignerAntisenseRnaRegion> regions) {
this.regions = regions;
}
@Override
public AntisenseRna createModelElement(String aliasId) {
AntisenseRna result = new AntisenseRna(aliasId);
super.setModelObjectFields(result);
for (CellDesignerAntisenseRnaRegion region : regions) {
result.addRegion(region.createAntisenseRegionAlias());
}
return result;
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.AntisenseRna;
/**
* Class representing CellDesigner {@link AntisenseRna}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerAntisenseRna.class);
/**
* List of antisense rna regions (some rna sequences) in this object.
*/
private List<CellDesignerAntisenseRnaRegion> regions = new ArrayList<CellDesignerAntisenseRnaRegion>();
/**
* Constructor that copies the data from species given in the argument.
*
* @param species
* parent species from which we want to copy data
*/
public CellDesignerAntisenseRna(CellDesignerSpecies<?> species) {
super(species);
if (species instanceof CellDesignerAntisenseRna) {
CellDesignerAntisenseRna asRna = (CellDesignerAntisenseRna) species;
for (CellDesignerAntisenseRnaRegion region : asRna.getRegions()) {
addRegion(new CellDesignerAntisenseRnaRegion(region));
}
}
}
/**
* Default constructor.
*/
public CellDesignerAntisenseRna() {
super();
}
@Override
public CellDesignerAntisenseRna copy() {
if (this.getClass() == CellDesignerAntisenseRna.class) {
return new CellDesignerAntisenseRna(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
/**
* Addd antisense rna region (part of rna sequence that has some meaning) to the
* object. If the region with given id exists then the data of this region is
* copied to the one that is already in the {@link CellDesignerAntisenseRna}.
*
*
* @param region
* region to add
*/
public void addRegion(CellDesignerAntisenseRnaRegion region) {
for (CellDesignerAntisenseRnaRegion region2 : regions) {
if (region2.getIdAntisenseRnaRegion().equals(region.getIdAntisenseRnaRegion())) {
region2.update(region);
return;
}
}
regions.add(region);
region.setSpecies(this);
}
@Override
public void update(CellDesignerSpecies<?> sp) {
super.update(sp);
if (sp instanceof CellDesignerAntisenseRna) {
CellDesignerAntisenseRna rna = (CellDesignerAntisenseRna) sp;