Commit c4a9b6db authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'master' into multithread-test-issue

parents 6a0c4f10 e03ef028
Pipeline #6762 passed with stage
in 9 minutes and 37 seconds
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lcsb.mapviewer</groupId>
......@@ -28,7 +30,7 @@
</repositories>
<build>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
......@@ -46,7 +48,7 @@
</executions>
</plugin>
</plugins>
</build>
</build>
<dependencies>
......
......@@ -160,7 +160,11 @@ public class RestAnnotationParser extends XmlParser {
return "";
}
} else if (value instanceof String) {
if (!((String) value).trim().isEmpty() || forceFullInfo) {
return type.getCommonName() + ": " + value + "\n";
} else {
return "";
}
} else if (value instanceof Integer) {
return type.getCommonName() + ": " + value + "\n";
} else if (value instanceof Collection) {
......@@ -350,7 +354,7 @@ public class RestAnnotationParser extends XmlParser {
logger.debug("Y");
notes = notes.substring(notes.indexOf("</head>") + "</head>".length());
}
notes = notes.replace("xmlns=\"http://www.w3.org/1999/xhtml\"","");
notes = notes.replace("xmlns=\"http://www.w3.org/1999/xhtml\"", "");
return notes.replaceAll("&amp;", "&");
}
......
......@@ -76,9 +76,52 @@
<dependency>
<groupId>org.sbml.jsbml</groupId>
<artifactId>jsbml</artifactId>
<version>1.3.1</version>
<version>${jsbml.version}</version>
<!-- for now we use lower version of log4j and this one introduce some
problem with tomcat loggin -->
problem with tomcat logging -->
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
</exclusion>
<!-- https://github.com/sbmlteam/jsbml/issues/156 -->
<exclusion>
<groupId>org.sbml.jsbml</groupId>
<artifactId>jsbml-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sbml.jsbml</groupId>
<artifactId>jsbml-core</artifactId>
<version>${jsbml.version}</version>
<!-- for now we use lower version of log4j and this one introduce some
problem with tomcat logging -->
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
......
package lcsb.mapviewer.converter.model.sbml;
import java.awt.Color;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
......@@ -11,6 +12,13 @@ import org.apache.log4j.Logger;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.render.ColorDefinition;
import org.sbml.jsbml.ext.render.LocalRenderInformation;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderConstants;
import org.sbml.jsbml.ext.render.RenderGraphicalObjectPlugin;
import org.sbml.jsbml.ext.render.RenderGroup;
import org.sbml.jsbml.ext.render.RenderLayoutPlugin;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidStateException;
......@@ -116,6 +124,13 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
this.layout = layout;
}
protected RenderLayoutPlugin getRenderPlugin() {
if (layout.getExtensionCount() > 0) {
return (RenderLayoutPlugin) layout.getExtension("render");
}
return null;
}
protected lcsb.mapviewer.model.map.model.Model getMinervaModel() {
return minervaModel;
}
......@@ -132,4 +147,47 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
return sbmlGlyphByElementId.get(elementId);
}
protected ColorDefinition getColorDefinition(Color color) {
RenderLayoutPlugin renderPlugin = getRenderPlugin();
LocalRenderInformation renderInformation = null;
for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) {
if (lri.getId().equals("minerva_definitions")) {
renderInformation = lri;
}
}
if (renderInformation == null) {
renderInformation = new LocalRenderInformation("minerva_definitions");
renderPlugin.addLocalRenderInformation(renderInformation);
}
for (ColorDefinition cd : renderInformation.getListOfColorDefinitions()) {
if (cd.getValue().equals(color)) {
return cd;
}
}
ColorDefinition colorDefinition = new ColorDefinition("color_" + colorToString(color), color);
renderInformation.addColorDefinition(colorDefinition);
return colorDefinition;
}
protected void assignStyleToGlyph(AbstractReferenceGlyph speciesGlyph, LocalStyle style) {
RenderGraphicalObjectPlugin rgop = new RenderGraphicalObjectPlugin(speciesGlyph);
rgop.setObjectRole(style.getRoleList().get(0));
speciesGlyph.addExtension(RenderConstants.shortLabel, rgop);
}
protected LocalStyle createStyle(T element) {
LocalRenderInformation renderInformation = new LocalRenderInformation();
LocalStyle style = new LocalStyle();
style.getRoleList().add("style_" + element.getElementId());
style.setGroup(new RenderGroup());
renderInformation.addLocalStyle(style);
getRenderPlugin().addLocalRenderInformation(renderInformation);
return style;
}
}
package lcsb.mapviewer.converter.model.sbml;
import java.awt.Color;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
......@@ -9,6 +12,9 @@ import org.apache.log4j.Logger;
import org.sbml.jsbml.AbstractNamedSBase;
import org.sbml.jsbml.Annotation;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.render.LocalRenderInformation;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderLayoutPlugin;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
......@@ -89,4 +95,67 @@ public class SbmlBioEntityParser extends XmlParser {
return (idCounter++) + "";
}
/**
* Returns {@link LocalStyle} from the layout data identified by objectRole.
*
* @param objectRole
* object role identifier
* @return {@link LocalStyle} from the layout data
*/
protected LocalStyle getStyleForRole(String objectRole) {
RenderLayoutPlugin renderPlugin = (RenderLayoutPlugin) layout.getExtension("render");
for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) {
for (LocalStyle style : lri.getListOfLocalStyles()) {
if (style.getRoleList().contains(objectRole)) {
return style;
}
}
}
return null;
}
protected Color getColorByColorDefinition(String fill) {
RenderLayoutPlugin renderPlugin = (RenderLayoutPlugin) layout.getExtension("render");
for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) {
if (lri.getColorDefinition(fill) != null) {
return lri.getColorDefinition(fill).getValue();
}
}
return null;
}
protected LocalStyle getStyleForElement(BioEntity element) {
LocalStyle result = getStyleByRole("style_" + element.getElementId());
if (result == null && element.getElementId().contains("__")) {
result = getStyleByRole("style_" + element.getElementId().split("__")[1]);
}
if (result == null) {
result = getStyleByRole("default_" + element.getClass().getSimpleName());
}
return result;
}
private Map<String, LocalStyle> styleById = null;
LocalStyle getStyleByRole(String string) {
if (styleById == null) {
styleById = new HashMap<>();
if (layout != null) {
RenderLayoutPlugin renderPlugin = (RenderLayoutPlugin) layout.getExtension("render");
if (renderPlugin != null) {
for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) {
if (lri.getId().equals("minerva_definitions")) {
for (LocalStyle style : lri.getListOfLocalStyles()) {
for (String role : style.getRoleList()) {
styleById.put(role, style);
}
}
}
}
}
}
}
return styleById.get(string);
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ import org.sbml.jsbml.ext.layout.BoundingBox;
import org.sbml.jsbml.ext.layout.Dimensions;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.render.ColorDefinition;
import org.sbml.jsbml.ext.render.LocalStyle;
import lcsb.mapviewer.model.map.species.Element;
......@@ -25,8 +27,14 @@ public abstract class SbmlElementExporter<T extends Element, S extends org.sbml.
dimensions.setWidth(element.getWidth());
dimensions.setHeight(element.getHeight());
boundingBox.setDimensions(dimensions);
speciesGlyph.setBoundingBox(boundingBox);
LocalStyle style = createStyle(element);
ColorDefinition color = getColorDefinition(element.getColor());
style.getGroup().setFill(color.getId());
assignStyleToGlyph(speciesGlyph, style);
}
}
package lcsb.mapviewer.converter.model.sbml;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
......@@ -12,6 +13,9 @@ import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderConstants;
import org.sbml.jsbml.ext.render.RenderGraphicalObjectPlugin;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
......@@ -57,6 +61,13 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
elementBySbmlId.put(species.getElementId(), species);
}
for (Element element : elements) {
LocalStyle style = getStyleForElement(element);
if (style != null) {
applyStyleToElement(element, style);
}
}
for (Pair<String, AbstractReferenceGlyph> idGlyphPair : getGlyphs(sbmlLayout)) {
String id = idGlyphPair.getLeft();
Element source = elementBySbmlId.get(id);
......@@ -68,12 +79,7 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
if (glyph.getId() == null || glyph.getId().equals("")) {
throw new InvalidInputDataExecption("Glyph for Species " + idGlyphPair.getLeft() + " doesn't have id");
}
Element elementWithLayout = source.copy();
elementWithLayout.setElementId(glyph.getId());
elementWithLayout.setX(glyph.getBoundingBox().getPosition().getX());
elementWithLayout.setY(glyph.getBoundingBox().getPosition().getY());
elementWithLayout.setWidth(glyph.getBoundingBox().getDimensions().getWidth());
elementWithLayout.setHeight(glyph.getBoundingBox().getDimensions().getHeight());
Element elementWithLayout = createElementWithLayout(source, glyph);
minervaModel.addElement(elementWithLayout);
result.add(elementWithLayout);
elementBySbmlId.put(id, elementWithLayout);
......@@ -91,6 +97,33 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
return result;
}
private Element createElementWithLayout(Element source, AbstractReferenceGlyph glyph)
throws InvalidInputDataExecption {
Element elementWithLayout = source.copy();
elementWithLayout.setElementId(glyph.getId());
elementWithLayout.setX(glyph.getBoundingBox().getPosition().getX());
elementWithLayout.setY(glyph.getBoundingBox().getPosition().getY());
elementWithLayout.setWidth(glyph.getBoundingBox().getDimensions().getWidth());
elementWithLayout.setHeight(glyph.getBoundingBox().getDimensions().getHeight());
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");
}
applyStyleToElement(elementWithLayout, style);
}
return elementWithLayout;
}
private void applyStyleToElement(Element elementWithLayout, LocalStyle style) {
if (style.getGroup().getFill() != null) {
Color backgroundColor = getColorByColorDefinition(style.getGroup().getFill());
elementWithLayout.setColor(backgroundColor);
}
}
protected abstract List<Pair<String, AbstractReferenceGlyph>> getGlyphs(Layout sbmlLayout);
protected abstract Element parse(T species, Model sbmlModel) throws InvalidInputDataExecption;
......
......@@ -11,6 +11,8 @@ import org.sbml.jsbml.SBMLWriter;
import org.sbml.jsbml.ext.layout.Dimensions;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.LayoutModelPlugin;
import org.sbml.jsbml.ext.render.GlobalRenderInformation;
import org.sbml.jsbml.ext.render.RenderLayoutPlugin;
import lcsb.mapviewer.converter.model.sbml.reaction.SbmlReactionExporter;
import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesExporter;
......@@ -19,6 +21,7 @@ import lcsb.mapviewer.model.map.species.Species;
public class SbmlExporter {
Logger logger = Logger.getLogger(SbmlExporter.class);
public String toXml(lcsb.mapviewer.model.map.model.Model model)
throws SBMLException, XMLStreamException, InconsistentModelException {
SBMLDocument doc = new SBMLDocument(3, 1);
......@@ -47,7 +50,7 @@ public class SbmlExporter {
return stream.toString();
}
private Layout createSbmlLayout(lcsb.mapviewer.model.map.model.Model model, Model result) {
public Layout createSbmlLayout(lcsb.mapviewer.model.map.model.Model model, Model result) {
LayoutModelPlugin layoutPlugin = new LayoutModelPlugin(result);
Layout layout = new Layout();
Dimensions dimensions = new Dimensions();
......@@ -64,6 +67,15 @@ public class SbmlExporter {
layout.setDimensions(dimensions);
layoutPlugin.add(layout);
result.addExtension("layout", layoutPlugin);
createSbmlRenderPlugin(layout, result);
return layout;
}
RenderLayoutPlugin createSbmlRenderPlugin(Layout layout, Model result) {
RenderLayoutPlugin renderPlugin = new RenderLayoutPlugin(layout);
renderPlugin.setRenderInformation(new GlobalRenderInformation());
layout.addExtension("render", renderPlugin);
return renderPlugin;
}
}
......@@ -19,6 +19,7 @@ import org.sbml.jsbml.SBMLReader;
import org.sbml.jsbml.ext.SBasePlugin;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.LayoutModelPlugin;
import org.sbml.jsbml.ext.render.LocalStyle;
import lcsb.mapviewer.commands.CommandExecutionException;
import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand;
......@@ -114,14 +115,15 @@ public class SbmlParser implements IConverter {
if (sbmlModel.getRuleCount() > 0) {
throw new NotImplementedException("Rule not implemented for model");
}
createLayout(model, layout, params.isSizeAutoAdjust());
createLayout(model, layout, params.isSizeAutoAdjust(), reactionParser);
return model;
} catch (XMLStreamException e) {
throw new InvalidInputDataExecption(e);
}
}
private void createLayout(Model model, Layout layout, boolean resize) throws InvalidInputDataExecption {
private void createLayout(Model model, Layout layout, boolean resize, SbmlReactionParser parser)
throws InvalidInputDataExecption {
if (model.getWidth() == null) {
double maxY = 0;
double maxX = 0;
......@@ -150,6 +152,15 @@ public class SbmlParser implements IConverter {
try {
if (bioEntitesRequiringLayout.size() > 0) {
new ApplySimpleLayoutModelCommand(model, bioEntitesRequiringLayout, true).execute();
for (BioEntity bioEntity : bioEntitesRequiringLayout) {
if (bioEntity instanceof Reaction) {
LocalStyle style = parser.getStyleForElement(bioEntity);
if (style != null) {
parser.applyStyleToReaction((Reaction) bioEntity, style);
}
}
}
}
} catch (CommandExecutionException e) {
throw new InvalidInputDataExecption("Problem with generating layout", e);
......
......@@ -23,6 +23,8 @@ import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.layout.ReactionGlyph;
import org.sbml.jsbml.ext.layout.SpeciesReferenceGlyph;
import org.sbml.jsbml.ext.layout.SpeciesReferenceRole;
import org.sbml.jsbml.ext.render.ColorDefinition;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.Configuration;
......@@ -173,8 +175,8 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
}
@Override
protected void assignLayoutToGlyph(Reaction reaction, AbstractReferenceGlyph compartmentGlyph) {
ReactionGlyph reactionGlyph = (ReactionGlyph) compartmentGlyph;
protected void assignLayoutToGlyph(Reaction reaction, AbstractReferenceGlyph glyph) {
ReactionGlyph reactionGlyph = (ReactionGlyph) glyph;
boolean firstReactant = true;
reactionGlyph.setCurve(new Curve());
......@@ -242,6 +244,14 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
modifierGlyph.setRole(SpeciesReferenceRole.MODIFIER);
}
}
LocalStyle style = createStyle(reaction);
ColorDefinition color = getColorDefinition(reaction.getReactants().get(0).getLine().getColor());
style.getGroup().setStrokeWidth(reaction.getReactants().get(0).getLine().getWidth());
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);
}
assignRenderDataToReaction(glyph, reactionWithLayout);
minervaModel.addReaction(reactionWithLayout);
} catch (InvalidArgumentException e) {
throw new InvalidInputDataExecption(e);
......@@ -255,6 +234,63 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
}
}
private Class<? extends ReactionNode> getReactionNodeClass(SpeciesReferenceGlyph speciesRefernceGlyph) {
Class<? extends ReactionNode> nodeClass = null;
if (speciesRefernceGlyph.getRole() != null) {