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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lcsb.mapviewer</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>CellDesigner-plugin</artifactId>
<!-- dependency from the MapViewer model -->
<repositories>
<repository>
<id>central</id>
<url>http://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>repo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>install.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>commons</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>converter-CellDesigner</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>jp.sbi</groupId>
<artifactId>celldesigner</artifactId>
<version>${celldesigner.version}</version>
</dependency>
<dependency>
<groupId>org.sbml</groupId>
<artifactId>libsbml</artifactId>
<version>${libsbml.version}</version>
</dependency>
</dependencies>
<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>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>CellDesigner-plugin</artifactId>
<!-- dependency from the MapViewer model -->
<repositories>
<repository>
<id>central</id>
<url>http://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>repo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>install.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>commons</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>converter-CellDesigner</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>jp.sbi</groupId>
<artifactId>celldesigner</artifactId>
<version>${celldesigner.version}</version>
</dependency>
<dependency>
<groupId>org.sbml</groupId>
<artifactId>libsbml</artifactId>
<version>${libsbml.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -160,7 +160,11 @@ public class RestAnnotationParser extends XmlParser {
return "";
}
} else if (value instanceof String) {
return type.getCommonName() + ": " + value + "\n";
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,9 @@
<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>
......@@ -97,24 +97,67 @@
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<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>
<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>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>${stax2-api.version}</version>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>${stax2-api.version}</version>
</dependency>
<dependency>
......
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());