Commit 96dd9860 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

export to xml of modifications fixed

parent 48e20687
package lcsb.mapviewer.converter.model.celldesigner.geometry;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.RoundRectangle2D;
import org.apache.log4j.Logger;
......@@ -20,10 +18,8 @@ import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerP
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerRectangleTransformation;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.IonChannelProtein;
import lcsb.mapviewer.model.map.species.ReceptorProtein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.TruncatedProtein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* This abstract class is an interface for setting up graphical data for alias
......@@ -401,4 +397,24 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
return result;
}
@Override
public Double getCellDesignerPositionByCoordinates(ModificationResidue mr) {
return null;
}
@Override
public Point2D getCoordinatesByPosition(Element element, Double pos) {
throw new NotImplementedException("Not implemented for: "+this.getClass());
}
@Override
public Double getCellDesignerSize(ModificationResidue mr) {
throw new NotImplementedException("Not implemented for: "+this.getClass());
}
@Override
public Double getWidthBySize(Element element, Double size) {
throw new NotImplementedException("Not implemented for: "+this.getClass());
}
}
......@@ -6,9 +6,12 @@ import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.AbstractRegionModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Class that provides CellDesigner specific graphical information for
......@@ -115,8 +118,27 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner
}
@Override
public Point2D getResidueCoordinates(Species element, double angle) {
return new Point2D.Double(element.getX() + element.getWidth() * 3.0 / 4.0 * angle, element.getY());
public Double getCellDesignerPositionByCoordinates(ModificationResidue mr) {
return (mr.getPosition().getX() - mr.getSpecies().getX())
/ (mr.getSpecies().getWidth() * 3.0 / 4.0);
}
@Override
public Point2D getCoordinatesByPosition(Element element, Double pos) {
return new Point2D.Double(element.getX() + element.getWidth() * 3.0 / 4.0 * pos, element.getY());
}
@Override
public Double getCellDesignerSize(ModificationResidue mr) {
if (mr instanceof AbstractRegionModification) {
return ((AbstractRegionModification) mr).getWidth() / (mr.getSpecies().getWidth() * 3.0 / 4.0);
}
throw new NotImplementedException("Not implemented for: " + this.getClass() + ", " + mr.getClass());
}
@Override
public Double getWidthBySize(Element element, Double size) {
return size * (element.getWidth() * 3.0 / 4.0);
}
}
......@@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
......@@ -124,4 +125,24 @@ public class CellDesignerAliasConverter implements ICellDesignerAliasConverter<E
return converter.getResidueCoordinates(species, angle);
}
@Override
public Double getCellDesignerPositionByCoordinates(ModificationResidue mr) {
return converter.getCellDesignerPositionByCoordinates(mr);
}
@Override
public Point2D getCoordinatesByPosition(Element element, Double pos) {
return converter.getCoordinatesByPosition(element, pos);
}
@Override
public Double getCellDesignerSize(ModificationResidue mr) {
return converter.getCellDesignerSize(mr);
}
@Override
public Double getWidthBySize(Element element, Double size) {
return converter.getWidthBySize(element, size);
}
}
......@@ -9,9 +9,12 @@ import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.field.AbstractRegionModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Class that provides CellDesigner specific graphical information for Gene.
......@@ -21,7 +24,7 @@ import lcsb.mapviewer.model.map.species.Gene;
*
*/
public class GeneCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Gene> {
Logger logger = Logger.getLogger(GeneCellDesignerAliasConverter.class);
/**
......@@ -84,16 +87,30 @@ public class GeneCellDesignerAliasConverter extends AbstractCellDesignerAliasCon
}
@Override
public Point2D getResidueCoordinates(final Gene gene, double angle) {
Point2D result = new Point2D.Double(gene.getX() + gene.getWidth() * angle, gene.getY());
public Double getCellDesignerPositionByCoordinates(ModificationResidue mr) {
Double result = (mr.getPosition().getX() - mr.getSpecies().getX()) / mr.getSpecies().getWidth();
result = Math.min(result, 1.0);
result = Math.max(result, 0.0);
return result;
}
@Override
public Double getAngleForPoint(Gene gene, Point2D position) {
Double result = (position.getX() - gene.getX()) / gene.getWidth();
result = Math.min(result, 1.0);
result = Math.max(result, 0.0);
public Point2D getCoordinatesByPosition(Element element, Double pos) {
Point2D result = new Point2D.Double(element.getX() + element.getWidth() * pos, element.getY());
return result;
}
@Override
public Double getCellDesignerSize(ModificationResidue mr) {
if (mr instanceof AbstractRegionModification) {
return ((AbstractRegionModification) mr).getWidth() / mr.getSpecies().getWidth();
}
throw new NotImplementedException("Not implemented for: " + this.getClass() + ", " + mr.getClass());
}
@Override
public Double getWidthBySize(Element element, Double size) {
return size * element.getWidth();
}
}
......@@ -5,10 +5,11 @@ import java.awt.geom.Point2D;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Interface that defines functions usefull in transforming graphical
* information from objects retrieved from CellDesigner xml into abslote values.
* Interface that defines functions useful in transforming graphical
* information from objects retrieved from CellDesigner xml into absolute values.
*
* @author Piotr Gawron
*
......@@ -61,4 +62,11 @@ public interface ICellDesignerAliasConverter<T extends Element> {
Double getAngleForPoint(T alias, Point2D position);
public Double getCellDesignerPositionByCoordinates(ModificationResidue mr);
public Point2D getCoordinatesByPosition(Element element, Double pos);
public Double getCellDesignerSize(ModificationResidue mr);
public Double getWidthBySize(Element element, Double size);
}
......@@ -6,9 +6,14 @@ import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.AbstractRegionModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Class that provides CellDesigner specific graphical information for Rna. It's
......@@ -18,6 +23,7 @@ import lcsb.mapviewer.model.map.species.Species;
*
*/
public class RnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
Logger logger = Logger.getLogger(RnaCellDesignerAliasConverter.class);
/**
* Default constructor.
......@@ -114,9 +120,28 @@ public class RnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConv
}
@Override
public Point2D getResidueCoordinates(Species element, double angle) {
return new Point2D.Double(element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * angle,
public Double getCellDesignerPositionByCoordinates(ModificationResidue mr) {
return (mr.getPosition().getX() - mr.getSpecies().getX() - mr.getSpecies().getWidth() / 4.0)
/ (mr.getSpecies().getWidth() * 3.0 / 4.0);
}
@Override
public Point2D getCoordinatesByPosition(Element element, Double pos) {
return new Point2D.Double(element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * pos,
element.getY());
}
@Override
public Double getCellDesignerSize(ModificationResidue mr) {
if (mr instanceof AbstractRegionModification) {
return ((AbstractRegionModification) mr).getWidth() / (mr.getSpecies().getWidth() * 3.0 / 4.0);
}
throw new NotImplementedException("Not implemented for: " + this.getClass() + ", " + mr.getClass());
}
@Override
public Double getWidthBySize(Element element, Double size) {
return size * (element.getWidth() * 3.0 / 4.0);
}
}
......@@ -9,6 +9,7 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* Class that provides CellDesigner specific graphical information for
......@@ -69,5 +70,4 @@ public class UnknownCellDesignerAliasConverter extends AbstractCellDesignerAlias
unknown.getHeight(), angle);
return result;
}
}
......@@ -121,6 +121,8 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
* @return xml representation of the given region
*/
private String toXml(ModificationResidue region) {
CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(region);
String result = "";
String attributes = "";
if (!region.getIdModificationResidue().equals("")) {
......@@ -129,28 +131,20 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner
if (!region.getName().equals("")) {
attributes += " name=\"" + escapeXml(region.getName()) + "\"";
}
double width = 0;
String type = null;
if (region instanceof CodingRegion) {
width = ((CodingRegion) region).getWidth();
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
type = "CodingRegion";
} else if (region instanceof ModificationSite) {
type = "Modification Site";
} else if (region instanceof ProteinBindingDomain) {
width = ((ProteinBindingDomain) region).getWidth();
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
type = "proteinBindingDomain";
} else {
throw new InvalidArgumentException("Unknown modificatin type: " + region.getClass());
}
if (width != 0) {
attributes += " size=\"" + width / region.getSpecies().getWidth() + "\"";
}
if (region.getPosition() != null) {
double pos = (region.getPosition().getX() - region.getSpecies().getWidth())
/ (region.getSpecies().getWidth() * 3 / 4);
attributes += " pos=\"" + pos + "\"";
}
attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\"";
attributes += " type=\"" + type + "\"";
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>";
......
......@@ -156,7 +156,7 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
* @return CellDesigner xml for {@link CellDesignerModificationResidue}
*/
String toXml(ModificationResidue mr) {
CellDesignerAliasConverter converter = new CellDesignerAliasConverter(mr.getSpecies(), false);
CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr);
String result = "";
String attributes = "";
......@@ -171,10 +171,10 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
type = ModificationType.MODIFICATION_SITE.getCellDesignerName();
} else if (mr instanceof RegulatoryRegion) {
type = ModificationType.REGULATORY_REGION.getCellDesignerName();
attributes += " size=\"" + ((RegulatoryRegion) mr).getWidth() / mr.getSpecies().getWidth() + "\"";
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
} else if (mr instanceof CodingRegion) {
type = ModificationType.CODING_REGION.getCellDesignerName();
attributes += " size=\"" + ((RegulatoryRegion) mr).getWidth() / mr.getSpecies().getWidth() + "\"";
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
} else if (mr instanceof TranscriptionSite) {
TranscriptionSite transcriptionSite = (TranscriptionSite) mr;
if (transcriptionSite.getDirection().equals("RIGHT")) {
......@@ -182,13 +182,13 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge
} else {
type = ModificationType.TRANSCRIPTION_SITE_LEFT.getCellDesignerName();
}
attributes += " size=\"" + transcriptionSite.getWidth() / mr.getSpecies().getWidth() + "\"";
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
attributes += " active=\"" + transcriptionSite.getActive() + "\"";
} 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=\"" + cellDesignerModificationResidue.getPos() + "\"";
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>\n";
......
......@@ -5,14 +5,20 @@ 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.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.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;
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.ProteinBindingDomain;
/**
* Class that performs parsing of the CellDesigner xml for
......@@ -125,8 +131,54 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna>
result += "</body></html>";
result += "</celldesigner:notes>";
if (rna.getRegions().size() > 0) {
result += "<celldesigner:listOfRegions>";
for (ModificationResidue mr : rna.getRegions()) {
result += toXml(mr);
}
result += "</celldesigner:listOfRegions>";
}
result += "</celldesigner:RNA>";
return result;
}
/**
* Generates CellDesigner xml for {@link CellDesignerModificationResidue}.
*
* @param mr
* object to transform into xml
* @return CellDesigner xml for {@link CellDesignerModificationResidue}
*/
String toXml(ModificationResidue mr) {
CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr);
String result = "";
String attributes = "";
if (!mr.getIdModificationResidue().equals("")) {
attributes += " id=\"" + mr.getIdModificationResidue() + "\"";
}
if (!mr.getName().equals("")) {
attributes += " name=\"" + escapeXml(mr.getName()) + "\"";
}
String type = null;
if (mr instanceof ModificationSite) {
type = ModificationType.MODIFICATION_SITE.getCellDesignerName();
} else if (mr instanceof CodingRegion) {
type = ModificationType.CODING_REGION.getCellDesignerName();
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
} else if (mr instanceof ProteinBindingDomain) {
type = ModificationType.PROTEIN_BINDING_DOMAIN.getCellDesignerName();
attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\"";
} else {
throw new InvalidArgumentException("Don't know how to handle: " + mr.getClass());
}
attributes += " type=\"" + type + "\"";
attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\"";
result += "<celldesigner:region " + attributes + ">";
result += "</celldesigner:region>\n";
return result;
}
}
......@@ -98,7 +98,7 @@ public class CellDesignerModificationResidue implements Serializable {
this.idModificationResidue = mr.idModificationResidue;
this.name = mr.name;
this.angle = mr.angle;
this.active= mr.active;
this.active = mr.active;
this.size = mr.size;
this.side = mr.side;
this.pos = mr.pos;
......@@ -117,7 +117,7 @@ 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;
this.pos = converter.getCellDesignerPositionByCoordinates(mr);
if (mr instanceof Residue) {
this.modificationType = ModificationType.RESIDUE;
this.state = ((Residue) mr).getState();
......@@ -125,17 +125,17 @@ public class CellDesignerModificationResidue implements Serializable {
this.modificationType = ModificationType.MODIFICATION_SITE;
this.state = ((ModificationSite) mr).getState();
} else if (mr instanceof CodingRegion) {
this.size = ((CodingRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.size = converter.getCellDesignerSize(mr);
this.modificationType = ModificationType.CODING_REGION;
} else if (mr instanceof ProteinBindingDomain) {
this.size = ((CodingRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.size = converter.getCellDesignerSize(mr);
this.modificationType = ModificationType.PROTEIN_BINDING_DOMAIN;
} else if (mr instanceof RegulatoryRegion) {
this.size = ((RegulatoryRegion) mr).getWidth() / mr.getSpecies().getWidth();
this.size = converter.getCellDesignerSize(mr);
this.modificationType = ModificationType.REGULATORY_REGION;
} else if (mr instanceof TranscriptionSite) {
TranscriptionSite transcriptionSite = (TranscriptionSite)mr;
this.size = transcriptionSite.getWidth() / mr.getSpecies().getWidth();
TranscriptionSite transcriptionSite = (TranscriptionSite) mr;
this.size = converter.getCellDesignerSize(mr);
this.active = transcriptionSite.getActive();
if (transcriptionSite.getDirection().equals("LEFT")) {
this.modificationType = ModificationType.TRANSCRIPTION_SITE_LEFT;
......@@ -400,7 +400,8 @@ public class CellDesignerModificationResidue implements Serializable {
return createProteinBindingDomain(element, converter);
} else if (modificationType.equals(ModificationType.REGULATORY_REGION)) {
return createRegulatoryRegion(element, converter);
} else if (modificationType.equals(ModificationType.TRANSCRIPTION_SITE_LEFT) || modificationType.equals(ModificationType.TRANSCRIPTION_SITE_RIGHT)) {
} else if (modificationType.equals(ModificationType.TRANSCRIPTION_SITE_LEFT)
|| modificationType.equals(ModificationType.TRANSCRIPTION_SITE_RIGHT)) {
return createTranscriptionSite(element, converter);
} else {
throw new InvalidArgumentException("Unknown modification type: " + modificationType);
......@@ -410,10 +411,10 @@ public class CellDesignerModificationResidue implements Serializable {
private ProteinBindingDomain createProteinBindingDomain(Element element, CellDesignerAliasConverter converter) {
ProteinBindingDomain result = new ProteinBindingDomain();
result.setWidth(element.getWidth() * size);
result.setWidth(converter.getWidthBySize(element, size));
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, pos));
result.setPosition(converter.getCoordinatesByPosition(element, pos));
return result;
}
......@@ -434,29 +435,33 @@ public class CellDesignerModificationResidue implements Serializable {
private CodingRegion createCodingRegion(Element element, CellDesignerAliasConverter converter) {
CodingRegion result = new CodingRegion();
result.setWidth(element.getWidth() * size);
result.setWidth(converter.getWidthBySize(element, size));
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, pos));
if (pos == null) {
pos = angle;
}
result.setPosition(converter.getCoordinatesByPosition(element, pos));
return result;
}
private RegulatoryRegion createRegulatoryRegion(Element element, CellDesignerAliasConverter converter) {
RegulatoryRegion result = new RegulatoryRegion();
result.setWidth(element.getWidth() * size);
result.setWidth(converter.getWidthBySize(element, size));
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, angle));
result.setPosition(converter.getCoordinatesByPosition(element, angle));
return result;
}
private TranscriptionSite createTranscriptionSite(Element element, CellDesignerAliasConverter converter) {
TranscriptionSite result = new TranscriptionSite();
result.setWidth(element.getWidth() * size);
result.setWidth(converter.getWidthBySize(element, size));
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setActive(active);
result.setPosition(converter.getResidueCoordinates(element, angle));
logger.debug(angle);