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

errornous reaction catch

parent ba0545cb
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
......@@ -89,125 +89,124 @@ public class SbmlReactionParser {
throw new InvalidInputDataExecption("Layout contains invalid Species id: " + glyph.getReaction());
}
used.add(source);
Reaction reactionWithLayout = source.copy();
reactionWithLayout.setIdReaction(glyph.getId());
for (SpeciesReferenceGlyph speciesRefernceGlyph : glyph.getListOfSpeciesReferenceGlyphs()) {
SpeciesGlyph speciesGlyph = layout.getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
ReactionNode minervaNode = null;
Class<? extends ReactionNode> nodeClass = null;
switch (speciesRefernceGlyph.getRole()) {
case ACTIVATOR:
nodeClass = Trigger.class;
break;
case INHIBITOR:
nodeClass = Inhibition.class;
break;
case MODIFIER:
nodeClass = Modulation.class;
break;
case PRODUCT:
nodeClass = Product.class;
break;
case SIDEPRODUCT:
nodeClass = Product.class;
break;
case SIDESUBSTRATE:
nodeClass = Reactant.class;
break;
case SUBSTRATE:
nodeClass = Reactant.class;
break;
case UNDEFINED:
nodeClass = null;
break;
}
for (ReactionNode node : reactionWithLayout.getReactionNodes()) {
if (node.getElement().getElementId().equals(speciesGlyph.getSpecies())) {
if (nodeClass == null) {
minervaNode = node;
} else if (node.getClass().isAssignableFrom(nodeClass)) {
minervaNode = node;
try {
Reaction reactionWithLayout = source.copy();
reactionWithLayout.setIdReaction(glyph.getId());
for (SpeciesReferenceGlyph speciesRefernceGlyph : glyph.getListOfSpeciesReferenceGlyphs()) {
SpeciesGlyph speciesGlyph = layout.getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
ReactionNode minervaNode = null;
Class<? extends ReactionNode> nodeClass = null;
switch (speciesRefernceGlyph.getRole()) {
case ACTIVATOR:
nodeClass = Trigger.class;
break;
case INHIBITOR:
nodeClass = Inhibition.class;
break;
case MODIFIER:
nodeClass = Modulation.class;
break;
case PRODUCT:
nodeClass = Product.class;
break;
case SIDEPRODUCT:
nodeClass = Product.class;
break;
case SIDESUBSTRATE:
nodeClass = Reactant.class;
break;
case SUBSTRATE:
nodeClass = Reactant.class;
break;
case UNDEFINED:
nodeClass = null;
break;
}
for (ReactionNode node : reactionWithLayout.getReactionNodes()) {
if (node.getElement().getElementId().equals(speciesGlyph.getSpecies())) {
if (nodeClass == null) {
minervaNode = node;
} else if (node.getClass().isAssignableFrom(nodeClass)) {
minervaNode = node;
}
}
}
}
if (minervaNode == null) {
throw new InvalidInputDataExecption(
"Cannot find reaction node for layouted reaction: " + speciesGlyph.getSpecies() + ", " + glyph.getId());
}
Element minervaElement = minervaModel.getElementByElementId(speciesGlyph.getId());
if (minervaElement == null) {
throw new InvalidInputDataExecption("Cannot find layouted reaction node for layouted reaction: "
+ speciesGlyph.getId() + ", " + glyph.getId());
}
if (minervaNode == null) {
throw new InvalidInputDataExecption(
"Cannot find reaction node for layouted reaction: " + speciesGlyph.getSpecies() + ", " + glyph.getId());
}
Element minervaElement = minervaModel.getElementByElementId(speciesGlyph.getId());
if (minervaElement == null) {
throw new InvalidInputDataExecption("Cannot find layouted reaction node for layouted reaction: "
+ speciesGlyph.getId() + ", " + glyph.getId());
}
PolylineData line = null;
for (CurveSegment segment : speciesRefernceGlyph.getCurve().getListOfCurveSegments()) {
Point2D start = new Point2D.Double(segment.getStart().getX(), segment.getStart().getY());
Point2D end = new Point2D.Double(segment.getEnd().getX(), segment.getEnd().getY());
if (line == null) {
line = new PolylineData(start, end);
} else {
line.addPoint(end);
PolylineData line = null;
for (CurveSegment segment : speciesRefernceGlyph.getCurve().getListOfCurveSegments()) {
Point2D start = new Point2D.Double(segment.getStart().getX(), segment.getStart().getY());
Point2D end = new Point2D.Double(segment.getEnd().getX(), segment.getEnd().getY());
if (line == null) {
line = new PolylineData(start, end);
} else {
line.addPoint(end);
}
}
}
if (minervaNode instanceof Reactant) {
line = line.reverse();
}
if (minervaNode instanceof Product) {
ArrowTypeData atd = new ArrowTypeData();
atd.setArrowType(ArrowType.FULL);
line.setEndAtd(atd);
} else if (minervaNode instanceof Modifier) {
for (ModifierType mt : ModifierType.values()) {
if (mt.getClazz().equals(nodeClass)) {
line.setEndAtd(mt.getAtd());
line.setType(mt.getLineType());
if (minervaNode instanceof Reactant) {
line = line.reverse();
}
if (minervaNode instanceof Product) {
ArrowTypeData atd = new ArrowTypeData();
atd.setArrowType(ArrowType.FULL);
line.setEndAtd(atd);
} else if (minervaNode instanceof Modifier) {
for (ModifierType mt : ModifierType.values()) {
if (mt.getClazz().equals(nodeClass)) {
line.setEndAtd(mt.getAtd());
line.setType(mt.getLineType());
}
}
}
}
minervaNode.setLine(line);
minervaNode.setElement(minervaElement);
if (nodeClass != minervaNode.getClass()) {
reactionWithLayout.removeModifier((Modifier) minervaNode);
minervaNode.setLine(line);
minervaNode.setElement(minervaElement);
if (nodeClass != minervaNode.getClass()) {
reactionWithLayout.removeModifier((Modifier) minervaNode);
try {
ReactionNode newNode = nodeClass.getConstructor().newInstance();
newNode.setElement(minervaElement);
newNode.setLine(line);
reactionWithLayout.addNode(newNode);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new InvalidStateException(e);
try {
ReactionNode newNode = nodeClass.getConstructor().newInstance();
newNode.setElement(minervaElement);
newNode.setLine(line);
reactionWithLayout.addNode(newNode);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new InvalidStateException(e);
}
}
}
}
if (reactionWithLayout.getReactants().size()>1 && reactionWithLayout.getProducts().size()>0) {
PolylineData line = new PolylineData();
Point2D p1 = reactionWithLayout.getReactants().get(0).getLine().getEndPoint();
Point2D p2 = reactionWithLayout.getProducts().get(0).getLine().getBeginPoint();
Point2D center = new Point2D.Double((p1.getX()+p2.getX())/2, (p1.getY()+p2.getY())/2);
line.addPoint(p1);
line.addPoint(center);
NodeOperator operator = new AndOperator();
operator.addInputs(reactionWithLayout.getReactants());
operator.setLine(line);
reactionWithLayout.addNode(operator);
}
if (reactionWithLayout.getReactants().size()>0 && reactionWithLayout.getProducts().size()>1) {
PolylineData line = new PolylineData();
Point2D p1 = reactionWithLayout.getReactants().get(0).getLine().getEndPoint();
Point2D p2 = reactionWithLayout.getProducts().get(0).getLine().getBeginPoint();
Point2D center = new Point2D.Double((p1.getX()+p2.getX())/2, (p1.getY()+p2.getY())/2);
line.addPoint(p2);
line.addPoint(center);
NodeOperator operator = new SplitOperator();
operator.addOutputs(reactionWithLayout.getProducts());
operator.setLine(line);
reactionWithLayout.addNode(operator);
}
logger.debug(glyph.getCurve().getListOfCurveSegments().get(0));
try {
if (reactionWithLayout.getReactants().size() > 1 && reactionWithLayout.getProducts().size() > 0) {
PolylineData line = new PolylineData();
Point2D p1 = reactionWithLayout.getReactants().get(0).getLine().getEndPoint();
Point2D p2 = reactionWithLayout.getProducts().get(0).getLine().getBeginPoint();
Point2D center = new Point2D.Double((p1.getX() + p2.getX()) / 2, (p1.getY() + p2.getY()) / 2);
line.addPoint(p1);
line.addPoint(center);
NodeOperator operator = new AndOperator();
operator.addInputs(reactionWithLayout.getReactants());
operator.setLine(line);
reactionWithLayout.addNode(operator);
}
if (reactionWithLayout.getReactants().size() > 0 && reactionWithLayout.getProducts().size() > 1) {
PolylineData line = new PolylineData();
Point2D p1 = reactionWithLayout.getReactants().get(0).getLine().getEndPoint();
Point2D p2 = reactionWithLayout.getProducts().get(0).getLine().getBeginPoint();
Point2D center = new Point2D.Double((p1.getX() + p2.getX()) / 2, (p1.getY() + p2.getY()) / 2);
line.addPoint(p2);
line.addPoint(center);
NodeOperator operator = new SplitOperator();
operator.addOutputs(reactionWithLayout.getProducts());
operator.setLine(line);
reactionWithLayout.addNode(operator);
}
minervaModel.addReaction(new StateTransitionReaction(reactionWithLayout));
} catch (InvalidArgumentException e) {
throw new InvalidInputDataExecption(e);
......
package lcsb.mapviewer.converter.model.sbml;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ GenericSbmlParserTest.class, SbmlPareserForInvalidReactionTest.class, SbmlParserTest.class })
public class AllSbmlConverterTests {
}
......@@ -5,9 +5,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.awt.Desktop;
import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import org.apache.log4j.Logger;
......@@ -15,9 +13,6 @@ import org.junit.Test;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.NormalImageGenerator;
import lcsb.mapviewer.converter.graphics.PngImageGenerator;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -110,32 +105,34 @@ public class SbmlParserTest {
}
assertEquals(2, reaction.getOperators().size());
AbstractImageGenerator.Params params = new AbstractImageGenerator.Params().height(model.getHeight())
.width(model.getWidth()).nested(true).scale(1).level(20).x(0).y(0).model(model);
NormalImageGenerator nig = new PngImageGenerator(params);
nig.saveToFile("tmp.png");
Desktop.getDesktop().open(new File("tmp.png"));
// AbstractImageGenerator.Params params = new
// AbstractImageGenerator.Params().height(model.getHeight())
// .width(model.getWidth()).nested(true).scale(1).level(20).x(0).y(0).model(model);
// NormalImageGenerator nig = new PngImageGenerator(params);
// nig.saveToFile("tmp.png");
// Desktop.getDesktop().open(new File("tmp.png"));
}
@Test
public void testReactionWithoutLayout() throws Exception {
Model model = parser.createModel(new ConverterParams().filename("testFiles/layoutExample/Complete_Example_level2.xml"));
Model model = parser
.createModel(new ConverterParams().filename("testFiles/layoutExample/Complete_Example_level2.xml"));
assertNotNull(model);
assertEquals(1, model.getReactions().size());
Reaction reaction = model.getReactions().iterator().next();
for (ReactionNode node : reaction.getReactionNodes()) {
logger.debug(node.getClass()+","+node.getElement());
assertNotNull(node.getLine());
assertTrue(node.getLine().length() > 0);
}
assertEquals(2, reaction.getOperators().size());
AbstractImageGenerator.Params params = new AbstractImageGenerator.Params().height(model.getHeight())
.width(model.getWidth()).nested(true).scale(1).level(20).x(0).y(0).model(model);
NormalImageGenerator nig = new PngImageGenerator(params);
nig.saveToFile("tmp.png");
Desktop.getDesktop().open(new File("tmp.png"));
// AbstractImageGenerator.Params params = new
// AbstractImageGenerator.Params().height(model.getHeight())
// .width(model.getWidth()).nested(true).scale(1).level(20).x(0).y(0).model(model);
// NormalImageGenerator nig = new PngImageGenerator(params);
// nig.saveToFile("tmp.png");
// Desktop.getDesktop().open(new File("tmp.png"));
}
......
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