Commit 2dcc5326 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1472-missing-info-about-species-id-for-sbml-import-warnings' into 'master'

Resolve "missing info about species id for sbml import warnings"

Closes #1472

See merge request !1294
parents 74f87ef3 a65a8f68
Pipeline #40064 failed with stage
in 23 minutes and 29 seconds
......@@ -2,6 +2,9 @@ minerva (16.0.0~alpha.2) stable; urgency=medium
* Backward incompatibility: debian package cannot be upgraded from version
prior to 12.1.0 (#1464)
* Small improvement: homomultimer information is provided in API (#1468)
* Small improvement: missing info about species for SBML parsing warning
(#1472)
* Small improvement: glyph quality is improved (#1458)
-- Piotr Gawron <piotr.gawron@uni.lu> Fri, 26 Mar 2021 10:00:00 +0200
......
......@@ -88,7 +88,7 @@ public class CopyPasteAbstractAction {
*/
protected String getCopyString(String annotationString, String notesString) throws InvalidXmlSchemaException {
XmlAnnotationParser xap = new XmlAnnotationParser();
Set<MiriamData> set = xap.parse(annotationString);
Set<MiriamData> set = xap.parse(annotationString, null);
StringBuilder result = new StringBuilder();
for (MiriamData md : set) {
result.append(serialize(md) + "\n");
......
......@@ -395,7 +395,7 @@ public class CellDesignerXmlParser extends Converter {
private void processModelRdfNode(Model model, Node node) throws InvalidXmlSchemaException {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
model.addMiriamData(xmlAnnotationParser.parseRdfNode(node));
model.addMiriamData(xmlAnnotationParser.parseRdfNode(node, null));
model.addAuthors(xmlAnnotationParser.getAuthorsFromRdf(node));
model.setCreationDate(xmlAnnotationParser.getCreateDateFromRdf(node));
model.addModificationDates(xmlAnnotationParser.getModificationDatesFromRdf(node));
......
......@@ -885,7 +885,8 @@ public class RestAnnotationParser {
Matcher nodeMatcher = rdfNodePattern.matcher(notes);
if (nodeMatcher.find()) {
String rdfString = "<rdf:RDF" + nodeMatcher.group(1) + "</rdf:RDF>";
element.addMiriamData(xmlAnnotationParser.parse(rdfString));
element.addMiriamData(
xmlAnnotationParser.parse(rdfString, new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element)));
notes = notes.substring(0, nodeMatcher.start() - "<rdf:RDF".length())
+ notes.substring(nodeMatcher.end() + "</rdf:RDF>".length());
......
......@@ -15,6 +15,8 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationPars
import lcsb.mapviewer.converter.model.celldesigner.species.AbstractElementXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerCompartment;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
......@@ -144,7 +146,9 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC
Node node = annotationNodes.item(y);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("rdf:RDF")) {
compartment.addMiriamData(xmlAnnotationParser.parseRdfNode(node));
compartment.addMiriamData(xmlAnnotationParser.parseRdfNode(node,
new LogMarker(ProjectLogEntryType.PARSING_ISSUE, compartment.getClass().getSimpleName(),
compartment.getElementId(), "")));
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:extension")) {
parseExtensionNode(compartment, node);
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:name")) {
......
......@@ -19,6 +19,8 @@ import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesigner
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.*;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.*;
import lcsb.mapviewer.converter.model.celldesigner.types.*;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.*;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
......@@ -313,7 +315,8 @@ public class ReactionFromXml {
try {
XmlAnnotationParser xmlParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
result.addMiriamData(xmlParser.parseRdfNode(node));
result.addMiriamData(xmlParser.parseRdfNode(node, new LogMarker(ProjectLogEntryType.PARSING_ISSUE,
result.getClass().getSimpleName(), result.getElementId(), model.getName())));
} catch (InvalidXmlSchemaException e) {
throw new ReactionParserException("Problem with parsing RDF", result, e);
}
......
......@@ -17,6 +17,8 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationPars
import lcsb.mapviewer.converter.model.celldesigner.structure.*;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
import lcsb.mapviewer.model.map.kinetics.SbmlUnit;
......@@ -198,7 +200,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
if (rdfNode != null) {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode));
species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode, new LogMarker(ProjectLogEntryType.PARSING_ISSUE,
species.getClass().getSimpleName(), species.getElementId(), "")));
}
return result;
......
......@@ -984,7 +984,8 @@ public class SbgnmlXmlParser {
"No rdf node provided in annotation extension");
} else {
try {
element.addMiriamData(new XmlAnnotationParser().parseRdfNode(rdf));
element.addMiriamData(
new XmlAnnotationParser().parseRdfNode(rdf, new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element)));
} catch (InvalidXmlSchemaException e) {
logger.error(e, e);
}
......@@ -1677,7 +1678,7 @@ public class SbgnmlXmlParser {
List<Line2D> lines = new ArrayList<>(product.getLine().getLines());
product.getLine().removeLines();
Collections.reverse(lines);
for (Line2D l: lines) {
for (Line2D l : lines) {
product.getLine().addLine(l.getP2(), l.getP1());
}
}
......
......@@ -99,10 +99,11 @@ public abstract class ElementConverter<T extends Element> extends BioEntityConve
protected void drawGlyph(T bioEntity, Graphics2D graphics) throws DrawingException {
try {
Image img = ImageIO.read(new ByteArrayInputStream(bioEntity.getGlyph().getFile().getFileContent()));
graphics.drawImage(img,
Image scaledImage = img.getScaledInstance(bioEntity.getWidth().intValue(), bioEntity.getHeight().intValue(), Image.SCALE_SMOOTH);
graphics.drawImage(scaledImage,
bioEntity.getX().intValue(), bioEntity.getY().intValue(),
(int) (bioEntity.getX() + bioEntity.getWidth()), (int) (bioEntity.getY() + bioEntity.getHeight()),
0, 0, img.getWidth(null), img.getHeight(null),
null);
} catch (IOException e) {
throw new DrawingException(
......
......@@ -16,6 +16,7 @@ import lcsb.mapviewer.common.UnitTestFailedWatcher;
import lcsb.mapviewer.model.graphics.*;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.modifier.Catalysis;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.species.*;
......@@ -93,6 +94,19 @@ public abstract class GraphicsTestFunctions {
return complex;
}
protected LayerText createText() {
LayerText layerText = new LayerText();
layerText.setX(256.0);
layerText.setY(79.0);
layerText.setWidth(233.0);
layerText.setHeight(188.0);
layerText.setZ(0);
layerText.setNotes("asd as");
layerText.setColor(Color.BLACK);
return layerText;
}
protected List<Color> removeAlpha(List<Color> allValues) {
List<Color> result = new ArrayList<>();
for (Color color : allValues) {
......
package lcsb.mapviewer.converter.graphics;
import java.awt.*;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.nio.file.Files;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -10,12 +13,12 @@ import org.junit.*;
import lcsb.mapviewer.commands.CreateHierarchyCommand;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.layout.graphics.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.*;
public class NormalImageGeneratorTest extends GraphicsTestFunctions {
static Logger logger = LogManager.getLogger();
......@@ -33,27 +36,15 @@ public class NormalImageGeneratorTest extends GraphicsTestFunctions {
model.setWidth(526);
model.setHeight(346);
LayerText compAlias = new LayerText();
compAlias.setX(256.0);
compAlias.setY(79.0);
compAlias.setWidth(233.0);
compAlias.setHeight(188.0);
compAlias.setNotes("asd as");
compAlias.setColor(Color.BLACK);
LayerText layerText = createText();
Layer layer = new Layer();
layer.addLayerText(compAlias);
layer.addLayerText(layerText);
layer.setVisible(true);
model.addLayer(layer);
layer.addLayerLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(100, 100)));
Complex alias = new Complex("1");
alias.setName("a");
alias.setX(300);
alias.setY(90);
alias.setWidth(100);
alias.setHeight(50);
model.addElement(alias);
model.addElement(createComplex());
return model;
}
......
......@@ -83,8 +83,7 @@ public class BioEntityConverterImplTest extends GraphicsTestFunctions {
BioEntityConverterImpl converter = new BioEntityConverterImpl(alias, false, colorExtractor);
converter.draw(alias, graphics, new ConverterParams());
verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(),
anyInt(), anyInt(), nullable(ImageObserver.class));
verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), nullable(ImageObserver.class));
}
private Reaction createReaction(double lineWidth) {
......
......@@ -367,8 +367,7 @@ public class SpeciesConverterTest extends GraphicsTestFunctions {
alias.setGlyph(glyph);
rc.draw(alias, graphics, new ConverterParams());
verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(),
anyInt(), anyInt(), nullable(ImageObserver.class));
verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), nullable(ImageObserver.class));
}
protected GenericProtein createProtein() {
......
......@@ -18,6 +18,8 @@ import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.sbml.species.ElementColorEnum;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.compartment.Compartment;
......@@ -68,13 +70,13 @@ public class SbmlBioEntityParser {
this.layout = getSbmlLayout(sbmlModel);
}
protected Set<MiriamData> extractMiriamDataFromAnnotation(Annotation annotation) throws InvalidInputDataExecption {
protected Set<MiriamData> extractMiriamDataFromAnnotation(Annotation annotation, LogMarker marker) throws InvalidInputDataExecption {
XmlAnnotationParser parser = new XmlAnnotationParser();
Set<MiriamData> result = new HashSet<>();
try {
Node rdfNode = getRdfNodeFromAnnotation(annotation);
if (rdfNode != null) {
result.addAll(parser.parseRdfNode(rdfNode));
result.addAll(parser.parseRdfNode(rdfNode, marker));
}
} catch (InvalidXmlSchemaException e) {
throw new InvalidInputDataExecption(e);
......@@ -136,7 +138,7 @@ public class SbmlBioEntityParser {
protected void assignBioEntityData(AbstractNamedSBase sbmlElement, BioEntity result)
throws InvalidInputDataExecption {
result.addMiriamData(extractMiriamDataFromAnnotation(sbmlElement.getAnnotation()));
result.addMiriamData(extractMiriamDataFromAnnotation(sbmlElement.getAnnotation(), new LogMarker(ProjectLogEntryType.PARSING_ISSUE, result)));
result.setName(sbmlElement.getName());
String notes = NotesUtility.extractNotes(sbmlElement);
result.setNotes(notes);
......
......@@ -4,12 +4,15 @@ import java.awt.Color;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbml.jsbml.AbstractNamedSBase;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.SBasePlugin;
import org.sbml.jsbml.ext.layout.*;
import org.sbml.jsbml.ext.render.*;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.ArrowType;
public class SbmlModelUtils {
......@@ -247,4 +250,14 @@ public class SbmlModelUtils {
return result;
}
public static LogMarker createMarker(ProjectLogEntryType type, AbstractNamedSBase element) {
if (element == null) {
return new LogMarker(type, "", "N/A", "N/A");
} else if (element.getModel() == null) {
return new LogMarker(type, element.getClass().getSimpleName(), element.getId(), "");
} else {
return new LogMarker(type, element.getClass().getSimpleName(), element.getId(), element.getModel().getName());
}
}
}
......@@ -72,7 +72,7 @@ public class SbmlParser extends Converter {
SbmlParameterParser parameterParser = new SbmlParameterParser(sbmlModel, model);
SbmlFunctionParser functionParser = new SbmlFunctionParser(sbmlModel, model);
model.addMiriamData(compartmentParser.extractMiriamDataFromAnnotation(sbmlModel.getAnnotation()));
model.addMiriamData(compartmentParser.extractMiriamDataFromAnnotation(sbmlModel.getAnnotation(), null));
model.addAuthors(compartmentParser.extractAuthorsFromAnnotation(sbmlModel.getAnnotation()));
model.addModificationDates(compartmentParser.extractModificationDatesFromAnnotation(sbmlModel.getAnnotation()));
model.setCreationDate(compartmentParser.extractCreationDateFromAnnotation(sbmlModel.getAnnotation()));
......
......@@ -5,7 +5,10 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbml.jsbml.ModifierSpeciesReference;
import lcsb.mapviewer.converter.model.sbml.SbmlModelUtils;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.modifier.*;
import lcsb.mapviewer.model.map.reaction.Modifier;
......@@ -31,7 +34,8 @@ public enum SBOTermModifierType {
}
}
public static Class<? extends Modifier> getTypeSBOTerm(String sboTerm) {
public static Class<? extends Modifier> getTypeSBOTerm(ModifierSpeciesReference modifier) {
String sboTerm = modifier.getSBOTermID();
if (sboTerm == null || sboTerm.isEmpty()) {
return Modifier.class;
}
......@@ -43,8 +47,10 @@ public enum SBOTermModifierType {
}
}
}
if (result == null) {
logger.warn("Don't know how to handle SBOTerm " + sboTerm + " for modifier");
logger.warn(SbmlModelUtils.createMarker(ProjectLogEntryType.PARSING_ISSUE, modifier),
"Don't know how to handle SBOTerm " + sboTerm + " for modifier");
result = Modifier.class;
}
return result;
......
......@@ -6,6 +6,8 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.converter.model.sbml.SbmlModelUtils;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.type.*;
......@@ -49,7 +51,12 @@ public enum SBOTermReactionType {
}
}
public static Class<? extends Reaction> getTypeSBOTerm(String sboTerm) {
public static Class<? extends Reaction> getTypeSBOTerm(org.sbml.jsbml.Reaction reaction) {
if (reaction == null) {
return StateTransitionReaction.class;
}
String sboTerm = reaction.getSBOTermID();
if (sboTerm == null || sboTerm.isEmpty()) {
return StateTransitionReaction.class;
}
......@@ -62,7 +69,8 @@ public enum SBOTermReactionType {
}
}
if (result == null) {
logger.warn("Don't know how to handle SBOTerm " + sboTerm + " for reaction");
logger.warn(SbmlModelUtils.createMarker(ProjectLogEntryType.PARSING_ISSUE, reaction),
"Don't know how to handle SBOTerm " + sboTerm + " for reaction");
result = StateTransitionReaction.class;
}
return result;
......
......@@ -707,7 +707,7 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
for (ModifierSpeciesReference modifier : sbmlReaction.getListOfModifiers()) {
Species element = getMinervaModel().getElementByElementId(modifier.getSpecies());
Class<? extends Modifier> nodeClass = SBOTermModifierType.getTypeSBOTerm(modifier.getSBOTermID());
Class<? extends Modifier> nodeClass = SBOTermModifierType.getTypeSBOTerm(modifier);
try {
Modifier newNode = nodeClass.getConstructor(Element.class).newInstance(element);
reaction.addModifier(newNode);
......@@ -740,16 +740,14 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
reaction.addProduct(new Product(element));
}
String sboTerm = sbmlReaction.getSBOTermID();
reaction = createProperReactionClassForSboTerm(reaction, sboTerm);
reaction = createProperReactionClassForSboTerm(reaction, sbmlReaction);
return reaction;
}
private Reaction createProperReactionClassForSboTerm(Reaction reaction, String sboTerm)
private Reaction createProperReactionClassForSboTerm(Reaction reaction, org.sbml.jsbml.Reaction sbmlReaction)
throws InvalidInputDataExecption {
Class<? extends Reaction> reactionClass = SBOTermReactionType.getTypeSBOTerm(sboTerm);
Class<? extends Reaction> reactionClass = SBOTermReactionType.getTypeSBOTerm(sbmlReaction);
try {
reaction = reactionClass.getConstructor(Reaction.class).newInstance(reaction);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
......
......@@ -8,6 +8,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.converter.model.sbml.SbmlModelUtils;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.species.*;
public enum SBOTermSpeciesType {
......@@ -50,7 +52,7 @@ public enum SBOTermSpeciesType {
this.hypothetical = hypothetical;
}
private static SBOTermSpeciesType getTypeSBOTerm(String sboTerm) {
private static SBOTermSpeciesType getTypeSBOTerm(String sboTerm, org.sbml.jsbml.Species species) {
if (sboTerm == null || sboTerm.isEmpty()) {
return SIMPLE_MOLECULE;
}
......@@ -63,17 +65,18 @@ public enum SBOTermSpeciesType {
}
}
if (result == null) {
logger.warn("Don't know how to handle SBOTerm " + sboTerm + " for species");
logger.warn(SbmlModelUtils.createMarker(ProjectLogEntryType.PARSING_ISSUE, species),
"Don't know how to handle SBOTerm " + sboTerm);
result = SIMPLE_MOLECULE;
}
return result;
}
public static Species createElementForSBOTerm(String sboTerm, String elementId) {
public static Species createElementForSBOTerm(String sboTerm, org.sbml.jsbml.Species species) {
try {
SBOTermSpeciesType type = getTypeSBOTerm(sboTerm);
SBOTermSpeciesType type = getTypeSBOTerm(sboTerm, species);
Class<? extends Species> clazz = type.clazz;
Species result = clazz.getConstructor(String.class).newInstance(elementId);
Species result = clazz.getConstructor(String.class).newInstance(species.getId());
if (type.hypothetical) {
result.setHypothetical(true);
}
......
Supports Markdown
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