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

creating modifications simplified

parent 6932c247
......@@ -19,97 +19,104 @@ import lcsb.mapviewer.model.map.species.Species;
*/
public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected AntisenseRnaCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected AntisenseRnaCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* How big should be the arc in rectangle for nucleic acid feature
* representation.
*/
private static final int RECTANGLE_CORNER_ARC_SIZE = 5;
/**
* How big should be the arc in rectangle for nucleic acid feature
* representation.
*/
private static final int RECTANGLE_CORNER_ARC_SIZE = 5;
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
if (invalidAnchorPosition(alias, anchor)) {
return alias.getCenter();
}
if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(), alias.getWidth(), alias.getHeight(), anchor);
}
ArrayList<Point2D> points = getPoints(alias);
return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor);
}
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
if (invalidAnchorPosition(alias, anchor)) {
return alias.getCenter();
}
if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(), alias.getWidth(),
alias.getHeight(), anchor);
}
ArrayList<Point2D> points = getPoints(alias);
return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor);
}
@Override
protected PathIterator getBoundPathIterator(Species alias) {
return getAntisebseRnaPath(alias).getPathIterator(new AffineTransform());
}
@Override
protected PathIterator getBoundPathIterator(Species alias) {
return getAntisebseRnaPath(alias).getPathIterator(new AffineTransform());
}
/**
* Returns shape of the AntisenseRna as a list of points.
*
* @param alias
* alias for which we are looking for a border
* @return list of points defining border of the given alias
*/
private ArrayList<Point2D> getPoints(Element alias) {
double x = alias.getX();
double y = alias.getY();
double width = alias.getWidth();
double height = alias.getHeight();
ArrayList<Point2D> points = new ArrayList<Point2D>();
/**
* Returns shape of the AntisenseRna as a list of points.
*
* @param alias
* alias for which we are looking for a border
* @return list of points defining border of the given alias
*/
private ArrayList<Point2D> getPoints(Element alias) {
double x = alias.getX();
double y = alias.getY();
double width = alias.getWidth();
double height = alias.getHeight();
ArrayList<Point2D> points = new ArrayList<Point2D>();
// CHECKSTYLE:OFF
points.add(new Point2D.Double(x + width / 8, y + height / 2));
points.add(new Point2D.Double(x, y));
points.add(new Point2D.Double(x + width * 3 / 8, y));
points.add(new Point2D.Double(x + width * 3 / 4, y));
points.add(new Point2D.Double(x + width * 7 / 8, y + height / 2));
points.add(new Point2D.Double(x + width, y + height));
points.add(new Point2D.Double(x + width * 5 / 8, y + height));
points.add(new Point2D.Double(x + width / 4, y + height));
// CHECKSTYLE:ON
return points;
}
// CHECKSTYLE:OFF
points.add(new Point2D.Double(x + width / 8, y + height / 2));
points.add(new Point2D.Double(x, y));
points.add(new Point2D.Double(x + width * 3 / 8, y));
points.add(new Point2D.Double(x + width * 3 / 4, y));
points.add(new Point2D.Double(x + width * 7 / 8, y + height / 2));
points.add(new Point2D.Double(x + width, y + height));
points.add(new Point2D.Double(x + width * 5 / 8, y + height));
points.add(new Point2D.Double(x + width / 4, y + height));
// CHECKSTYLE:ON
return points;
}
/**
* Returns shape of the AntisenseRna as a GeneralPath object.
*
* @param alias
* alias for which we are looking for a border
* @return GeneralPath object defining border of the given alias
*/
private GeneralPath getAntisebseRnaPath(Element alias) {
// CHECKSTYLE:OFF
GeneralPath path;
if (!isSbgn()) {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);
path.moveTo(alias.getX(), alias.getY());
path.lineTo(alias.getX() + alias.getWidth() * 3 / 4, alias.getY());
path.lineTo(alias.getX() + alias.getWidth(), alias.getY() + alias.getHeight());
path.lineTo(alias.getX() + alias.getWidth() / 4, alias.getY() + alias.getHeight());
path.closePath();
} else {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6);
double x = alias.getX(), y = alias.getY(), width = alias.getWidth(), height = alias.getHeight();
/**
* Returns shape of the AntisenseRna as a GeneralPath object.
*
* @param alias
* alias for which we are looking for a border
* @return GeneralPath object defining border of the given alias
*/
private GeneralPath getAntisebseRnaPath(Element alias) {
// CHECKSTYLE:OFF
GeneralPath path;
if (!isSbgn()) {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);
path.moveTo(alias.getX(), alias.getY());
path.lineTo(alias.getX() + alias.getWidth() * 3 / 4, alias.getY());
path.lineTo(alias.getX() + alias.getWidth(), alias.getY() + alias.getHeight());
path.lineTo(alias.getX() + alias.getWidth() / 4, alias.getY() + alias.getHeight());
path.closePath();
} else {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6);
double x = alias.getX(), y = alias.getY(), width = alias.getWidth(), height = alias.getHeight();
path.moveTo(x, y);
path.lineTo(x, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.curveTo(x, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height);
path.lineTo(x + width - RECTANGLE_CORNER_ARC_SIZE, y + height);
path.curveTo(x + width, y + height, x + width, y + height - RECTANGLE_CORNER_ARC_SIZE, x + width, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.lineTo(x + width, y);
path.closePath();
}
// CHECKSTYLE:ON
return path;
}
path.moveTo(x, y);
path.lineTo(x, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.curveTo(x, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height);
path.lineTo(x + width - RECTANGLE_CORNER_ARC_SIZE, y + height);
path.curveTo(x + width, y + height, x + width, y + height - RECTANGLE_CORNER_ARC_SIZE, x + width,
y + height - RECTANGLE_CORNER_ARC_SIZE);
path.lineTo(x + width, y);
path.closePath();
}
// CHECKSTYLE:ON
return path;
}
@Override
public Point2D getResidueCoordinates(Species element, double angle) {
return new Point2D.Double(element.getX() + element.getWidth() * 3.0 / 4.0 * angle, element.getY());
}
}
package lcsb.mapviewer.converter.model.celldesigner.geometry;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
/**
* Class that provides CellDesigner specific graphical information for Rna.
* It's used for conversion from xml to normal x,y coordinates.
*
* @author Piotr Gawron
*
*/
public class RnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected RnaCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* How big should be the arc in rectangle for nucleic acid feature representation.
*/
private static final int RECTANGLE_CORNER_ARC_SIZE = 5;
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
if (invalidAnchorPosition(alias, anchor)) {
return alias.getCenter();
}
if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(),
alias.getWidth(), alias.getHeight(), anchor);
}
ArrayList<Point2D> points = getPoints(alias);
return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor);
}
@Override
public PathIterator getBoundPathIterator(Species alias) {
return getRnaPath(alias).getPathIterator(new AffineTransform());
}
/**
* Returns shape of the Rna as a list of points.
*
* @param alias
* alias for which we are looking for a border
* @return list of points defining border of the given alias
*/
private ArrayList<Point2D> getPoints(Element alias) {
double x = alias.getX();
double y = alias.getY();
double width = alias.getWidth();
double height = alias.getHeight();
ArrayList<Point2D> points = new ArrayList<Point2D>();
// CHECKSTYLE:OFF
points.add(new Point2D.Double(x + width / 8, y + height / 2));
points.add(new Point2D.Double(x + width / 4, y));
points.add(new Point2D.Double(x + width * 5 / 8, y));
points.add(new Point2D.Double(x + width, y));
points.add(new Point2D.Double(x + width * 7 / 8, y + height / 2));
points.add(new Point2D.Double(x + width * 3 / 4, y + height));
points.add(new Point2D.Double(x + width * 3 / 8, y + height));
// CHECKSTYLE:ON
points.add(new Point2D.Double(x, y + height));
return points;
}
/**
* Returns shape of the Rna as a GeneralPath object.
*
* @param alias
* alias for which we are looking for a border
* @return GeneralPath object defining border of the given alias
*/
private GeneralPath getRnaPath(Element alias) {
// CHECKSTYLE:OFF
GeneralPath path;
if (!isSbgn()) {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);
path.moveTo(alias.getX() + alias.getWidth() / 4, alias.getY());
path.lineTo(alias.getX() + alias.getWidth(), alias.getY());
path.lineTo(alias.getX() + alias.getWidth() * 3 / 4, alias.getY() + alias.getHeight());
path.lineTo(alias.getX(), alias.getY() + alias.getHeight());
path.closePath();
} else {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6);
double x = alias.getX(), y = alias.getY(), width = alias.getWidth(), height = alias.getHeight();
path.moveTo(x, y);
path.lineTo(x, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.curveTo(x, y + height,
x + RECTANGLE_CORNER_ARC_SIZE, y + height,
x + RECTANGLE_CORNER_ARC_SIZE, y + height);
path.lineTo(x + width - RECTANGLE_CORNER_ARC_SIZE, y + height);
path.curveTo(x + width, y + height,
x + width, y + height - RECTANGLE_CORNER_ARC_SIZE,
x + width, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.lineTo(x + width, y);
path.closePath();
}
// CHECKSTYLE:ON
return path;
}
}
package lcsb.mapviewer.converter.model.celldesigner.geometry;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
/**
* Class that provides CellDesigner specific graphical information for Rna. It's
* used for conversion from xml to normal x,y coordinates.
*
* @author Piotr Gawron
*
*/
public class RnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected RnaCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* How big should be the arc in rectangle for nucleic acid feature
* representation.
*/
private static final int RECTANGLE_CORNER_ARC_SIZE = 5;
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
if (invalidAnchorPosition(alias, anchor)) {
return alias.getCenter();
}
if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(), alias.getWidth(),
alias.getHeight(), anchor);
}
ArrayList<Point2D> points = getPoints(alias);
return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor);
}
@Override
public PathIterator getBoundPathIterator(Species alias) {
return getRnaPath(alias).getPathIterator(new AffineTransform());
}
/**
* Returns shape of the Rna as a list of points.
*
* @param alias
* alias for which we are looking for a border
* @return list of points defining border of the given alias
*/
private ArrayList<Point2D> getPoints(Element alias) {
double x = alias.getX();
double y = alias.getY();
double width = alias.getWidth();
double height = alias.getHeight();
ArrayList<Point2D> points = new ArrayList<Point2D>();
// CHECKSTYLE:OFF
points.add(new Point2D.Double(x + width / 8, y + height / 2));
points.add(new Point2D.Double(x + width / 4, y));
points.add(new Point2D.Double(x + width * 5 / 8, y));
points.add(new Point2D.Double(x + width, y));
points.add(new Point2D.Double(x + width * 7 / 8, y + height / 2));
points.add(new Point2D.Double(x + width * 3 / 4, y + height));
points.add(new Point2D.Double(x + width * 3 / 8, y + height));
// CHECKSTYLE:ON
points.add(new Point2D.Double(x, y + height));
return points;
}
/**
* Returns shape of the Rna as a GeneralPath object.
*
* @param alias
* alias for which we are looking for a border
* @return GeneralPath object defining border of the given alias
*/
private GeneralPath getRnaPath(Element alias) {
// CHECKSTYLE:OFF
GeneralPath path;
if (!isSbgn()) {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);
path.moveTo(alias.getX() + alias.getWidth() / 4, alias.getY());
path.lineTo(alias.getX() + alias.getWidth(), alias.getY());
path.lineTo(alias.getX() + alias.getWidth() * 3 / 4, alias.getY() + alias.getHeight());
path.lineTo(alias.getX(), alias.getY() + alias.getHeight());
path.closePath();
} else {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6);
double x = alias.getX(), y = alias.getY(), width = alias.getWidth(), height = alias.getHeight();
path.moveTo(x, y);
path.lineTo(x, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.curveTo(x, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height);
path.lineTo(x + width - RECTANGLE_CORNER_ARC_SIZE, y + height);
path.curveTo(x + width, y + height, x + width, y + height - RECTANGLE_CORNER_ARC_SIZE, x + width,
y + height - RECTANGLE_CORNER_ARC_SIZE);
path.lineTo(x + width, y);
path.closePath();
}
// CHECKSTYLE:ON
return path;
}
@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,
element.getY());
}
}
......@@ -146,7 +146,7 @@ public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna>
@Override
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerModificationResidue region : regions) {
((AntisenseRna) element).addRegion(region.createAntisenseRegionAlias(element));
((AntisenseRna) element).addRegion(region.createModificationResidue(element));
}
}
......
......@@ -115,7 +115,7 @@ public class CellDesignerGene extends CellDesignerSpecies<Gene> {
@Override
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerModificationResidue region : modificationResidues) {
((Gene) element).addModificationResidue(region.createGeneModification(element));
((Gene) element).addModificationResidue(region.createModificationResidue(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.createProteinModification(element));
((Protein) element).addModificationResidue(mr.createModificationResidue(element));
}
}
......
......@@ -145,7 +145,7 @@ public class CellDesignerRna extends CellDesignerSpecies<Rna> {
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerModificationResidue region : regions) {
Rna rna = (Rna) element;
rna.addRegion(region.createRnaRegionAlias(rna));
rna.addRegion(region.createModificationResidue(rna));
}
}
......
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.awt.geom.Point2D;
import java.io.Serializable;
import org.apache.log4j.Logger;
......@@ -348,19 +347,46 @@ public class CellDesignerModificationResidue implements Serializable {
*
* @return {@link ModificationResidue} representing this object in a model
*/
public ModificationResidue createProteinModification(Element element) {
public ModificationResidue createModificationResidue(Element element) {
CellDesignerAliasConverter converter = new CellDesignerAliasConverter(element, false);
ModificationResidue result = null;
if (modificationType == null) {
throw new InvalidArgumentException("No type information for modification: " + idModificationResidue);
} else if (modificationType.equals("RESIDUE")) {
result = new Residue();
((Residue) result).setState(this.getState());
return createResidue(element, converter);
} else if (modificationType.equals("MODIFICATION_SITE")) {
return createModificationSite(element, converter);
} else if (modificationType.equals("CODING_REGION")) {
return createCodingRegion(element, converter);
} else if (modificationType.equals("PROTEIN_BINDING_DOMAIN")) {
return createProteinBindingDomain(element, converter);
} else {
throw new InvalidArgumentException("Unknown protein modification type: " + modificationType);
throw new InvalidArgumentException("Unknown modification type: " + modificationType);
}
}
private ProteinBindingDomain createProteinBindingDomain(Element element, CellDesignerAliasConverter converter) {
ProteinBindingDomain result = new ProteinBindingDomain();
result.setWidth(element.getWidth() * size);
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getResidueCoordinates(element, angle));
return result;
}
private CodingRegion createCodingRegion(Element element, CellDesignerAliasConverter converter) {
CodingRegion result = new CodingRegion();
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) {
ModificationSite result = new