Commit 0a762d65 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch...

Merge branch '1281-celldesigner-ignores-all-rdf-description-block-in-case-it-contains-not-supported-bqmodel' into 'master'

Resolve "CellDesigner ignores all rdf description block in case it contains not-supported bqmodel:isDerivedFrom"

Closes #1281

See merge request !1174
parents ed549da3 f4e89c33
Pipeline #28214 failed with stage
in 60 minutes and 2 seconds
......@@ -14,6 +14,8 @@ minerva (15.0.0~beta.5) unstable; urgency=medium
(#1268)
* Bug fix: proper color is parsed from CellDesigner species marked as 'brief'
(#1268)
* Bug fix: export to CellDesigner replace unsupported bqmodel:isDerivedFrom
types with something readable by CellDesigner (#1281)
* Bug fix: unknown elements are exported to 'Unknown' data nodes in GPML
(#1274)
* Bug fix: uploading map with elements having identifiers like "artX" could
......
......@@ -393,7 +393,7 @@ public class CellDesignerXmlParser extends Converter {
}
private void processModelRdfNode(Model model, Node node) throws InvalidXmlSchemaException {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
model.addMiriamData(xmlAnnotationParser.parseRdfNode(node));
model.addAuthors(xmlAnnotationParser.getAuthorsFromRdf(node));
model.setCreationDate(xmlAnnotationParser.getCreateDateFromRdf(node));
......@@ -728,7 +728,8 @@ public class CellDesignerXmlParser extends Converter {
result.append(layerParser.layerCollectionToXml(model.getLayers()));
result.append("</celldesigner:extension>\n");
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
result.append(xmlAnnotationParser.dataSetToXmlString(model.getMiriamData(), model.getAuthors(),
model.getCreationDate(), model.getModificationDates(), model.getIdModel()));
result.append("</annotation>\n");
......
......@@ -4,6 +4,7 @@ import java.awt.Color;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.util.*;
import javax.xml.parsers.*;
......@@ -15,6 +16,7 @@ import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SingleLine;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.View;
import lcsb.mapviewer.model.map.MiriamRelationType;
/**
* Class with parsers for common CellDesigner objects.
......@@ -47,6 +49,13 @@ public class CommonXmlParser {
}
public static Set<MiriamRelationType> RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER;
{
RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER = new HashSet<>();
RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER.addAll(Arrays.asList(MiriamRelationType.values()));
RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER.remove(MiriamRelationType.BQ_MODEL_IS_DERIVED_FROM);
}
private DocumentBuilderFactory dbFactory;
private DocumentBuilder dBuilder;
......
......@@ -17,6 +17,7 @@ import lcsb.mapviewer.common.comparator.*;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
......@@ -48,13 +49,17 @@ public class RestAnnotationParser {
/**
* Parser used for parsing annotations in rdf format.
*/
private XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
private XmlAnnotationParser xmlAnnotationParser;
/**
* Class used for some simple operations on {@link BioEntity} elements.
*/
private ElementUtils elementUtils = new ElementUtils();
public RestAnnotationParser() {
xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
}
/**
* This method parse the string with annotations provided by the lcsb team.
* Parsing has been prepared based on the information provided by Kazuhiro
......
......@@ -10,6 +10,7 @@ import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.species.AbstractElementXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerCompartment;
......@@ -34,7 +35,7 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC
/**
* Parser used to retrieve Miriam data for the element.
*/
private XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
private XmlAnnotationParser xmlAnnotationParser;
/**
* Collection of {@link CellDesignerElement cell designer elements} parsed from
......@@ -56,6 +57,7 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC
*/
public CompartmentXmlParser(CellDesignerElementCollection elements) {
this.elements = elements;
xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
}
@Override
......
......@@ -12,6 +12,7 @@ import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesignerConverter;
......@@ -311,7 +312,7 @@ public class ReactionFromXml {
result = parseReactionExtension(result, node, model);
} else if (node.getNodeName().equalsIgnoreCase("rdf:RDF")) {
try {
XmlAnnotationParser xmlParser = new XmlAnnotationParser();
XmlAnnotationParser xmlParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
result.addMiriamData(xmlParser.parseRdfNode(node));
} catch (InvalidXmlSchemaException e) {
throw new ReactionParserException("Problem with parsing RDF", result, e);
......
......@@ -14,6 +14,7 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.*;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
......@@ -494,7 +495,7 @@ public class ReactionToXml {
sb.append(getLineXmlStringForLines(reaction.getLine()));
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
sb.append("</celldesigner:extension>\n");
sb.append(xmlAnnotationParser.dataSetToXmlString(reaction.getMiriamData(), reaction.getIdReaction()));
sb.append("</annotation>\n");
......
......@@ -13,6 +13,7 @@ import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.*;
import lcsb.mapviewer.model.map.InconsistentModelException;
......@@ -67,7 +68,7 @@ public class SpeciesCollectionXmlParser {
/**
* Parser used for parsing annotation.
*/
private XmlAnnotationParser xap = new XmlAnnotationParser();
private XmlAnnotationParser xap;
/**
* Helper class used to decode/encode CellDesigner strings.
......@@ -114,6 +115,7 @@ public class SpeciesCollectionXmlParser {
geneParser = new GeneXmlParser(elements);
proteinParser = new ProteinXmlParser(elements);
antisenseRnaParser = new AntisenseRnaXmlParser(elements);
xap = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
}
/**
......
......@@ -12,6 +12,7 @@ import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.CommonXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.*;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
......@@ -195,7 +196,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
}
if (rdfNode != null) {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode));
}
......@@ -286,7 +287,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
builder.append("</celldesigner:extension>\n");
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser();
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
builder.append(xmlAnnotationParser.dataSetToXmlString(species.getMiriamData(), elements.getElementId(species)));
builder.append("</annotation>\n");
......
......@@ -30,10 +30,21 @@ public class XmlAnnotationParser {
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private Set<MiriamRelationType> supportedRelationTypes = new HashSet<>();
/**
* Default constructor.
*/
public XmlAnnotationParser() {
this(new ArrayList<>());
}
public XmlAnnotationParser(Collection<MiriamRelationType> supportedRelationTypes) {
if (supportedRelationTypes == null || supportedRelationTypes.size() == 0) {
this.supportedRelationTypes.addAll(Arrays.asList(MiriamRelationType.values()));
} else {
this.supportedRelationTypes.addAll(supportedRelationTypes);
}
}
/**
......@@ -353,12 +364,20 @@ public class XmlAnnotationParser {
*/
public String miriamDataToXmlString(MiriamData data) {
StringBuilder result = new StringBuilder("");
result.append("<" + data.getRelationType().getStringRepresentation() + ">\n");
MiriamRelationType relationType;
if (supportedRelationTypes.contains(data.getRelationType())) {
relationType = data.getRelationType();
} else {
relationType = supportedRelationTypes.iterator().next();
logger.warn(data.getRelationType().getStringRepresentation() + " is not supported. Replacing with: "
+ relationType.getStringRepresentation());
}
result.append("<" + relationType.getStringRepresentation() + ">\n");
result.append("<rdf:Bag>\n");
result.append("<rdf:li rdf:resource=\"" + data.getDataType().getUris().get(0) + ":"
+ data.getResource().replaceAll(":", "%3A") + "\"/>\n");
result.append("</rdf:Bag>\n");
result.append("</" + data.getRelationType().getStringRepresentation() + ">\n");
result.append("</" + relationType.getStringRepresentation() + ">\n");
return result.toString();
}
......
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.converter.annotation;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Set;
import org.junit.*;
......@@ -105,4 +106,15 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
assertEquals(1, getWarnings().size());
}
@Test
public void testMiriamDataToXmlWithUnsupportedType() throws Exception {
MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, "e:f");
XmlAnnotationParser parser = new XmlAnnotationParser(Arrays.asList(MiriamRelationType.BQ_BIOL_ENCODES));
String xml = parser.miriamDataToXmlString(md);
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml));
assertNotNull(set);
MiriamData md1 = set.iterator().next();
assertNotEquals(md.getRelationType(), md1.getRelationType());
}
}
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