Commit 3f06aced authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1602-sbgn-compartment-ref' into 'devel_16.0.x'

set compartmentRef when exporting to SBGN

See merge request !1397
parents 3dc8166b 4af112d0
Pipeline #50594 failed with stage
in 64 minutes and 1 second
minerva (16.0.3) stable; urgency=medium
* Bug fix: searching for element in submap was broken (#1601)
* Bug fix: compartmentRef was not set when exporting to SBGN (#1602)
* Bug fix: title of request an account email was not taken from configuration
(#1604)
......
......@@ -5,21 +5,39 @@ import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbgn.*;
import org.sbgn.bindings.*;
import org.sbgn.bindings.Arc.*;
import org.sbgn.ArcClazz;
import org.sbgn.GlyphClazz;
import org.sbgn.Language;
import org.sbgn.RenderUtil;
import org.sbgn.bindings.Arc;
import org.sbgn.bindings.Arc.End;
import org.sbgn.bindings.Arc.Next;
import org.sbgn.bindings.Arc.Start;
import org.sbgn.bindings.Bbox;
import org.sbgn.bindings.Glyph;
import org.sbgn.bindings.Label;
import org.sbgn.bindings.Map;
import org.sbgn.bindings.Port;
import org.sbgn.bindings.RenderInformation;
import org.sbgn.bindings.SBGNBase;
import org.sbgn.bindings.Sbgn;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
......@@ -37,11 +55,64 @@ import lcsb.mapviewer.model.graphics.ArrowType;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.modifier.*;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.reaction.type.*;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.field.*;
import lcsb.mapviewer.model.map.modifier.Catalysis;
import lcsb.mapviewer.model.map.modifier.Inhibition;
import lcsb.mapviewer.model.map.modifier.Modulation;
import lcsb.mapviewer.model.map.modifier.PhysicalStimulation;
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.AssociationOperator;
import lcsb.mapviewer.model.map.reaction.DissociationOperator;
import lcsb.mapviewer.model.map.reaction.Modifier;
import lcsb.mapviewer.model.map.reaction.NodeOperator;
import lcsb.mapviewer.model.map.reaction.OrOperator;
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.ReactionNode;
import lcsb.mapviewer.model.map.reaction.SplitOperator;
import lcsb.mapviewer.model.map.reaction.TruncationOperator;
import lcsb.mapviewer.model.map.reaction.type.CatalysisReaction;
import lcsb.mapviewer.model.map.reaction.type.DissociationReaction;
import lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction;
import lcsb.mapviewer.model.map.reaction.type.InhibitionReaction;
import lcsb.mapviewer.model.map.reaction.type.KnownTransitionOmittedReaction;
import lcsb.mapviewer.model.map.reaction.type.ModifierReactionNotation;
import lcsb.mapviewer.model.map.reaction.type.ModulationReaction;
import lcsb.mapviewer.model.map.reaction.type.NegativeInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.PhysicalStimulationReaction;
import lcsb.mapviewer.model.map.reaction.type.PositiveInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.ReducedModulationReaction;
import lcsb.mapviewer.model.map.reaction.type.ReducedNotation;
import lcsb.mapviewer.model.map.reaction.type.ReducedPhysicalStimulationReaction;
import lcsb.mapviewer.model.map.reaction.type.ReducedTriggerReaction;
import lcsb.mapviewer.model.map.reaction.type.TriggerReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownCatalysisReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownInhibitionReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownNegativeInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownPositiveInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownReducedModulationReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownReducedPhysicalStimulationReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownReducedTriggerReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Degraded;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Ion;
import lcsb.mapviewer.model.map.species.Phenotype;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.TruncatedProtein;
import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.model.map.species.field.AbstractRegionModification;
import lcsb.mapviewer.model.map.species.field.AbstractSiteModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.StructuralState;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
......@@ -105,6 +176,8 @@ public class SbgnmlXmlExporter {
XmlAnnotationParser xap = new XmlAnnotationParser(new ArrayList<>(), true);
private java.util.Map<Element, String> exportElementIds = new HashMap<>();
/**
* Transforms model into SBGN-ML xml.
*
......@@ -113,7 +186,7 @@ public class SbgnmlXmlExporter {
* @return SBGM-ML xml string for the model
* @throws ConverterException
*/
public Sbgn toSbgnml(Model model) throws ConverterException {
public Sbgn toSbgnml(final Model model) throws ConverterException {
// Reset global variables
arcCounter = 0;
parsedOperators = new HashSet<>();
......@@ -138,6 +211,13 @@ public class SbgnmlXmlExporter {
map.getGlyph().add(newGlyph);
}
}
for (Species element : model.getSpeciesList()) {
Glyph speciesGlyph = ((Glyph) (sourceTargetMap.get(element.getElementId())));
if (element.getCompartment() != null) {
Glyph compartmentGlyph = ((Glyph) (sourceTargetMap.get(element.getCompartment().getElementId())));
speciesGlyph.setCompartmentRef(compartmentGlyph);
}
}
for (Reaction reaction : model.getReactions()) {
try {
......@@ -193,14 +273,10 @@ public class SbgnmlXmlExporter {
* alias with all parameters for the glyph
* @return newly created glyph
*/
private Glyph elementToGlyph(Element element) {
private Glyph elementToGlyph(final Element element) {
Glyph newGlyph = new Glyph();
boolean idIsANumber = StringUtils.isNumeric(element.getElementId().substring(0, 1));
if (idIsANumber) {
newGlyph.setId(RandomStringUtils.randomAlphabetic(ID_RANDOM_STRING_LENGTH).concat(element.getElementId()));
} else {
newGlyph.setId(element.getElementId());
}
String elementId = getExportElementId(element);
newGlyph.setId(elementId);
newGlyph.setClazz(getGlyphClazzFromElement(element).getClazz());
newGlyph.setLabel(getGlyphLabelFromAlias(element));
......@@ -248,7 +324,24 @@ public class SbgnmlXmlExporter {
return newGlyph;
}
private void addExtensions(Glyph newGlyph, Element element) {
private String getExportElementId(final Element element) {
if (element == null) {
return null;
}
String elementId = exportElementIds.get(element);
if (elementId == null) {
boolean idIsANumber = StringUtils.isNumeric(element.getElementId().substring(0, 1));
if (idIsANumber) {
elementId = RandomStringUtils.randomAlphabetic(ID_RANDOM_STRING_LENGTH).concat(element.getElementId());
} else {
elementId = element.getElementId();
}
exportElementIds.put(element, elementId);
}
return elementId;
}
private void addExtensions(final Glyph newGlyph, final Element element) {
SBGNBase.Extension extension = new SBGNBase.Extension();
newGlyph.setExtension(extension);
org.w3c.dom.Element annotation = getAnnotationExtension(element);
......@@ -258,7 +351,7 @@ public class SbgnmlXmlExporter {
}
private org.w3c.dom.Element getAnnotationExtension(Element element) {
private org.w3c.dom.Element getAnnotationExtension(final Element element) {
try {
String content = xap.dataSetToXmlString(element.getMiriamData(), element.getElementId());
content = "<annotation>" + content + "</annotation>";
......@@ -275,7 +368,7 @@ public class SbgnmlXmlExporter {
}
}
private void addRenderInformation(Glyph glyph, Element element) {
private void addRenderInformation(final Glyph glyph, final Element element) {
float lineWidth = 1.0f;
if (element instanceof Species) {
lineWidth = ((Species) element).getLineWidth().floatValue();
......@@ -286,19 +379,19 @@ public class SbgnmlXmlExporter {
colorParser.colorToHtml(element.getBorderColor()), lineWidth);
}
private void addRenderInformation(Glyph glyph, PolylineData line) {
private void addRenderInformation(final Glyph glyph, final PolylineData line) {
float lineWidth = (float) line.getWidth();
RenderUtil.addStyle(renderInformation, glyph.getId(), colorParser.colorToHtml(Color.WHITE),
colorParser.colorToHtml(line.getColor()), lineWidth);
}
private void addRenderInformation(Arc arc, PolylineData line) {
private void addRenderInformation(final Arc arc, final PolylineData line) {
float lineWidth = (float) line.getWidth();
RenderUtil.addStyle(renderInformation, arc.getId(), colorParser.colorToHtml(Color.WHITE),
colorParser.colorToHtml(line.getColor()), lineWidth);
}
private Glyph createStateVariableForStructuralState(StructuralState structuralState) {
private Glyph createStateVariableForStructuralState(final StructuralState structuralState) {
Glyph glyph = new Glyph();
glyph.setId(structuralState.getSpecies().getElementId() + "-state");
glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz());
......@@ -335,7 +428,7 @@ public class SbgnmlXmlExporter {
* operator with all parameters for the glyph
* @return newly created glyph
*/
private Glyph operatorToGlyph(NodeOperator operator) {
private Glyph operatorToGlyph(final NodeOperator operator) {
Glyph newGlyph = new Glyph();
newGlyph.setId("operator".concat(Integer.toString(parsedOperators.size())));
parsedOperators.add(operator);
......@@ -400,7 +493,7 @@ public class SbgnmlXmlExporter {
* element to extract GlyphCLazz from
* @return GlyphClazz adequate for given alias
*/
private GlyphClazz getGlyphClazzFromElement(Element element) {
private GlyphClazz getGlyphClazzFromElement(final Element element) {
if (element instanceof Protein) {
Protein protein = (Protein) element;
if (protein.getHomodimer() == 1) {
......@@ -491,7 +584,7 @@ public class SbgnmlXmlExporter {
* element with the name
* @return label for a glyph
*/
private Label getGlyphLabelFromAlias(Element element) {
private Label getGlyphLabelFromAlias(final Element element) {
Label label = new Label();
label.setText(element.getName());
Bbox box = new Bbox();
......@@ -510,7 +603,7 @@ public class SbgnmlXmlExporter {
* {@link ModificationResidue} to be parsed
* @return state variable glyph
*/
private Glyph parseStateVariable(ModificationResidue mr) {
private Glyph parseStateVariable(final ModificationResidue mr) {
Glyph glyph = new Glyph();
glyph.setId(mr.getIdModificationResidue());
glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz());
......@@ -544,15 +637,15 @@ public class SbgnmlXmlExporter {
}
/**
* Returns glyph with unit of information extracted from the alias or null if no
* unit of information was found.
* Returns glyph with unit of information extracted from the alias or null if
* no unit of information was found.
*
* @param species
* input species
* @return glyph with unit of information extracted from the alias or null if no
* unit of information was found
* @return glyph with unit of information extracted from the alias or null if
* no unit of information was found
*/
private Glyph getUnitOfInformationGlyph(Species species) {
private Glyph getUnitOfInformationGlyph(final Species species) {
Glyph uoiGlyph = null;
String uoiText = "";
......@@ -626,7 +719,7 @@ public class SbgnmlXmlExporter {
* reaction to be parsed
* @return process glyph for given reaction
*/
private Glyph getProcessGlyphFromReaction(Reaction reaction) {
private Glyph getProcessGlyphFromReaction(final Reaction reaction) {
Glyph processGlyph = new Glyph();
processGlyph.setId(reaction.getIdReaction());
GlyphClazz clazz = getGlyphClazzFromReaction(reaction);
......@@ -741,7 +834,7 @@ public class SbgnmlXmlExporter {
* {@link Reaction} to extract {@link GlyphClazz} from
* @return {@link GlyphClazz} appropriate to given reaction
*/
GlyphClazz getGlyphClazzFromReaction(Reaction reaction) {
GlyphClazz getGlyphClazzFromReaction(final Reaction reaction) {
if (reaction instanceof HeterodimerAssociationReaction) {
return GlyphClazz.ASSOCIATION;
}
......@@ -770,7 +863,7 @@ public class SbgnmlXmlExporter {
* reduced notation reaction
* @return arc extracted from given reduced notation reaction
*/
Arc getArcFromReducedReaction(Reaction reaction) {
Arc getArcFromReducedReaction(final Reaction reaction) {
if ((reaction.getReactants().size() != 1) || (reaction.getProducts().size() != 1)) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, reaction),
"Reduced notation does not allow to have multiple reactants/products. Reaction skipped");
......@@ -793,12 +886,12 @@ public class SbgnmlXmlExporter {
List<Point2D> pointList = new ArrayList<>();
pointList.add(reaction.getReactants().get(0).getLine().getStartPoint());
for (Line2D line: reaction.getReactants().get(0).getLine().getLines()) {
for (Line2D line : reaction.getReactants().get(0).getLine().getLines()) {
pointList.add(line.getP2());
}
pointList.add(reaction.getProducts().get(0).getLine().getStartPoint());
for (Line2D line: reaction.getProducts().get(0).getLine().getLines()) {
for (Line2D line : reaction.getProducts().get(0).getLine().getLines()) {
pointList.add(line.getP2());
}
......@@ -825,7 +918,7 @@ public class SbgnmlXmlExporter {
return arc;
}
ArcClazz getArcClassForReducedNotationReaction(Reaction reaction) {
ArcClazz getArcClassForReducedNotationReaction(final Reaction reaction) {
if (reaction instanceof NegativeInfluenceReaction) {
return ArcClazz.INHIBITION;
} else if (reaction instanceof ReducedModulationReaction) {
......@@ -870,7 +963,7 @@ public class SbgnmlXmlExporter {
* @param pointList
* list of points to be fixed
*/
private void removeRedundantPoints(List<Point2D> pointList) {
private void removeRedundantPoints(final List<Point2D> pointList) {
boolean allDone = false;
while (!allDone) {
allDone = true;
......@@ -903,7 +996,7 @@ public class SbgnmlXmlExporter {
* second side argument
* @return true if x is between s1 and s2
*/
private boolean between(double x, double s1, double s2) {
private boolean between(final double x, final double s1, final double s2) {
if ((x >= s1) && (x <= s2)) {
return true;
}
......@@ -922,7 +1015,7 @@ public class SbgnmlXmlExporter {
* list of all glyphs in the map; used only for parsing operators
* @return set of all arcs used in the reaction
*/
private List<Arc> getArcsFromReaction(Reaction reaction, List<Glyph> glyphList) {
private List<Arc> getArcsFromReaction(final Reaction reaction, final List<Glyph> glyphList) {
List<Arc> arcList = new ArrayList<>();
// Parse all nodes except NodeOperators
......@@ -969,7 +1062,7 @@ public class SbgnmlXmlExporter {
* list of all glyphs in the map; used only for parsing operators
* @return SBGN-ML arc for given node
*/
private Arc getArcFromNode(AbstractNode node, List<Glyph> glyphList) {
private Arc getArcFromNode(final AbstractNode node, final List<Glyph> glyphList) {
Arc arc = new Arc();
arc.setId("arc".concat(Integer.toString(arcCounter)));
arcCounter += 1;
......@@ -1038,7 +1131,7 @@ public class SbgnmlXmlExporter {
List<Point2D> arcPoints = new ArrayList<>();
arcPoints.add(node.getLine().getStartPoint());
for (Line2D line: node.getLine().getLines()) {
for (Line2D line : node.getLine().getLines()) {
arcPoints.add(line.getP2());
}
Start start = new Start();
......@@ -1109,7 +1202,7 @@ public class SbgnmlXmlExporter {
* Node to extract {@link ArcClazz} from
* @return {@link ArcClazz} for given node
*/
private ArcClazz getArcClazzFromNode(AbstractNode node) {
private ArcClazz getArcClazzFromNode(final AbstractNode node) {
if (node instanceof Reactant) {
return ArcClazz.CONSUMPTION;
}
......@@ -1134,20 +1227,20 @@ public class SbgnmlXmlExporter {
if (node instanceof NodeOperator) {
ArrowType arrowType = node.getLine().getEndAtd().getArrowType();
switch (arrowType) {
case BLANK:
return ArcClazz.STIMULATION;
case BLANK_CROSSBAR:
return ArcClazz.NECESSARY_STIMULATION;
case CIRCLE:
return ArcClazz.CATALYSIS;
case CROSSBAR:
return ArcClazz.INHIBITION;
case DIAMOND:
return ArcClazz.MODULATION;
case NONE:
return ArcClazz.LOGIC_ARC;
default:
throw new InvalidArgumentException();
case BLANK:
return ArcClazz.STIMULATION;
case BLANK_CROSSBAR:
return ArcClazz.NECESSARY_STIMULATION;
case CIRCLE:
return ArcClazz.CATALYSIS;
case CROSSBAR:
return ArcClazz.INHIBITION;
case DIAMOND:
return ArcClazz.MODULATION;
case NONE:
return ArcClazz.LOGIC_ARC;
default:
throw new InvalidArgumentException();
}
}
throw new InvalidArgumentException();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment