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 { ...@@ -108,7 +108,6 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
CellDesignerElementCollection elements = new CellDesignerElementCollection(); CellDesignerElementCollection elements = new CellDesignerElementCollection();
Model model = new ModelFullIndexed(null); Model model = new ModelFullIndexed(null);
model.setSbgnFormat(params.isSbgnFormat());
if (params.getFilename() != null) { if (params.getFilename() != null) {
model.setName(FilenameUtils.getBaseName(params.getFilename())); model.setName(FilenameUtils.getBaseName(params.getFilename()));
...@@ -198,7 +197,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { ...@@ -198,7 +197,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
} }
if (reactionsNode != null) { if (reactionsNode != null) {
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements); ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, params.isSbgnFormat());
List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode); List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode);
model.addReactions(reactions); model.addReactions(reactions);
} }
...@@ -561,7 +560,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter { ...@@ -561,7 +560,7 @@ public class CellDesignerXmlParser extends XmlParser implements IConverter {
CellDesignerElementCollection elements = new CellDesignerElementCollection(); CellDesignerElementCollection elements = new CellDesignerElementCollection();
SpeciesCollectionXmlParser speciesCollectionXmlParser = new SpeciesCollectionXmlParser(elements); SpeciesCollectionXmlParser speciesCollectionXmlParser = new SpeciesCollectionXmlParser(elements);
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements); ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, false);
aliasCollectionParser = new AliasCollectionXmlParser(elements, model); aliasCollectionParser = new AliasCollectionXmlParser(elements, model);
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
......
...@@ -23,7 +23,7 @@ import lcsb.mapviewer.model.map.species.Element; ...@@ -23,7 +23,7 @@ import lcsb.mapviewer.model.map.species.Element;
* @param <T> * @param <T>
*/ */
public abstract class AbstractCellDesignerAliasConverter<T extends Element> implements ICellDesignerAliasConverter<T> { public abstract class AbstractCellDesignerAliasConverter<T extends Element> implements ICellDesignerAliasConverter<T> {
/** /**
* Default class logger. * Default class logger.
*/ */
...@@ -33,17 +33,17 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl ...@@ -33,17 +33,17 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
* CellDesigner graphical helper with polygon transformation functions. * CellDesigner graphical helper with polygon transformation functions.
*/ */
private CellDesignerPolygonTransformation polygonTransformation = new CellDesignerPolygonTransformation(); private CellDesignerPolygonTransformation polygonTransformation = new CellDesignerPolygonTransformation();
/** /**
* CellDesigner graphical helper with lin transformation functions. * CellDesigner graphical helper with lin transformation functions.
*/ */
private LineTransformation lineTransformation = new LineTransformation(); private LineTransformation lineTransformation = new LineTransformation();
/** /**
* CellDesigner graphical helper with ellipse transformation functions. * CellDesigner graphical helper with ellipse transformation functions.
*/ */
private CellDesignerEllipseTransformation ellipseTransformation = new CellDesignerEllipseTransformation(); private CellDesignerEllipseTransformation ellipseTransformation = new CellDesignerEllipseTransformation();
/** /**
* CellDesigner graphical helper with rectangle transformation functions. * CellDesigner graphical helper with rectangle transformation functions.
*/ */
...@@ -54,10 +54,19 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl ...@@ -54,10 +54,19 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
*/ */
public static final int HOMODIMER_OFFSET = 6; 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. * 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 @Override
...@@ -215,4 +224,21 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl ...@@ -215,4 +224,21 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
this.rectangleTransformation = rectangleTransformation; 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; ...@@ -20,18 +20,28 @@ import lcsb.mapviewer.model.map.species.Species;
public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<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 @Override
public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) { public Point2D getPointCoordinates(Species alias, CellDesignerAnchor anchor) {
if (invalidAnchorPosition(alias, anchor)) { if (invalidAnchorPosition(alias, anchor)) {
return alias.getCenter(); return alias.getCenter();
} }
if (alias.getModel().isSbgnFormat()) { if (isSbgn()) {
return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(), return getRectangleTransformation().getPointOnRectangleByAnchor(alias.getX(), alias.getY(), alias.getWidth(), alias.getHeight(), anchor);
alias.getWidth(), alias.getHeight(), anchor);
} }
ArrayList<Point2D> points = getPoints(alias); ArrayList<Point2D> points = getPoints(alias);
return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor); return getPolygonTransformation().getPointOnPolygonByAnchor(points, anchor);
...@@ -79,7 +89,7 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner ...@@ -79,7 +89,7 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner
private GeneralPath getAntisebseRnaPath(Element alias) { private GeneralPath getAntisebseRnaPath(Element alias) {
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
GeneralPath path; GeneralPath path;
if (!alias.getModel().isSbgnFormat()) { if (!isSbgn()) {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4); path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);
path.moveTo(alias.getX(), alias.getY()); path.moveTo(alias.getX(), alias.getY());
path.lineTo(alias.getX() + alias.getWidth() * 3 / 4, alias.getY()); path.lineTo(alias.getX() + alias.getWidth() * 3 / 4, alias.getY());
...@@ -89,16 +99,12 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner ...@@ -89,16 +99,12 @@ public class AntisenseRnaCellDesignerAliasConverter extends AbstractCellDesigner
} else { } else {
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6); path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6);
double x = alias.getX(), y = alias.getY(), width = alias.getWidth(), height = alias.getHeight(); double x = alias.getX(), y = alias.getY(), width = alias.getWidth(), height = alias.getHeight();
path.moveTo(x, y); path.moveTo(x, y);
path.lineTo(x, y + height - RECTANGLE_CORNER_ARC_SIZE); path.lineTo(x, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.curveTo(x, y + height, path.curveTo(x, y + height, x + RECTANGLE_CORNER_ARC_SIZE, y + height, x + RECTANGLE_CORNER_ARC_SIZE, 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.lineTo(x + width - RECTANGLE_CORNER_ARC_SIZE, y + height);
path.curveTo(x + width, y + height, path.curveTo(x + width, y + height, x + width, y + height - RECTANGLE_CORNER_ARC_SIZE, x + width, y + height - RECTANGLE_CORNER_ARC_SIZE);
x + width, y + height - RECTANGLE_CORNER_ARC_SIZE,
x + width, y + height - RECTANGLE_CORNER_ARC_SIZE);
path.lineTo(x + width, y); path.lineTo(x + width, y);
path.closePath(); path.closePath();
} }
......
package lcsb.mapviewer.converter.model.celldesigner.geometry; package lcsb.mapviewer.converter.model.celldesigner.geometry;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.HashMap;
import java.util.Map;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor; import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.model.graphics.PolylineData; 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.AntisenseRna;
import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Degraded; import lcsb.mapviewer.model.map.species.Degraded;
import lcsb.mapviewer.model.map.species.Drug; 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.Gene;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Ion; 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.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.Rna;
import lcsb.mapviewer.model.map.species.SimpleMolecule; import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.TruncatedProtein;
import lcsb.mapviewer.model.map.species.Unknown; import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.modelutils.map.ElementUtils; import lcsb.mapviewer.modelutils.map.ElementUtils;
/** /**
* This class is designed to obtain CellDesigner specific data from alias. It * This class is designed to obtain CellDesigner specific data from
* contains static instances of converter for every type and use one that is * {@link Element}.
* needed for currently processed alias.
* *
* @author Piotr Gawron * @author Piotr Gawron
* *
...@@ -35,83 +30,54 @@ import lcsb.mapviewer.modelutils.map.ElementUtils; ...@@ -35,83 +30,54 @@ import lcsb.mapviewer.modelutils.map.ElementUtils;
public class CellDesignerAliasConverter implements ICellDesignerAliasConverter<Element> { 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. * Class helping with transforming objectcs into meaningfull identifiers.
*/ */
private static ElementUtils eu = new ElementUtils(); 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());
}
/** /**
* 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 * @param element
* class type of element referenced by alias * element for which we are loooking for a converter
* @param converter * @param sbgn
* converter that should be used for conversion of this alias * 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) { private ICellDesignerAliasConverter<? extends Element> getConverterForAlias(Element element, boolean sbgn) {
elementConverters.put(clazz, converter); if (element == null) {
} throw new InvalidArgumentException("element cannot be null");
}
/** if (element instanceof Protein) {
* Returns a converter for given alias. If converter doesn't exist then null return new ProteinCellDesignerAliasConverter(sbgn);
* is returned. } else if (element instanceof Degraded) {
* return new DegradedCellDesignerAliasConverter(sbgn);
* @param alias } else if (element instanceof Complex) {
* alias for which we are loooking for a converter return new ComplexCellDesignerAliasConverter(sbgn);
* @return converter that can be applied for the given alias; null if such } else if (element instanceof SimpleMolecule) {
* converter doesn't exist return new SimpleMoleculeCellDesignerAliasConverter(sbgn);
*/ } else if (element instanceof Drug) {
private static ICellDesignerAliasConverter<? extends Element> getConverterForAlias(Element alias) { return new DrugCellDesignerAliasConverter(sbgn);
if (alias == null) { } else if (element instanceof Ion) {
throw new InvalidArgumentException("alias cannot be null"); 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") @SuppressWarnings("rawtypes")
private ICellDesignerAliasConverter converter = null; private ICellDesignerAliasConverter converter = null;
...@@ -119,32 +85,30 @@ public class CellDesignerAliasConverter implements ICellDesignerAliasConverter<E ...@@ -119,32 +85,30 @@ public class CellDesignerAliasConverter implements ICellDesignerAliasConverter<E
/** /**
* Default constructor. * Default constructor.
* *
* @param alias * @param sbgn
* alias for which this converter will be used * Should the converter use sbgn standard
* @param element
* element for which this converter will be used
*/ */
public CellDesignerAliasConverter(Element alias) { public CellDesignerAliasConverter(Element element, boolean sbgn) {
converter = getConverterForAlias(alias); converter = getConverterForAlias(element, sbgn);
// 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");
}
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public CellDesignerAnchor getAnchorForCoordinates(Element alias, Point2D point) { public CellDesignerAnchor getAnchorForCoordinates(Element element, Point2D point) {
return converter.getAnchorForCoordinates(alias, point); return converter.getAnchorForCoordinates(element, point);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Point2D getPointCoordinates(Element alias, CellDesignerAnchor anchor) { public Point2D getPointCoordinates(Element element, CellDesignerAnchor anchor) {
return converter.getPointCoordinates(alias, anchor); return converter.getPointCoordinates(element, anchor);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Point2D getAnchorPointCoordinates(Element alias, CellDesignerAnchor anchor, PolylineData line) { public Point2D getAnchorPointCoordinates(Element element, CellDesignerAnchor anchor, PolylineData line) {
return converter.getAnchorPointCoordinates(alias, anchor, line); return converter.getAnchorPointCoordinates(element, anchor, line);
} }
} }
...@@ -18,6 +18,16 @@ import lcsb.mapviewer.model.map.species.Complex; ...@@ -18,6 +18,16 @@ import lcsb.mapviewer.model.map.species.Complex;
*/ */
public class ComplexCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<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. * How big is the triangle trimmed part of the complex.
*/ */
......
...@@ -17,6 +17,16 @@ import lcsb.mapviewer.model.map.species.Species; ...@@ -17,6 +17,16 @@ import lcsb.mapviewer.model.map.species.Species;
*/ */
public class DegradedCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<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 * Part of height of the line used to cross degraded circle that goes behind
* this circle. * this circle.
......
...@@ -19,10 +19,21 @@ import lcsb.mapviewer.model.map.species.Species; ...@@ -19,10 +19,21 @@ import lcsb.mapviewer.model.map.species.Species;
* *
*/ */
public class DrugCellDesignerAliasConverter extends AbstractCellDesignerAliasConverter<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. * 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;