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

basic layout for reactions added

parent 7f88dcd6
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
package lcsb.mapviewer.converter.model.sbml;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
......@@ -22,10 +23,20 @@ import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.IConverter;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.model.celldesigner.types.ModifierType;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.AndOperator;
import lcsb.mapviewer.model.map.reaction.Modifier;
import lcsb.mapviewer.model.map.reaction.NodeOperator;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.SplitOperator;
import lcsb.mapviewer.model.map.species.Element;
public class SbmlParser implements IConverter {
......@@ -110,14 +121,18 @@ public class SbmlParser implements IConverter {
}
private void createLayout(Model model, Layout layout) {
for (Element element : model.getElements()) {
if (element.getWidth() == 0 || element.getHeight() == 0) {
element.setWidth(100);
element.setHeight(20);
Point coord = nextCoordinates();
element.setX(coord.x * 120);
element.setX(coord.y * 30);
element.setY(coord.y * 50);
}
}
for (Reaction reaction : model.getReactions()) {
if (!hasLayout(reaction)) {
createLayoutForReaction(reaction);
}
}
......@@ -149,6 +164,83 @@ public class SbmlParser implements IConverter {
model.setHeight(height);
}
private void createLayoutForReaction(Reaction reaction) {
Point2D reactantStartPoint = reaction.getReactants().get(0).getElement().getCenter();
Point2D productEndPoint = reaction.getProducts().get(0).getElement().getCenter();
Point2D center = new Point2D.Double((reactantStartPoint.getX() + productEndPoint.getX()) / 2,
(reactantStartPoint.getY() + productEndPoint.getY()) / 2);
Point2D reactantMergePoint = new Point2D.Double((reactantStartPoint.getX() + center.getX() * 3) / 4,
(reactantStartPoint.getY() + center.getY() * 3) / 4);
Point2D productMergePoint = new Point2D.Double((productEndPoint.getX() + center.getX() * 3) / 4,
(productEndPoint.getY() + center.getY() * 3) / 4);
if (reaction.getReactants().size()==1) {
PolylineData line = new PolylineData();
line.addPoint(reactantStartPoint);
line.addPoint(center);
reaction.getReactants().get(0).setLine(line);
} else {
for (Reactant reactant: reaction.getReactants()) {
PolylineData line = new PolylineData();
line.addPoint(reactantMergePoint);
line.addPoint(reactant.getElement().getCenter());
reactant.setLine(line);
}
NodeOperator operator = new AndOperator();
PolylineData line = new PolylineData();
line.addPoint(reactantMergePoint);
line.addPoint(center);
operator.addInputs(reaction.getReactants());
operator.setLine(line);
reaction.addNode(operator);
}
if (reaction.getProducts().size()==1) {
PolylineData line = new PolylineData();
line.addPoint(productEndPoint);
line.addPoint(center);
reaction.getProducts().get(0).setLine(line);
} else {
for (Product product: reaction.getProducts()) {
PolylineData line = new PolylineData();
line.addPoint(product.getElement().getCenter());
line.addPoint(productMergePoint);
product.setLine(line);
}
NodeOperator operator = new SplitOperator();
PolylineData line = new PolylineData();
line.addPoint(productMergePoint);
line.addPoint(center);
operator.addOutputs(reaction.getProducts());
operator.setLine(line);
reaction.addNode(operator);
}
for (Modifier modifier: reaction.getModifiers()) {
PolylineData line = new PolylineData();
line.addPoint(modifier.getElement().getCenter());
line.addPoint(center);
modifier.setLine(line);
if (modifier.getClass()==Modifier.class) {
line.setEndAtd(ModifierType.MODULATION_STRING.getAtd());
}
}
}
private boolean hasLayout(Reaction reaction) {
for (AbstractNode node : reaction.getNodes()) {
if (node.getLine() == null) {
return false;
} else if (node.getLine().length() == 0) {
return false;
}
}
return true;
}
Point coordinates = null;
int radius = 0;
......@@ -174,6 +266,7 @@ public class SbmlParser implements IConverter {
private Layout getSbmlLayout(org.sbml.jsbml.Model sbmlModel) {
Layout layout = null;
if (sbmlModel.getExtensionCount() > 0) {
for (SBasePlugin plugin : sbmlModel.getExtensionPackages().values()) {
if (plugin.getClass().equals(org.sbml.jsbml.ext.layout.LayoutModelPlugin.class)) {
......
......@@ -227,7 +227,7 @@ public class SbmlReactionParser {
}
protected Reaction parse(org.sbml.jsbml.Reaction sbmlReaction, Model sbmlModel) throws InvalidInputDataExecption {
Reaction reaction = new Reaction();
Reaction reaction = new StateTransitionReaction();
reaction.setIdReaction(sbmlReaction.getId());
if (sbmlReaction.getKineticLaw() != null) {
throw new NotImplementedException("KineticLaw not implemented");
......
......@@ -108,7 +108,28 @@ public class SbmlParserTest {
assertNotNull(node.getLine());
assertTrue(node.getLine().length() > 0);
}
// assertEquals(2, reaction.getOperators().size());
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"));
}
@Test
public void testReactionWithoutLayout() throws Exception {
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);
......
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2" level="2" version="1">
<model id="TestModel_with_modifiers">
<annotation>
<listOfLayouts xmlns="http://projects.eml.org/bcb/sbml/level2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<layout id="Layout_1">
<dimensions width="400" height="230"/>
<listOfCompartmentGlyphs>
<compartmentGlyph id="CompartmentGlyph_1" compartment="Yeast">
<boundingBox id="bb1">
<position x="5" y="5"/>
<dimensions width="390" height="220"/>
</boundingBox>
</compartmentGlyph>
</listOfCompartmentGlyphs>
<listOfSpeciesGlyphs>
<speciesGlyph id="SpeciesGlyph_Glucose" species="Glucose">
<boundingBox id="bb2">
<position x="105" y="20"/>
<dimensions width="130" height="20"/>
</boundingBox>
</speciesGlyph>
<speciesGlyph id="SpeciesGlyph_G6P" species="G6P">
<boundingBox id="bb5">
<position x="50" y="190"/>
<dimensions width="270" height="20"/>
</boundingBox>
</speciesGlyph>
<speciesGlyph id="SpeciesGlyph_ATP" species="ATP">
<boundingBox id="bb3">
<position x="270" y="70"/>
<dimensions width="80" height="20"/>
</boundingBox>
</speciesGlyph>
<speciesGlyph id="glyph_ADP" species="ADP">
<boundingBox id="bb4">
<position x="270" y="140"/>
<dimensions width="80" height="20"/>
</boundingBox>
</speciesGlyph>
<speciesGlyph id="SpeciesGlyph_Pi" species="Pi">
<boundingBox id="bb6">
<position x="50" y="100"/>
<dimensions width="60" height="20"/>
</boundingBox>
</speciesGlyph>
</listOfSpeciesGlyphs>
<listOfReactionGlyphs>
<reactionGlyph id="glyph_Hexokinase" reaction="Hexokinase">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="LineSegment">
<start x="170" y="100"/>
<end x="170" y="130"/>
</curveSegment>
</listOfCurveSegments>
</curve>
<listOfSpeciesReferenceGlyphs>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_Glucose"
speciesReference="SpeciesReference_Glucose"
speciesGlyph="SpeciesGlyph_Glucose" role="substrate">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="LineSegment">
<start x="170" y="100"/>
<end x="170" y="50"/>
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_ATP"
speciesReference="SpeciesReference_ATP"
speciesGlyph="SpeciesGlyph_ATP" role="sidesubstrate">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="170" y="100"/>
<end x="260" y="80"/>
<basePoint1 x="170" y="80"/>
<basePoint2 x="170" y="80"/>
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_G6P_1"
speciesReference="SpeciesReference_G6P"
speciesGlyph="SpeciesGlyph_G6P" role="product">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="LineSegment">
<start x="170" y="130"/>
<end x="170" y="180"/>
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_ADP"
speciesReference="SpeciesReference_ADP"
speciesGlyph="glyph_ADP" role="sideproduct">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="170" y="130"/>
<end x="260" y="150"/>
<basePoint1 x="170" y="150"/>
<basePoint2 x="170" y="150"/>
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_G6P_2"
speciesReference="ModifierSpeciesReference_G6P"
speciesGlyph="SpeciesGlyph_G6P" role="inhibitor">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="45" y="200"/>
<end x="165" y="120"/>
<basePoint1 x="0" y="200"/>
<basePoint2 x="0" y="120"/>
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_PI"
speciesReference="ModifierSpeciesReference_Pi"
speciesGlyph="SpeciesGlyph_Pi" role="activator">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="115" y="110"/>
<end x="165" y="110"/>
<basePoint1 x="140" y="110"/>
<basePoint2 x="140" y="110"/>
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
</listOfSpeciesReferenceGlyphs>
</reactionGlyph>
</listOfReactionGlyphs>
<listOfTextGlyphs>
<textGlyph id="TextGlyph_Glucose" graphicalObject="SpeciesGlyph_Glucose"
originOfText="Glucose">
<boundingBox id="bbA">
<position x="115" y="20"/>
<dimensions width="110" height="20"/>
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_G6P" graphicalObject="SpeciesGlyph_G6P"
originOfText="G6P">
<boundingBox id="bbD">
<position x="60" y="190"/>
<dimensions width="250" height="20"/>
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_ATP" graphicalObject="SpeciesGlyph_ATP"
originOfText="ATP">
<boundingBox id="bbB">
<position x="280" y="70"/>
<dimensions width="60" height="20"/>
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_ADP" graphicalObject="glyph_ADP"
originOfText="ADP">
<boundingBox id="bbC">
<position x="280" y="140"/>
<dimensions width="60" height="20"/>
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_PI" graphicalObject="SpeciesGlyph_Pi"
originOfText="Pi">
<boundingBox id="bbE">
<position x="60" y="100"/>
<dimensions width="40" height="20"/>
</boundingBox>
</textGlyph>
</listOfTextGlyphs>
</layout>
</listOfLayouts>
</annotation>
<listOfCompartments>
<compartment id="Yeast"/>
</listOfCompartments>
<listOfSpecies>
<species id="Glucose" compartment="Yeast"/>
<species id="G6P" name="Glucose-6-phosphate" compartment="Yeast"/>
<species id="ATP" compartment="Yeast"/>
<species id="ADP" compartment="Yeast"/>
<species id="Pi" compartment="Yeast"/>
</listOfSpecies>
<listOfReactions>
<reaction id="Hexokinase" reversible="false">
<listOfReactants>
<speciesReference species="Glucose">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_Glucose"/>
</annotation>
</speciesReference>
<speciesReference species="ATP">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_ATP"/>
</annotation>
</speciesReference>
</listOfReactants>
<listOfProducts>
<speciesReference species="G6P">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_G6P"/>
</annotation>
</speciesReference>
<speciesReference species="ADP">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_ADP"/>
</annotation>
</speciesReference>
</listOfProducts>
<listOfModifiers>
<modifierSpeciesReference species="G6P">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="ModifierSpeciesReference_G6P"/>
</annotation>
</modifierSpeciesReference>
<modifierSpeciesReference species="Pi">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="ModifierSpeciesReference_Pi"/>
</annotation>
</modifierSpeciesReference>
</listOfModifiers>
</reaction>
</listOfReactions>
</model>
<model id="TestModel_with_modifiers">
<annotation>
<listOfLayouts xmlns="http://projects.eml.org/bcb/sbml/level2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<layout id="Layout_1">
<dimensions width="400" height="230" />
<listOfCompartmentGlyphs>
<compartmentGlyph id="CompartmentGlyph_1"
compartment="Yeast">
<boundingBox id="bb1">
<position x="5" y="5" />
<dimensions width="390" height="220" />
</boundingBox>
</compartmentGlyph>
</listOfCompartmentGlyphs>
<listOfSpeciesGlyphs>
<speciesGlyph id="SpeciesGlyph_Glucose" species="Glucose">
<boundingBox id="bb2">
<position x="105" y="20" />
<dimensions width="130" height="20" />
</boundingBox>
</speciesGlyph>
<speciesGlyph id="SpeciesGlyph_G6P" species="G6P">
<boundingBox id="bb5">
<position x="50" y="190" />
<dimensions width="270" height="20" />
</boundingBox>
</speciesGlyph>
<speciesGlyph id="SpeciesGlyph_ATP" species="ATP">
<boundingBox id="bb3">
<position x="270" y="70" />
<dimensions width="80" height="20" />
</boundingBox>
</speciesGlyph>
<speciesGlyph id="glyph_ADP" species="ADP">
<boundingBox id="bb4">
<position x="270" y="140" />
<dimensions width="80" height="20" />
</boundingBox>
</speciesGlyph>
<speciesGlyph id="SpeciesGlyph_Pi" species="Pi">
<boundingBox id="bb6">
<position x="50" y="100" />
<dimensions width="60" height="20" />
</boundingBox>
</speciesGlyph>
</listOfSpeciesGlyphs>
<listOfReactionGlyphs>
<reactionGlyph id="glyph_Hexokinase" reaction="Hexokinase">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="LineSegment">
<start x="170" y="100" />
<end x="170" y="130" />
</curveSegment>
</listOfCurveSegments>
</curve>
<listOfSpeciesReferenceGlyphs>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_Glucose"
speciesReference="SpeciesReference_Glucose" speciesGlyph="SpeciesGlyph_Glucose"
role="substrate">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="LineSegment">
<start x="170" y="100" />
<end x="170" y="50" />
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_ATP"
speciesReference="SpeciesReference_ATP" speciesGlyph="SpeciesGlyph_ATP"
role="sidesubstrate">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="170" y="100" />
<end x="260" y="80" />
<basePoint1 x="170" y="80" />
<basePoint2 x="170" y="80" />
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_G6P_1"
speciesReference="SpeciesReference_G6P" speciesGlyph="SpeciesGlyph_G6P"
role="product">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="LineSegment">
<start x="170" y="130" />
<end x="170" y="180" />
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_ADP"
speciesReference="SpeciesReference_ADP" speciesGlyph="glyph_ADP"
role="sideproduct">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="170" y="130" />
<end x="260" y="150" />
<basePoint1 x="170" y="150" />
<basePoint2 x="170" y="150" />
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_G6P_2"
speciesReference="ModifierSpeciesReference_G6P" speciesGlyph="SpeciesGlyph_G6P"
role="inhibitor">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="45" y="200" />
<end x="165" y="120" />
<basePoint1 x="0" y="200" />
<basePoint2 x="0" y="120" />
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
<speciesReferenceGlyph id="SpeciesReferenceGlyph_PI"
speciesReference="ModifierSpeciesReference_Pi" speciesGlyph="SpeciesGlyph_Pi"
role="activator">
<curve>
<listOfCurveSegments>
<curveSegment xsi:type="CubicBezier">
<start x="115" y="110" />
<end x="165" y="110" />
<basePoint1 x="140" y="110" />
<basePoint2 x="140" y="110" />
</curveSegment>
</listOfCurveSegments>
</curve>
</speciesReferenceGlyph>
</listOfSpeciesReferenceGlyphs>
</reactionGlyph>
</listOfReactionGlyphs>
<listOfTextGlyphs>
<textGlyph id="TextGlyph_Glucose" graphicalObject="SpeciesGlyph_Glucose"
originOfText="Glucose">
<boundingBox id="bbA">
<position x="115" y="20" />
<dimensions width="110" height="20" />
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_G6P" graphicalObject="SpeciesGlyph_G6P"
originOfText="G6P">
<boundingBox id="bbD">
<position x="60" y="190" />
<dimensions width="250" height="20" />
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_ATP" graphicalObject="SpeciesGlyph_ATP"
originOfText="ATP">
<boundingBox id="bbB">
<position x="280" y="70" />
<dimensions width="60" height="20" />
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_ADP" graphicalObject="glyph_ADP"
originOfText="ADP">
<boundingBox id="bbC">
<position x="280" y="140" />
<dimensions width="60" height="20" />
</boundingBox>
</textGlyph>
<textGlyph id="TextGlyph_PI" graphicalObject="SpeciesGlyph_Pi"
originOfText="Pi">
<boundingBox id="bbE">
<position x="60" y="100" />
<dimensions width="40" height="20" />
</boundingBox>
</textGlyph>
</listOfTextGlyphs>
</layout>
</listOfLayouts>
</annotation>
<listOfCompartments>
<compartment id="Yeast" />
</listOfCompartments>
<listOfSpecies>
<species id="Glucose" compartment="Yeast" />
<species id="G6P" name="Glucose-6-phosphate" compartment="Yeast" />
<species id="ATP" compartment="Yeast" />
<species id="ADP" compartment="Yeast" />
<species id="Pi" compartment="Yeast" />
</listOfSpecies>
<listOfReactions>
<reaction id="Hexokinase" reversible="false">
<listOfReactants>
<speciesReference species="Glucose">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_Glucose" />
</annotation>
</speciesReference>
<speciesReference species="ATP">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_ATP" />
</annotation>
</speciesReference>
</listOfReactants>
<listOfProducts>
<speciesReference species="G6P">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_G6P" />
</annotation>
</speciesReference>
<speciesReference species="ADP">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="SpeciesReference_ADP" />
</annotation>
</speciesReference>
</listOfProducts>
<listOfModifiers>
<modifierSpeciesReference species="G6P">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="ModifierSpeciesReference_G6P" />
</annotation>
</modifierSpeciesReference>
<modifierSpeciesReference species="Pi">
<annotation>
<layoutId xmlns="http://projects.eml.org/bcb/sbml/level2"
id="ModifierSpeciesReference_Pi" />
</annotation>
</modifierSpeciesReference>
</listOfModifiers>
</reaction>
</listOfReactions>
</model>
</sbml>
\ No newline at end of file
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