Commit 46c8bb18 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

consumption to something that is not a port raise a warning instead of exception

parent 83b0f919
......@@ -569,39 +569,7 @@ public class SbgnmlXmlParser {
boolean processFound;
switch (ArcClazz.fromClazz(a.getClazz())) {
case CONSUMPTION:
processFound = false;
Port arcTargetPort = null;
if (a.getTarget() instanceof Port) {
arcTargetPort = (Port) a.getTarget();
} else if (a.getSource() instanceof Port) {
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model),
"Consumption is going from process");
arcTargetPort = (Port) a.getSource();
} else {
for (Process p : processes) {
if (p.getCentralPoint().equals(a.getTarget())) {
p.addReagentArc(a);
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model), "Invalid target port");
processFound = true;
break;
}
if (p.getCentralPoint().equals(a.getSource())) {
p.addProductArc(a);
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model), "Invalid source port");
processFound = true;
break;
}
}
if (!processFound) {
throw new InvalidInputDataExecption(getTag(a) + "Consumption must be connected to a Port");
}
}
for (Process p : processes) {
if (p.getCentralPoint().getPort().contains(arcTargetPort)) {
p.addReagentArc(a);
break;
}
}
parseConsumption(a, model);
break;
case PRODUCTION:
processFound = false;
......@@ -723,6 +691,43 @@ public class SbgnmlXmlParser {
}
}
private void parseConsumption(final Arc a, final Model model) throws InvalidInputDataExecption {
boolean processFound;
processFound = false;
Port arcTargetPort = null;
if (a.getTarget() instanceof Port) {
arcTargetPort = (Port) a.getTarget();
} else if (a.getSource() instanceof Port) {
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model), "Consumption is going from process");
arcTargetPort = (Port) a.getSource();
} else {
for (Process p : processes) {
if (p.getCentralPoint().equals(a.getTarget())) {
p.addReagentArc(a);
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model), "Invalid target port");
processFound = true;
break;
}
if (p.getCentralPoint().equals(a.getSource())) {
p.addProductArc(a);
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model), "Invalid source port");
processFound = true;
break;
}
}
if (!processFound) {
logger.warn(new SbgnLogMarker(ProjectLogEntryType.PARSING_ISSUE, a, model), "Consumption must be connected to a Port. Ignoring arc.");
return;
}
}
for (Process p : processes) {
if (p.getCentralPoint().getPort().contains(arcTargetPort)) {
p.addReagentArc(a);
break;
}
}
}
private String getTag(final Arc arc) {
return "[" + ArcClazz.fromClazz(arc.getClazz()) + "; " + arc.getId() + "]\t";
}
......
......@@ -13,6 +13,7 @@ import org.junit.runners.Suite.SuiteClasses;
SbgnmlXmlExporterGenericTest.class,
SbgnmlXmlExporterGeneric2Test.class,
SbgnmlXmlExporterTest.class,
SbgnmlXmlParserForGeneratedTest.class,
SbgnmlXmlParserTest.class,
SbgnmlXmlParserTest2.class,
})
......
package lcsb.mapviewer.converter.model.sbgnml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.NormalImageGenerator;
import lcsb.mapviewer.converter.graphics.PngImageGenerator;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.reaction.ReactionComparator;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.ElementComparator;
@RunWith(Parameterized.class)
public class SbgnmlXmlParserForGeneratedTest extends SbgnmlTestFunctions {
Logger logger = LogManager.getLogger();
private Path filePath;
public SbgnmlXmlParserForGeneratedTest(final Path filePath) {
this.filePath = filePath;
}
@Parameters(name = "{index} : {0}")
public static Collection<Object[]> data() throws IOException {
Collection<Object[]> data = new ArrayList<Object[]>();
Files.walk(Paths.get("testFiles/sbgnmlParserTestFiles/generated")).forEach(fPath -> {
if (Files.isRegularFile(fPath)) {
data.add(new Object[] { fPath });
}
});
return data;
}
@Test
public void createModelTest() throws Exception {
String dir = Files.createTempDirectory("sbgn-temp-images-dir").toFile().getAbsolutePath();
Converter converter = new SbgnmlXmlConverter();
Model model = converter.createModel(new ConverterParams().filename(filePath.toString()));
// Create and display image of parsed map
AbstractImageGenerator.Params params = new AbstractImageGenerator.Params().height(model.getHeight())
.width(model.getWidth()).nested(true).scale(1).level(20).x(0).y(0).model(model);
NormalImageGenerator nig = new PngImageGenerator(params);
String pngFilePath = dir + "/"
.concat(filePath.getFileName().toString().substring(0, filePath.getFileName().toString().indexOf(".sbgn")))
.concat(".png");
nig.saveToFile(pngFilePath);
CellDesignerXmlParser cellDesignerXmlParser = new CellDesignerXmlParser();
String xmlString = cellDesignerXmlParser.model2String(model);
String cellDesignerFilePath = dir + "/"
.concat(filePath.getFileName().toString().substring(0, filePath.getFileName().toString().indexOf(".sbgn")))
.concat(".xml");
PrintWriter out = new PrintWriter(cellDesignerFilePath);
out.print(xmlString);
out.close();
InputStream is = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
Model model2 = cellDesignerXmlParser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
AbstractImageGenerator.Params params2 = new AbstractImageGenerator.Params().height(model2.getHeight())
.width(model2.getWidth()).nested(true).scale(1).level(20).x(0).y(0).model(model2);
NormalImageGenerator nig2 = new PngImageGenerator(params2);
String pngFilePath2 = dir + "/"
.concat(filePath.getFileName().toString().substring(0, filePath.getFileName().toString().indexOf(".sbgn")))
.concat("_2.png");
nig2.saveToFile(pngFilePath2);
assertNotNull(model2);
ModelComparator comparator = new ModelComparator(1.0);
comparator.getReactionSetComparator().setObjectComparator(new ReactionComparator(1.0, true));
model2.setNotes(model.getNotes());
for (Element element : model.getElements()) {
element.setNameX(0);
element.setNameY(0);
element.setNameWidth(0);
element.setNameHeight(0);
element.setNameHorizontalAlign(null);
element.setNameVerticalAlign(null);
}
for (Element element : model2.getElements()) {
element.setNameX(0);
element.setNameY(0);
element.setNameWidth(0);
element.setNameHeight(0);
element.setNameHorizontalAlign(null);
element.setNameVerticalAlign(null);
}
// export to CellDesigner changes line width
comparator.setElementComparator(new ElementComparator(3));
assertEquals(0, comparator.compare(model, model2));
FileUtils.deleteDirectory(new File(dir));
}
}
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.2">
<map language="process description">
<glyph id="n59" class="macromolecule">
<label text="C4"/>
<bbox x="662.16473" y="277.00546" w="80" h="40"/>
</glyph>
<glyph id="n61" class="unspecified entity">
<label text="C4a"/>
<bbox x="662.16473" y="472.85104" w="80" h="40"/>
</glyph>
<glyph id="glyph3" orientation="vertical" class="process">
<bbox y="448.0" x="478.0" h="24.0" w="24.0"/>
<port y="436.0" x="490.0" id="glyph3.1"/>
<port y="484.0" x="490.0" id="glyph3.2"/>
</glyph>
<arc id="e28" class="consumption" source="n59" target="n61">
<start x="702.16473" y="317.50546"/>
<end x="702.16473" y="382.92825"/>
</arc>
</map>
</sbgn>
\ No newline at end of file
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