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
......@@ -514,7 +514,7 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
@Override
protected Species parse(org.sbml.jsbml.Species species) throws InvalidInputDataExecption {
String sboTerm = extractSBOTermFromSpecies(species);
Species result = SBOTermSpeciesType.createElementForSBOTerm(sboTerm, species.getId());
Species result = SBOTermSpeciesType.createElementForSBOTerm(sboTerm, species);
if (!Double.isNaN(species.getInitialAmount())) {
result.setInitialAmount(species.getInitialAmount());
}
......
......@@ -8,7 +8,9 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({ SbmlReactionExportArrowType.class,
SbmlReactionExporterTest.class,
SbmlReactionParserTest.class,
SbmlReactionParserExtractCurveTest.class
SbmlReactionParserExtractCurveTest.class,
SBOTermModifierTypeTest.class,
SBOTermReactionTypeTest.class,
})
public class AllSbmlReactionParserTests {
......
package lcsb.mapviewer.converter.model.sbml.reaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.sbml.jsbml.ModifierSpeciesReference;
import lcsb.mapviewer.converter.model.sbml.SbmlTestFunctions;
import lcsb.mapviewer.model.map.reaction.Modifier;
public class SBOTermModifierTypeTest extends SbmlTestFunctions {
@Test
public void testUnknownId() {
ModifierSpeciesReference reference = new ModifierSpeciesReference(3, 2);
reference.setSBOTerm("SBO:0000000");
Class<? extends Modifier> clazz = SBOTermModifierType.getTypeSBOTerm(reference);
assertNotNull(clazz);
assertEquals(1, super.getWarnings().size());
assertNotNull(super.getWarnings().get(0).getMarker());
}
}
package lcsb.mapviewer.converter.model.sbml.reaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.sbml.jsbml.Reaction;
import lcsb.mapviewer.converter.model.sbml.SbmlTestFunctions;
public class SBOTermReactionTypeTest extends SbmlTestFunctions {
@Test
public void testTypeForUnknownSBOTerm() {
Reaction reaction = new Reaction(3, 2);
reaction.setSBOTerm("SBO:0000000");
Class<? extends lcsb.mapviewer.model.map.reaction.Reaction> clazz = SBOTermReactionType.getTypeSBOTerm(reaction);
assertNotNull(clazz);
assertEquals(1, super.getWarnings().size());
assertNotNull(super.getWarnings().get(0).getMarker());
}
}
......@@ -6,10 +6,11 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ModificationResidueExporterTest.class,
SbmlSpeciesExporterRenderShapeTest.class,
SbmlSpeciesExporterTest.class,
SbmlSpeciesParserTest.class })
ModificationResidueExporterTest.class,
SbmlSpeciesExporterRenderShapeTest.class,
SbmlSpeciesExporterTest.class,
SbmlSpeciesParserTest.class,
SBOTermSpeciesTypeTest.class })
public class AllSbmlSpeciesTests {
}
package lcsb.mapviewer.converter.model.sbml.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.sbml.jsbml.Species;
import lcsb.mapviewer.converter.model.sbml.SbmlTestFunctions;
import lcsb.mapviewer.model.map.species.Element;
public class SBOTermSpeciesTypeTest extends SbmlTestFunctions {
@Test
public void testCreateElementForSBOTerm() {
Species species = new Species(3, 2);
species.setSBOTerm("SBO:0000000");
Element element = SBOTermSpeciesType.createElementForSBOTerm("SBO:0000000", species);
assertNotNull(element);
assertEquals(1, super.getWarnings().size());
assertNotNull(super.getWarnings().get(0).getMarker());
}
}
......@@ -11,6 +11,8 @@ import org.w3c.dom.*;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.model.Author;
......@@ -66,14 +68,14 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
public Set<MiriamData> parse(String data) throws InvalidXmlSchemaException {
public Set<MiriamData> parse(String data, LogMarker marker) throws InvalidXmlSchemaException {
// start from creating a DOM parser and parse the whole document
Document doc = XmlParser.getXmlDocumentFromString(data);
NodeList root = doc.getChildNodes();
// process the whole schema
return parseRdfNode(root);
return parseRdfNode(root, marker);
}
/**
......@@ -85,9 +87,9 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
private Set<MiriamData> parseRdfNode(NodeList root) throws InvalidXmlSchemaException {
private Set<MiriamData> parseRdfNode(NodeList root, LogMarker marker) throws InvalidXmlSchemaException {
Node rdf = XmlParser.getNode("rdf:RDF", root);
return parseRdfNode(rdf);
return parseRdfNode(rdf, marker);
}
/**
......@@ -99,7 +101,7 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
public Set<MiriamData> parseRdfNode(Node rdf) throws InvalidXmlSchemaException {
public Set<MiriamData> parseRdfNode(Node rdf, LogMarker marker) throws InvalidXmlSchemaException {
Set<MiriamData> miriamDataSet = new HashSet<>();
if (rdf != null) {
Node description = XmlParser.getNode("rdf:Description", rdf.getChildNodes());
......@@ -111,7 +113,7 @@ public class XmlAnnotationParser {
String relationTypeString = node.getNodeName();
MiriamRelationType relationType = MiriamRelationType.getTypeByStringRepresentation(relationTypeString);
if (relationType != null) {
miriamDataSet.addAll(parseMiriamNode(node));
miriamDataSet.addAll(parseMiriamNode(node, marker));
} else if (relationTypeString.equals("dc:creator")) {
} else if (relationTypeString.equals("dcterms:created")) {
} else if (relationTypeString.equals("dcterms:modified")) {
......@@ -239,7 +241,7 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
public Set<MiriamData> parseMiriamNode(Node node) throws InvalidXmlSchemaException {
public Set<MiriamData> parseMiriamNode(Node node, LogMarker logMarker) throws InvalidXmlSchemaException {
Set<MiriamData> result = new HashSet<>();
NodeList list = node.getChildNodes();
String relationTypeString = node.getNodeName();
......@@ -259,7 +261,8 @@ public class XmlAnnotationParser {
try {
MiriamData md = MiriamType.getMiriamByUri(dataTypeUri);
if (relationType == null) {
logger.warn("Unknown relation type: " + relationTypeString + ". For miriam uri: " + dataTypeUri + ".");
logger.warn(logMarker,
"Unknown relation type: " + relationTypeString + ". For miriam uri: " + dataTypeUri + ".");
} else {
if (!MiriamType.PUBMED.equals(md.getDataType())) {
md.setRelationType(relationType);
......@@ -267,7 +270,7 @@ public class XmlAnnotationParser {
result.add(md);
}
} catch (InvalidArgumentException e) {
logger.warn(e.getMessage());
logger.warn(logMarker, e.getMessage());
}
}
return result;
......
......@@ -28,7 +28,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/rdf.xml");
Set<MiriamData> set = xap.parse(xml);
Set<MiriamData> set = xap.parse(xml, null);
assertEquals(2, set.size());
}
......@@ -38,7 +38,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/rdf_has_property.xml");
Set<MiriamData> set = xap.parse(xml);
Set<MiriamData> set = xap.parse(xml, null);
assertEquals(0, super.getWarnings().size());
assertEquals(7, set.size());
}
......@@ -49,7 +49,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
XmlAnnotationParser parser = new XmlAnnotationParser();
String xml = parser.miriamDataToXmlString(md);
assertNotNull(xml);
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml));
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml), null);
assertNotNull(set);
assertEquals(1, set.size());
MiriamData md1 = set.iterator().next();
......@@ -63,7 +63,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
public void testParseInvalidRdf() throws Exception {
XmlAnnotationParser xap = new XmlAnnotationParser();
xap.parseRdfNode((Node) null);
xap.parseRdfNode((Node) null, null);
}
@Test
......@@ -71,7 +71,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
XmlAnnotationParser xap = new XmlAnnotationParser();
String xml = readFile("testFiles/annotation/rdf_with_creator_tag.xml");
Set<MiriamData> set = xap.parse(xml);
Set<MiriamData> set = xap.parse(xml, null);
assertTrue(set.size() > 0);
}
......@@ -81,7 +81,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/invalid_rdf2.xml");
xap.parse(xml);
xap.parse(xml, null);
}
@Test
......@@ -90,7 +90,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/invalid_rdf3.xml");
xap.parse(xml);
xap.parse(xml, null);
assertEquals(1, getWarnings().size());
}
......@@ -101,7 +101,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/invalid_rdf4.xml");
xap.parse(xml);
xap.parse(xml, null);
assertEquals(1, getWarnings().size());
}
......@@ -111,7 +111,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
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));
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml), null);
assertNotNull(set);
MiriamData md1 = set.iterator().next();
assertNotEquals(md.getRelationType(), md1.getRelationType());
......
This diff is collapsed.
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