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

reaction line color is export/imported properly

parent e9f29204
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!452Resolve "Allow for color and line thickness control in the generated layout"
......@@ -100,7 +100,7 @@ public class SbmlBioEntityParser extends XmlParser {
* object role identifier
* @return {@link LocalStyle} from the layout data
*/
LocalStyle getStyleForRole(String objectRole) {
protected LocalStyle getStyleForRole(String objectRole) {
RenderLayoutPlugin renderPlugin = (RenderLayoutPlugin) layout.getExtension("render");
for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) {
for (LocalStyle style : lri.getListOfLocalStyles()) {
......@@ -112,7 +112,7 @@ public class SbmlBioEntityParser extends XmlParser {
return null;
}
Color getColorByColorDefinition(String fill) {
protected Color getColorByColorDefinition(String fill) {
RenderLayoutPlugin renderPlugin = (RenderLayoutPlugin) layout.getExtension("render");
for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) {
if (lri.getColorDefinition(fill) != null) {
......
......@@ -245,6 +245,12 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
}
}
LocalStyle style = createStyle(reaction);
ColorDefinition color = getColorDefinition(reaction.getReactants().get(0).getLine().getColor());
style.getGroup().setFill(color.getId());
assignStyleToGlyph(reactionGlyph, style);
}
private void addOperatorLineToGlyph(ReactionGlyph reactantGlyph, NodeOperator operator, boolean reverse) {
......
package lcsb.mapviewer.converter.model.sbml.reaction;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
......@@ -22,6 +23,9 @@ import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.ReactionGlyph;
import org.sbml.jsbml.ext.layout.SpeciesGlyph;
import org.sbml.jsbml.ext.layout.SpeciesReferenceGlyph;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderConstants;
import org.sbml.jsbml.ext.render.RenderGraphicalObjectPlugin;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
......@@ -41,6 +45,7 @@ import lcsb.mapviewer.model.map.kinetics.SbmlKinetics;
import lcsb.mapviewer.model.map.modifier.Inhibition;
import lcsb.mapviewer.model.map.modifier.Modulation;
import lcsb.mapviewer.model.map.modifier.Trigger;
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;
......@@ -56,8 +61,6 @@ import lcsb.mapviewer.modelutils.map.ElementUtils;
public class SbmlReactionParser extends SbmlBioEntityParser {
Logger logger = Logger.getLogger(SbmlReactionParser.class);
Layout layout;
lcsb.mapviewer.model.map.model.Model minervaModel;
ElementUtils eu = new ElementUtils();
......@@ -108,33 +111,7 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
for (SpeciesReferenceGlyph speciesRefernceGlyph : glyph.getListOfSpeciesReferenceGlyphs()) {
SpeciesGlyph speciesGlyph = layout.getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
ReactionNode minervaNode = null;
Class<? extends ReactionNode> nodeClass = null;
if (speciesRefernceGlyph.getRole() != null) {
switch (speciesRefernceGlyph.getRole()) {
case ACTIVATOR:
nodeClass = Trigger.class;
break;
case INHIBITOR:
nodeClass = Inhibition.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:
case MODIFIER:
nodeClass = null;
break;
}
}
Class<? extends ReactionNode> nodeClass = getReactionNodeClass(speciesRefernceGlyph);
if (reactionWithLayout.isReversible() && (nodeClass == Reactant.class || nodeClass == Product.class)) {
nodeClass = null;
......@@ -233,6 +210,8 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
operator.setLine(line);
reactionWithLayout.addNode(operator);
}
assignColorToReaction(glyph, reactionWithLayout);
minervaModel.addReaction(reactionWithLayout);
} catch (InvalidArgumentException e) {
throw new InvalidInputDataExecption(e);
......@@ -255,6 +234,54 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
}
}
private Class<? extends ReactionNode> getReactionNodeClass(SpeciesReferenceGlyph speciesRefernceGlyph) {
Class<? extends ReactionNode> nodeClass = null;
if (speciesRefernceGlyph.getRole() != null) {
switch (speciesRefernceGlyph.getRole()) {
case ACTIVATOR:
nodeClass = Trigger.class;
break;
case INHIBITOR:
nodeClass = Inhibition.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:
case MODIFIER:
nodeClass = null;
break;
}
}
return nodeClass;
}
private void assignColorToReaction(ReactionGlyph glyph, Reaction reactionWithLayout)
throws InvalidInputDataExecption {
RenderGraphicalObjectPlugin rgop = (RenderGraphicalObjectPlugin) glyph.getExtension(RenderConstants.shortLabel);
if (rgop != null) {
LocalStyle style = getStyleForRole(rgop.getObjectRole());
if (style == null) {
throw new InvalidInputDataExecption("Style " + rgop.getObjectRole() + " is not defined");
}
if (style.getGroup().getFill() != null) {
Color color = getColorByColorDefinition(style.getGroup().getFill());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setColor(color);
}
}
}
}
private PolylineData getLineFromReferenceGlyph(SpeciesReferenceGlyph speciesRefernceGlyph) {
PolylineData line = null;
for (CurveSegment segment : speciesRefernceGlyph.getCurve().getListOfCurveSegments()) {
......
......@@ -26,6 +26,7 @@ import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -285,4 +286,16 @@ public class SbmlExporterTest {
assertEquals(0, comparator.compare(model, model2));
}
@Test
public void testReactionColorParsing() throws Exception {
Model model = parser.createModel(new ConverterParams().filename("testFiles/layoutExample/example1.xml"));
for (Reaction element : model.getReactions()) {
for (AbstractNode node: element.getNodes()) {
node.getLine().setColor(Color.BLUE);
}
}
Model model2 = getModelAfterSerializing(model);
assertEquals(0, comparator.compare(model, model2));
}
}
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