Commit 3137d440 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1620-sbgn-import' into 'devel_16.0.x'

Resolve "sbgn import issue"

See merge request !1410
parents 366411ec d6051b50
Pipeline #51125 failed with stage
in 20 minutes and 49 seconds
......@@ -15,6 +15,8 @@ minerva (16.0.6) stable; urgency=medium
provided (#1623)
* Bug fix: export to SBML of model that contained compartment with
"default_compartment" id was crashing (#1622)
* Bug fix: import of SBGN file where TARGET PORT of modification was not
defined crashed minerva (#1620)
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 16 Dec 2021 11:00:00 +0200
......
......@@ -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
<?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="and">
<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="production" 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
<?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="macromolecule">
<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="inhibition" source="n59">
<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