Skip to content
Snippets Groups Projects
Commit d5e5d509 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

export of reaction layout added

parent 97f0c33a
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
...@@ -3,6 +3,7 @@ package lcsb.mapviewer.converter.model.sbml; ...@@ -3,6 +3,7 @@ package lcsb.mapviewer.converter.model.sbml;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
...@@ -18,6 +19,7 @@ import org.sbml.jsbml.ext.layout.ReactionGlyph; ...@@ -18,6 +19,7 @@ import org.sbml.jsbml.ext.layout.ReactionGlyph;
import org.sbml.jsbml.ext.layout.SpeciesReferenceGlyph; import org.sbml.jsbml.ext.layout.SpeciesReferenceGlyph;
import org.sbml.jsbml.ext.layout.SpeciesReferenceRole; import org.sbml.jsbml.ext.layout.SpeciesReferenceRole;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.modifier.Inhibition; import lcsb.mapviewer.model.map.modifier.Inhibition;
import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.reaction.Modifier;
...@@ -41,12 +43,12 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb ...@@ -41,12 +43,12 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
@Override @Override
public org.sbml.jsbml.Reaction createSbmlElement(Reaction reaction) throws InconsistentModelException { public org.sbml.jsbml.Reaction createSbmlElement(Reaction reaction) throws InconsistentModelException {
String reactionId = getReactionId(reaction); String reactionId = getReactionId(reaction);
logger.debug(reactionId);
org.sbml.jsbml.Reaction result = super.sbmlElementByElementId.get(reactionId); org.sbml.jsbml.Reaction result = super.sbmlElementByElementId.get(reactionId);
if (result != null) { if (result != null) {
return result; return result;
} }
result = sbmlModel.createReaction(reactionId); result = sbmlModel.createReaction(reactionId);
result.setReversible(reaction.isReversible());
for (Product product : reaction.getProducts()) { for (Product product : reaction.getProducts()) {
Species sbmlSymbol = speciesExporter.sbmlElementByElementId.get(product.getElement().getElementId()); Species sbmlSymbol = speciesExporter.sbmlElementByElementId.get(product.getElement().getElementId());
SpeciesReference speciesReference = result.createProduct(sbmlSymbol); SpeciesReference speciesReference = result.createProduct(sbmlSymbol);
...@@ -79,7 +81,6 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb ...@@ -79,7 +81,6 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
if (separatorIndex > 0) { if (separatorIndex > 0) {
glyphId = glyphId.substring(separatorIndex + 2); glyphId = glyphId.substring(separatorIndex + 2);
} }
logger.debug(glyphId);
ReactionGlyph reactionGlyph; ReactionGlyph reactionGlyph;
try { try {
// handle case when input data cannot doesn't come from SBML parser and contains // handle case when input data cannot doesn't come from SBML parser and contains
...@@ -135,18 +136,24 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb ...@@ -135,18 +136,24 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
private SpeciesReferenceGlyph createNodeGlyph(ReactionGlyph reactionGlyph, ReactionNode node) { private SpeciesReferenceGlyph createNodeGlyph(ReactionGlyph reactionGlyph, ReactionNode node) {
SpeciesReferenceGlyph reactantGlyph = reactionGlyph.createSpeciesReferenceGlyph("node_" + getNextId()); SpeciesReferenceGlyph reactantGlyph = reactionGlyph.createSpeciesReferenceGlyph("node_" + getNextId());
reactantGlyph.setSpeciesGlyph(speciesExporter.sbmlGlyphByElementId.get(node.getElement().getElementId()).getId()); reactantGlyph.setSpeciesGlyph(speciesExporter.sbmlGlyphByElementId.get(node.getElement().getElementId()).getId());
reactantGlyph.setCurve(createCurve(node)); reactantGlyph.setCurve(createCurve(node, node instanceof Reactant));
reactantGlyph.setSpeciesReference(speciesReferenceByReactionNode.get(node)); reactantGlyph.setSpeciesReference(speciesReferenceByReactionNode.get(node));
return reactantGlyph; return reactantGlyph;
} }
private Curve createCurve(ReactionNode reactant) { private Curve createCurve(ReactionNode reactant, boolean reverse) {
Curve curve = new Curve(); Curve curve = new Curve();
for (Line2D line : reactant.getLine().getLines()) { List<Line2D> lines = reactant.getLine().getLines();
LineSegment segment = new LineSegment(); if (reverse) {
segment.setStart(new Point(line.getX1(), line.getY1())); lines = reactant.getLine().reverse().getLines();
segment.setEnd(new Point(line.getX2(), line.getY2())); }
curve.addCurveSegment(segment); for (Line2D line : lines) {
if (line.getP1().distance(line.getP2())>Configuration.EPSILON) {
LineSegment segment = new LineSegment();
segment.setStart(new Point(line.getX1(), line.getY1()));
segment.setEnd(new Point(line.getX2(), line.getY2()));
curve.addCurveSegment(segment);
}
} }
return curve; return curve;
} }
......
...@@ -231,14 +231,6 @@ public class SbmlExporterTest { ...@@ -231,14 +231,6 @@ public class SbmlExporterTest {
Model model2 = converter.createModel(new ConverterParams().filename("tmp.xml")); Model model2 = converter.createModel(new ConverterParams().filename("tmp.xml"));
model2.setName(null); model2.setName(null);
for (Reaction r: model.getReactions()) {
logger.debug(r.getIdReaction());
}
logger.debug("---");
for (Reaction r: model2.getReactions()) {
logger.debug(r.getIdReaction());
}
assertNotNull(model2); assertNotNull(model2);
ModelComparator comparator = new ModelComparator(1.0); ModelComparator comparator = new ModelComparator(1.0);
......
...@@ -17,115 +17,127 @@ import lcsb.mapviewer.common.exception.NotImplementedException; ...@@ -17,115 +17,127 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
* *
*/ */
public class PolylineDataComparator implements Comparator<PolylineData> { public class PolylineDataComparator implements Comparator<PolylineData> {
/** /**
* Default class logger. * Default class logger.
*/ */
private Logger logger = Logger.getLogger(PolylineDataComparator.class); private Logger logger = Logger.getLogger(PolylineDataComparator.class);
/** /**
* Epsilon value used for comparison of doubles. * Epsilon value used for comparison of doubles.
*/ */
private double epsilon; private double epsilon;
/** /**
* Constructor that requires {@link #epsilon} parameter. * Constructor that requires {@link #epsilon} parameter.
* *
* @param epsilon * @param epsilon
* {@link #epsilon} * {@link #epsilon}
*/ */
public PolylineDataComparator(double epsilon) { public PolylineDataComparator(double epsilon) {
this.epsilon = epsilon; this.epsilon = epsilon;
} }
/** /**
* Default constructor. * Default constructor.
*/ */
public PolylineDataComparator() { public PolylineDataComparator() {
this(Configuration.EPSILON); this(Configuration.EPSILON);
} }
@Override @Override
public int compare(PolylineData arg0, PolylineData arg1) { public int compare(PolylineData arg0, PolylineData arg1) {
if (arg0 == null) { if (arg0 == null) {
if (arg1 == null) { if (arg1 == null) {
return 0; return 0;
} else { } else {
return 1; return 1;
} }
} else if (arg1 == null) { } else if (arg1 == null) {
return -1; return -1;
} }
if (arg0.getClass().equals(arg1.getClass())) { if (arg0.getClass().equals(arg1.getClass())) {
if (arg0.getClass().equals(PolylineData.class)) { if (arg0.getClass().equals(PolylineData.class)) {
return internalCompare(arg0, arg1); return internalCompare(arg0, arg1);
} else { } else {
throw new NotImplementedException("Don't know how to compare classes: " + arg0.getClass()); throw new NotImplementedException("Don't know how to compare classes: " + arg0.getClass());
} }
} else { } else {
return -1; return -1;
} }
} }
/** /**
* This method compares only the fields that are defined in * This method compares only the fields that are defined in {@link PolylineData}
* {@link PolylineData} class in inheritence tree. * class in inheritance tree.
* *
* @param arg0 * @param arg0
* first object to compare * first object to compare
* @param arg1 * @param arg1
* second object to compare * second object to compare
* @return if all fields are qual then returns 0. If they are different then * @return if all fields are equal then returns 0. If they are different then
* -1/1 is returned. * -1/1 is returned.
*/ */
private int internalCompare(PolylineData arg0, PolylineData arg1) { private int internalCompare(PolylineData arg0, PolylineData arg1) {
IntegerComparator integerComparator = new IntegerComparator(); IntegerComparator integerComparator = new IntegerComparator();
DoubleComparator doubleComparator = new DoubleComparator(epsilon); DoubleComparator doubleComparator = new DoubleComparator(epsilon);
ArrowTypeDataComparator atdComparator = new ArrowTypeDataComparator(epsilon); ArrowTypeDataComparator atdComparator = new ArrowTypeDataComparator(epsilon);
if (integerComparator.compare(arg0.getPoints().size(), arg1.getPoints().size()) != 0) { int different1=0;
logger.debug("Lines have different size: " + arg0.getPoints().size() + ", " + arg1.getPoints().size()); int different2=0;
return integerComparator.compare(arg0.getPoints().size(), arg1.getPoints().size()); for (int i=1;i<arg0.getPoints().size();i++) {
} if (arg0.getPoints().get(i).distance(arg0.getPoints().get(i-1))>Configuration.EPSILON) {
// TODO this should be fixed different1++;
// for (int i = 0; i < arg0.getPoints().size(); i++) { }
// if }
// (doubleComparator.compare(arg0.getPoints().get(i).distanceSq(arg1.getPoints().get(i)), for (int i=1;i<arg1.getPoints().size();i++) {
// 0.0) != 0) { if (arg1.getPoints().get(i).distance(arg1.getPoints().get(i-1))>Configuration.EPSILON) {
// logger.debug("Lines have different points: " + arg0.getPoints().get(i) + different2++;
// ", " + arg1.getPoints().get(i)); }
// return }
// doubleComparator.compare(arg0.getPoints().get(i).distanceSq(arg1.getPoints().get(i)), if (integerComparator.compare(different1, different2) != 0) {
// 0.0); logger.debug("Lines have different size: " + different1 + ", " + different2);
// } return integerComparator.compare(arg0.getPoints().size(), arg1.getPoints().size());
// } }
// TODO this should be fixed
if (atdComparator.compare(arg0.getBeginAtd(), arg1.getBeginAtd()) != 0) { // for (int i = 0; i < arg0.getPoints().size(); i++) {
logger.debug("Lines have different begin adt: " + arg0.getBeginAtd() + ", " + arg1.getBeginAtd()); // if
return atdComparator.compare(arg0.getBeginAtd(), arg1.getBeginAtd()); // (doubleComparator.compare(arg0.getPoints().get(i).distanceSq(arg1.getPoints().get(i)),
} // 0.0) != 0) {
// logger.debug("Lines have different points: " + arg0.getPoints().get(i) +
if (atdComparator.compare(arg0.getEndAtd(), arg1.getEndAtd()) != 0) { // ", " + arg1.getPoints().get(i));
logger.debug("Lines have different end adt: " + arg0.getEndAtd() + ", " + arg1.getEndAtd()); // return
return atdComparator.compare(arg0.getEndAtd(), arg1.getEndAtd()); // doubleComparator.compare(arg0.getPoints().get(i).distanceSq(arg1.getPoints().get(i)),
} // 0.0);
// }
if (doubleComparator.compare(arg0.getWidth(), arg1.getWidth()) != 0) { // }
logger.debug("Lines have different width: " + arg0.getWidth() + ", " + arg1.getWidth());
return doubleComparator.compare(arg0.getWidth(), arg1.getWidth()); if (atdComparator.compare(arg0.getBeginAtd(), arg1.getBeginAtd()) != 0) {
} logger.debug("Lines have different begin adt: " + arg0.getBeginAtd() + ", " + arg1.getBeginAtd());
return atdComparator.compare(arg0.getBeginAtd(), arg1.getBeginAtd());
if (integerComparator.compare(arg0.getColor().getRGB(), arg1.getColor().getRGB()) != 0) { }
logger.debug("Lines have different color: " + arg0.getColor() + ", " + arg1.getColor());
return integerComparator.compare(arg0.getColor().getRGB(), arg1.getColor().getRGB()); if (atdComparator.compare(arg0.getEndAtd(), arg1.getEndAtd()) != 0) {
} logger.debug("Lines have different end adt: " + arg0.getEndAtd() + ", " + arg1.getEndAtd());
return atdComparator.compare(arg0.getEndAtd(), arg1.getEndAtd());
if (arg0.getType().compareTo(arg1.getType()) != 0) { }
logger.debug("Lines have different type: " + arg0.getType() + ", " + arg1.getType());
return arg0.getType().compareTo(arg1.getType()); if (doubleComparator.compare(arg0.getWidth(), arg1.getWidth()) != 0) {
} logger.debug("Lines have different width: " + arg0.getWidth() + ", " + arg1.getWidth());
return doubleComparator.compare(arg0.getWidth(), arg1.getWidth());
return 0; }
}
if (integerComparator.compare(arg0.getColor().getRGB(), arg1.getColor().getRGB()) != 0) {
logger.debug("Lines have different color: " + arg0.getColor() + ", " + arg1.getColor());
return integerComparator.compare(arg0.getColor().getRGB(), arg1.getColor().getRGB());
}
if (arg0.getType().compareTo(arg1.getType()) != 0) {
logger.debug("Lines have different type: " + arg0.getType() + ", " + arg1.getType());
return arg0.getType().compareTo(arg1.getType());
}
return 0;
}
} }
...@@ -58,7 +58,7 @@ public class AbstractNodeComparator implements Comparator<AbstractNode> { ...@@ -58,7 +58,7 @@ public class AbstractNodeComparator implements Comparator<AbstractNode> {
// now check class types // now check class types
if (arg0.getClass().equals(arg1.getClass())) { if (arg0.getClass().equals(arg1.getClass())) {
// and call comparator of apropriate subclass // and call comparator of appropriate subclass
if (arg0 instanceof NodeOperator) { if (arg0 instanceof NodeOperator) {
NodeOperatorComparator nodeOperatorComparator = new NodeOperatorComparator(epsilon); NodeOperatorComparator nodeOperatorComparator = new NodeOperatorComparator(epsilon);
return nodeOperatorComparator.compare((NodeOperator) arg0, (NodeOperator) arg1); return nodeOperatorComparator.compare((NodeOperator) arg0, (NodeOperator) arg1);
...@@ -75,13 +75,13 @@ public class AbstractNodeComparator implements Comparator<AbstractNode> { ...@@ -75,13 +75,13 @@ public class AbstractNodeComparator implements Comparator<AbstractNode> {
/** /**
* This method compares only the fields that are defined in AbstractNode class * This method compares only the fields that are defined in AbstractNode class
* in inheritence tree. By the design it is called by subclass comparator. * in inheritance tree. By the design it is called by subclass comparator.
* *
* @param arg0 * @param arg0
* first object to compare * first object to compare
* @param arg1 * @param arg1
* second object to compare * second object to compare
* @return if all fields are qual then returns 0. If they are different then * @return if all fields are equal then returns 0. If they are different then
* -1/1 is returned. * -1/1 is returned.
*/ */
protected int internalCompare(AbstractNode arg0, AbstractNode arg1) { protected int internalCompare(AbstractNode arg0, AbstractNode arg1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment