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

issue #10 - sbgn format moved from model to project

parent 612d9c06
......@@ -108,7 +108,6 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
CellDesignerElementCollection elements = new CellDesignerElementCollection();
Model model = new ModelFullIndexed(null);
model.setSbgnFormat(params.isSbgnFormat());
if (params.getFilename() != null) {
model.setName(FilenameUtils.getBaseName(params.getFilename()));
......@@ -198,7 +197,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
}
if (reactionsNode != null) {
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements);
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, params.isSbgnFormat());
List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode);
model.addReactions(reactions);
}
......@@ -561,7 +560,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
CellDesignerElementCollection elements = new CellDesignerElementCollection();
SpeciesCollectionXmlParser speciesCollectionXmlParser = new SpeciesCollectionXmlParser(elements);
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements);
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, false);
aliasCollectionParser = new AliasCollectionXmlParser(elements, model);
StringBuilder result = new StringBuilder();
......
......@@ -23,7 +23,7 @@ import lcsb.mapviewer.model.map.species.Element;
* @param <T>
*/
public abstract class AbstractCellDesignerAliasConverter<T extends Element> implements ICellDesignerAliasConverter<T> {
/**
* Default class logger.
*/
......@@ -33,17 +33,17 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
* CellDesigner graphical helper with polygon transformation functions.
*/
private CellDesignerPolygonTransformation polygonTransformation = new CellDesignerPolygonTransformation();
/**
* CellDesigner graphical helper with lin transformation functions.
*/
private LineTransformation lineTransformation = new LineTransformation();
/**
* CellDesigner graphical helper with ellipse transformation functions.
*/
private CellDesignerEllipseTransformation ellipseTransformation = new CellDesignerEllipseTransformation();
/**
* CellDesigner graphical helper with rectangle transformation functions.
*/
......@@ -54,10 +54,19 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
*/
public static final int HOMODIMER_OFFSET = 6;
/**
* Should the converter use sbgn standard.
*/
private boolean sbgn;
/**
* Default constructor that prevents from instatiation of the class.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected AbstractCellDesignerAliasConverter() {
protected AbstractCellDesignerAliasConverter(boolean sbgn) {
this.sbgn = sbgn;
};
@Override
......@@ -215,4 +224,21 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
this.rectangleTransformation = rectangleTransformation;
}
/**
* @return the sbgn
* @see #sbgn
*/
protected boolean isSbgn() {
return sbgn;
}
/**
* @param sbgn
* the sbgn to set
* @see #sbgn
*/
protected void setSbgn(boolean sbgn) {
this.sbgn = sbgn;
}
}
......@@ -20,18 +20,28 @@ import lcsb.mapviewer.model.map.species.Species;
public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* How big should be the arc in rectangle for nucleic acid feature representation.
* 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;
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 (alias.getModel().isSbgnFormat()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(),
alias.getWidth(), alias.getHeight(), anchor);
if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(), alias.getWidth(), alias.getHeight(), anchor);
}
ArrayList<Point2D> points = getPoints(alias);
return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor);
......@@ -79,7 +89,7 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner
private GeneralPath getAntisebseRnaPath(Element alias) {
// CHECKSTYLE:OFF
GeneralPath path;
if (!alias.getModel().isSbgnFormat()) {
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());
......@@ -89,16 +99,12 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner
} 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.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.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();
}
......
package lcsb.mapviewer.converter.model.celldesigner.geometry;
import java.awt.geom.Point2D;
import java.util.HashMap;
import java.util.Map;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
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.AntisenseRna;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Degraded;
import lcsb.mapviewer.model.map.species.Drug;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Ion;
import lcsb.mapviewer.model.map.species.IonChannelProtein;
import lcsb.mapviewer.model.map.species.Phenotype;
import lcsb.mapviewer.model.map.species.ReceptorProtein;
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.TruncatedProtein;
import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* This class is designed to obtain CellDesigner specific data from alias. It
* contains static instances of converter for every type and use one that is
* needed for currently processed alias.
* This class is designed to obtain CellDesigner specific data from
* {@link Element}.
*
* @author Piotr Gawron
*
......@@ -35,83 +30,54 @@ import lcsb.mapviewer.modelutils.map.ElementUtils;
public class CellDesignerAliasConverter implements ICellDesignerAliasConverter<Element> {
// *****************************************************************
//
// STATIC PART
//
// *****************************************************************
/**
* Static map of alias converters used for conversion of aliases. Key in this
* map is a class of element to which alias reference to. Value is instance of
* a converter that can process the alias with the specific element type
* reference.
*/
private static Map<Class<? extends Element>, ICellDesignerAliasConverter<?>> elementConverters;
/**
* Class helping with transforming objectcs into meaningfull identifiers.
*/
private static ElementUtils eu = new ElementUtils();
static {
elementConverters = new HashMap<>();
addElementConverter(GenericProtein.class, new ProteinCellDesignerAliasConverter());
addElementConverter(TruncatedProtein.class, new ProteinCellDesignerAliasConverter());
addElementConverter(ReceptorProtein.class, new ProteinCellDesignerAliasConverter());
addElementConverter(IonChannelProtein.class, new ProteinCellDesignerAliasConverter());
addElementConverter(Degraded.class, new DegradedCellDesignerAliasConverter());
addElementConverter(Complex.class, new ComplexCellDesignerAliasConverter());
addElementConverter(SimpleMolecule.class, new SimpleMoleculeCellDesignerAliasConverter());
addElementConverter(Drug.class, new DrugCellDesignerAliasConverter());
addElementConverter(Ion.class, new IonCellDesignerAliasConverter());
addElementConverter(Phenotype.class, new PhenotypeCellDesignerAliasConverter());
addElementConverter(Rna.class, new RnaCellDesignerAliasConverter());
addElementConverter(AntisenseRna.class, new AntisenseRnaCellDesignerAliasConverter());
addElementConverter(Gene.class, new GeneCellDesignerAliasConverter());
addElementConverter(Unknown.class, new UnknownCellDesignerAliasConverter());
}
private static ElementUtils eu = new ElementUtils();
/**
* Method that set a converter for element referenced by alias to process.
* Returns a converter for given {@link Element}. If converter doesn't exist
* exception is thrown.
*
* @param clazz
* class type of element referenced by alias
* @param converter
* converter that should be used for conversion of this alias
* @param element
* element for which we are loooking for a converter
* @param sbgn
* Should the converter use sbgn standard
* @return converter that can be applied for the given element
*/
protected static void addElementConverter(Class<? extends Element> clazz, ICellDesignerAliasConverter<?> converter) {
elementConverters.put(clazz, converter);
}
/**
* Returns a converter for given alias. If converter doesn't exist then null
* is returned.
*
* @param alias
* alias for which we are loooking for a converter
* @return converter that can be applied for the given alias; null if such
* converter doesn't exist
*/
private static ICellDesignerAliasConverter<? extends Element> getConverterForAlias(Element alias) {
if (alias == null) {
throw new InvalidArgumentException("alias cannot be null");
private ICellDesignerAliasConverter<? extends Element> getConverterForAlias(Element element, boolean sbgn) {
if (element == null) {
throw new InvalidArgumentException("element cannot be null");
}
if (element instanceof Protein) {
return new ProteinCellDesignerAliasConverter(sbgn);
} else if (element instanceof Degraded) {
return new DegradedCellDesignerAliasConverter(sbgn);
} else if (element instanceof Complex) {
return new ComplexCellDesignerAliasConverter(sbgn);
} else if (element instanceof SimpleMolecule) {
return new SimpleMoleculeCellDesignerAliasConverter(sbgn);
} else if (element instanceof Drug) {
return new DrugCellDesignerAliasConverter(sbgn);
} else if (element instanceof Ion) {
return new IonCellDesignerAliasConverter(sbgn);
} else if (element instanceof Phenotype) {
return new PhenotypeCellDesignerAliasConverter(sbgn);
} else if (element instanceof Rna) {
return new RnaCellDesignerAliasConverter(sbgn);
} else if (element instanceof AntisenseRna) {
return new AntisenseRnaCellDesignerAliasConverter(sbgn);
} else if (element instanceof Gene) {
return new GeneCellDesignerAliasConverter(sbgn);
} else if (element instanceof Unknown) {
return new UnknownCellDesignerAliasConverter(sbgn);
} else {
throw new NotImplementedException(eu.getElementTag(element) + "Unknown converter for class");
}
ICellDesignerAliasConverter<?> result = elementConverters.get(alias.getClass());
return result;
}
// *******************************************************
//
// NON-STATIC CLASS DEFINITION
//
// *******************************************************
/**
* Converter used for operations on the alias given in constructor.
* Converter used for operations on the {@link Element} given in constructor.
*/
@SuppressWarnings("rawtypes")
private ICellDesignerAliasConverter converter = null;
......@@ -119,32 +85,30 @@ public class CellDesignerAliasConverter implements ICellDesignerAliasConverter<E
/**
* Default constructor.
*
* @param alias
* alias for which this converter will be used
* @param sbgn
* Should the converter use sbgn standard
* @param element
* element for which this converter will be used
*/
public CellDesignerAliasConverter(Element alias) {
converter = getConverterForAlias(alias);
// if we don't know which converter to use then throw an exception
if (converter == null) {
throw new InvalidArgumentException(eu.getElementTag(alias) + "Unknown converter for class");
}
public CellDesignerAliasConverter(Element element, boolean sbgn) {
converter = getConverterForAlias(element, sbgn);
}
@SuppressWarnings("unchecked")
@Override
public CellDesignerAnchor getAnchorForCoordinates(Element alias, Point2D point) {
return converter.getAnchorForCoordinates(alias, point);
public CellDesignerAnchor getAnchorForCoordinates(Element element, Point2D point) {
return converter.getAnchorForCoordinates(element, point);
}
@SuppressWarnings("unchecked")
@Override
public Point2D getPointCoordinates(Element alias, CellDesignerAnchor anchor) {
return converter.getPointCoordinates(alias, anchor);
public Point2D getPointCoordinates(Element element, CellDesignerAnchor anchor) {
return converter.getPointCoordinates(element, anchor);
}
@SuppressWarnings("unchecked")
@Override
public Point2D getAnchorPointCoordinates(Element alias, CellDesignerAnchor anchor, PolylineData line) {
return converter.getAnchorPointCoordinates(alias, anchor, line);
public Point2D getAnchorPointCoordinates(Element element, CellDesignerAnchor anchor, PolylineData line) {
return converter.getAnchorPointCoordinates(element, anchor, line);
}
}
......@@ -18,6 +18,16 @@ import lcsb.mapviewer.model.map.species.Complex;
*/
public class ComplexCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Complex> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected ComplexCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* How big is the triangle trimmed part of the complex.
*/
......
......@@ -17,6 +17,16 @@ import lcsb.mapviewer.model.map.species.Species;
*/
public class DegradedCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected DegradedCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* Part of height of the line used to cross degraded circle that goes behind
* this circle.
......
......@@ -19,10 +19,21 @@ import lcsb.mapviewer.model.map.species.Species;
*
*/
public class DrugCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected DrugCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* How big should be the arc in rectangle for drug representation.
*/
private static final int RECTANGLE_CORNER_ARC_SIZE = 40;
private static final int RECTANGLE_CORNER_ARC_SIZE = 40;
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
......
......@@ -20,6 +20,16 @@ import lcsb.mapviewer.model.map.species.Species;
*/
public class GeneCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected GeneCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* How big should be the arc in rectangle for nucleic acid feature representation.
*/
......@@ -41,7 +51,7 @@ public class GeneCellDesignerAliasConverter extends AbstractCellDesignerAliasCon
* @return Shape object that represents alias
*/
private Shape getGeneShape(Element alias) {
if (!alias.getModel().isSbgnFormat()) {
if (!isSbgn()) {
Shape shape;
shape = new Rectangle(alias.getX().intValue(), alias.getY().intValue(), alias.getWidth().intValue(), alias.getHeight().intValue());
return shape;
......
......@@ -17,6 +17,16 @@ import lcsb.mapviewer.model.map.species.Species;
*/
public class IonCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected IonCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
double diameter = getDiameter(alias);
......
......@@ -11,13 +11,24 @@ import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
/**
* Class that provides CellDesigner specific graphical information for Phenotype.
* It's used for conversion from xml to normal x,y coordinates.
* Class that provides CellDesigner specific graphical information for
* Phenotype. It's used for conversion from xml to normal x,y coordinates.
*
* @author Piotr Gawron
*
*/
public class PhenotypeCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Species> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected PhenotypeCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
@Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
if (invalidAnchorPosition(alias, anchor)) {
......
......@@ -28,6 +28,17 @@ import lcsb.mapviewer.modelutils.map.ElementUtils;
*
*/
public class ProteinCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<Protein> {
/**
* Default constructor.
*
* @param sbgn
* Should the converter use sbgn standard
*/
protected ProteinCellDesignerAliasConverter(boolean sbgn) {
super(sbgn);
}
/**
* Default class logger.
*/
......
......@@ -19,6 +19,16 @@ import lcsb.mapviewer.model.map.species.Species;
*/
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.
*/
......@@ -29,7 +39,7 @@ public class RnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConv
if (invalidAnchorPosition(alias, anchor)) {
return alias.getCenter();
}
if (alias.getModel().isSbgnFormat()) {
if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(),
alias.getWidth(), alias.getHeight(), anchor);
}
......@@ -78,7 +88,7 @@ public class RnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConv
private GeneralPath getRnaPath(Element alias) {
// CHECKSTYLE:OFF