From 045ff5d7db61b4a340f06b44eef2b58127415b98 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 23 Oct 2019 10:29:57 +0200 Subject: [PATCH] import/export of StructuralStat from sbgml uses new data structure --- .../model/sbgnml/SbgnmlXmlExporter.java | 35 ++++--- .../model/sbgnml/SbgnmlXmlParser.java | 27 +++++- .../model/sbgnml/CellDesignerToSbgnTest.java | 5 +- .../model/sbgnml/DbSerializationTest.java | 92 ++++++++----------- .../model/sbgnml/SbgnmlXmlExporterTest.java | 23 +++-- .../insulin-like_growth_factor_signaling.sbgn | 0 .../mapk_cascade.sbgn | 0 .../neuronal_muscle_signalling.sbgn | 0 .../neuronal_muscle_signalling_color.sbgn | 0 .../states.sbgn | 0 .../submap.sbgn | 0 .../theWeirdOne.sbgn | 0 .../unitOfInformation.sbgn | 0 13 files changed, 97 insertions(+), 85 deletions(-) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/insulin-like_growth_factor_signaling.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/mapk_cascade.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/neuronal_muscle_signalling.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/neuronal_muscle_signalling_color.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/states.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/submap.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/theWeirdOne.sbgn (100%) rename converter-SBGNML/testFiles/{sbgnmlParserTestFiles/sbgnmlFiles => sbgnmlCellDesignerInompatible}/unitOfInformation.sbgn (100%) diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java index c3cc9949f4..eb61780079 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java @@ -10,8 +10,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.sbgn.*; import org.sbgn.bindings.*; -import org.sbgn.bindings.Map; import org.sbgn.bindings.Arc.*; +import org.sbgn.bindings.Map; import lcsb.mapviewer.common.comparator.DoubleComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; @@ -24,8 +24,7 @@ import lcsb.mapviewer.model.map.modifier.*; import lcsb.mapviewer.model.map.reaction.*; import lcsb.mapviewer.model.map.reaction.type.*; import lcsb.mapviewer.model.map.species.*; -import lcsb.mapviewer.model.map.species.field.AbstractSiteModification; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.*; import lcsb.mapviewer.modelutils.map.ElementUtils; /** @@ -170,8 +169,8 @@ public class SbgnmlXmlExporter { stateVariableGlyph.setId(newGlyph.getId().concat("-").concat(stateVariableGlyph.getId())); newGlyph.getGlyph().add(stateVariableGlyph); } - if (protein.getStructuralState() != null && !protein.getStructuralState().isEmpty()) { - newGlyph.getGlyph().add(createStateVariableForStructuralState(protein, protein.getStructuralState())); + if (protein.getStructuralState() != null && !protein.getStructuralState().getValue().isEmpty()) { + newGlyph.getGlyph().add(createStateVariableForStructuralState(protein.getStructuralState())); } } @@ -186,8 +185,8 @@ public class SbgnmlXmlExporter { Glyph childGlyph = elementToGlyph(child); newGlyph.getGlyph().add(childGlyph); } - if (complex.getStructuralState() != null && !complex.getStructuralState().isEmpty()) { - newGlyph.getGlyph().add(createStateVariableForStructuralState(complex, complex.getStructuralState())); + if (complex.getStructuralState() != null && !complex.getStructuralState().getValue().isEmpty()) { + newGlyph.getGlyph().add(createStateVariableForStructuralState(complex.getStructuralState())); } } } @@ -196,24 +195,24 @@ public class SbgnmlXmlExporter { return newGlyph; } - private Glyph createStateVariableForStructuralState(Element element, String structuralState) { + private Glyph createStateVariableForStructuralState(StructuralState structuralState) { Glyph glyph = new Glyph(); - glyph.setId(element.getElementId() + "-state"); + glyph.setId(structuralState.getSpecies().getElementId() + "-state"); glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz()); Glyph.State state = new Glyph.State(); - state.setValue(structuralState); + state.setValue(structuralState.getValue()); glyph.setState(state); Bbox bbox = new Bbox(); - - float width = (float) (element.getWidth() - 20); - float height = 28.0f; - bbox.setH(width); - bbox.setW(height); - - bbox.setX((float) (element.getX() + 10)); - bbox.setY((float) (element.getY() - height / 2)); + + float width = structuralState.getWidth().floatValue(); + float height = structuralState.getHeight().floatValue(); + bbox.setH(height); + bbox.setW(width); + + bbox.setX((float) structuralState.getPosition().getX()); + bbox.setY((float) structuralState.getPosition().getY()); glyph.setBbox(bbox); diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java index 9423bb9f7c..fcc383be60 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java @@ -1,6 +1,6 @@ package lcsb.mapviewer.converter.model.sbgnml; -import java.awt.*; +import java.awt.Color; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.io.File; @@ -34,6 +34,7 @@ import lcsb.mapviewer.model.map.reaction.*; import lcsb.mapviewer.model.map.reaction.type.*; import lcsb.mapviewer.model.map.species.*; import lcsb.mapviewer.model.map.species.field.*; +import lcsb.mapviewer.modelutils.map.ElementUtils; /** * This class is a parser for SBGN-ML files. @@ -590,13 +591,14 @@ public class SbgnmlXmlParser { logger.warn(ex.getMessage()); } } else { - String structuralState = child.getState().getValue(); if (newSpecies instanceof Protein) { Protein protein = (Protein) newSpecies; - protein.setStructuralState(structuralState); + protein.setStructuralState(createStructuralState(child)); } else if (newSpecies instanceof Complex) { Complex complex = (Complex) newSpecies; - complex.setStructuralState(structuralState); + complex.setStructuralState(createStructuralState(child)); + } else { + logger.warn(new ElementUtils().getElementTag(newSpecies) + "State is not supported"); } } } @@ -608,6 +610,23 @@ public class SbgnmlXmlParser { } + private StructuralState createStructuralState(Glyph glyph) { + StructuralState structuralState = new StructuralState(); + + double height = new Double(glyph.getBbox().getH()); + double width = new Double(glyph.getBbox().getW()); + double x = new Double(glyph.getBbox().getX()); + double y = new Double(glyph.getBbox().getY()); + + structuralState.setFontSize(10); + structuralState.setValue(glyph.getState().getValue()); + structuralState.setHeight(height); + structuralState.setWidth(width); + structuralState.setPosition(new Point2D.Double(x, y)); + + return structuralState; + } + /** * {@link ModificationResidue} in element might have slightly off coordinates * (due to different symbol shapes). For that we need to align them to match our diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java index 54da7290fb..f040b80617 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java @@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.model.map.species.field.StructuralStateComparator; import lcsb.mapviewer.modelutils.map.ElementUtils; public class CellDesignerToSbgnTest extends SbgnmlTestFunctions { @@ -108,7 +109,9 @@ public class CellDesignerToSbgnTest extends SbgnmlTestFunctions { protein1 = model.getElementByElementId("sa2"); protein2 = model2.getElementByElementId("sa2"); - assertEquals(protein1.getStructuralState(), protein2.getStructuralState()); + StructuralStateComparator comparator = new StructuralStateComparator(); + + assertEquals(0, comparator.compare(protein1.getStructuralState(), protein2.getStructuralState())); } } diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/DbSerializationTest.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/DbSerializationTest.java index 7f6000f2a5..c2a66df954 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/DbSerializationTest.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/DbSerializationTest.java @@ -3,35 +3,61 @@ package lcsb.mapviewer.converter.model.sbgnml; import static org.junit.Assert.assertEquals; import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.*; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.transaction.annotation.Transactional; import lcsb.mapviewer.model.map.model.*; import lcsb.mapviewer.persist.DbUtils; import lcsb.mapviewer.persist.dao.map.ModelDao; -@Transactional -@ContextConfiguration(classes = SpringSBGNMLConverterTestConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(Parameterized.class) public class DbSerializationTest extends SbgnmlTestFunctions { - @Autowired - ModelDao modelDao; - @Autowired - DbUtils dbUtils; + + static ApplicationContext applicationContext; Logger logger = LogManager.getLogger(DbSerializationTest.class.getName()); - private void makeDbSerializationTest(String filePath) throws Exception { + private String fileName; + + public DbSerializationTest(String filePath) { + this.fileName = filePath; + } + + @Parameters(name = "{index} : {0}") + public static Collection<Object[]> data() throws IOException { + applicationContext = new AnnotationConfigApplicationContext( + SpringSBGNMLConverterTestConfig.class); + + Collection<Object[]> data = new ArrayList<Object[]>(); + data.add(new Object[] {"testFiles/sbgnmlParserTestFiles/sbgnmlFiles/VANTEDdiagram.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlParserTestFiles/sbgnmlFiles/activated_stat1alpha_induction_of_the_irf1_gene.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlParserTestFiles/sbgnmlFiles/adh.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlParserTestFiles/sbgnmlFiles/clone-marker.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlParserTestFiles/sbgnmlFiles/glycolysis.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlCellDesignerInompatible/insulin-like_growth_factor_signaling.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlCellDesignerInompatible/neuronal_muscle_signalling.sbgn"}); + data.add(new Object[] {"testFiles/sbgnmlParserTestFiles/sbgnmlFiles/phenotypeTest.sbgn"}); + return data; + } + + @Test + @Transactional + public void dbSerializationTest() throws Exception { + ModelDao modelDao = applicationContext.getBean(ModelDao.class); + SbgnmlXmlParser parser = new SbgnmlXmlParser(); - String fileName = "testFiles/sbgnmlParserTestFiles/sbgnmlFiles/".concat(filePath); Model model = parser.createModel(fileName, new File(fileName)); modelDao.add(model); @@ -47,6 +73,7 @@ public class DbSerializationTest extends SbgnmlTestFunctions { @Before public void setUp() throws Exception { + DbUtils dbUtils = applicationContext.getBean(DbUtils.class); // we use custom threads because in layoutservice there is commit method // called, and because of that hibernate session injected by spring // cannot @@ -58,48 +85,9 @@ public class DbSerializationTest extends SbgnmlTestFunctions { @After public void tearDown() throws Exception { + DbUtils dbUtils = applicationContext.getBean(DbUtils.class); // close session dbUtils.closeSessionForCurrentThread(); } - @Test - public void VANTEDdiagramTest() throws Exception { - makeDbSerializationTest("VANTEDdiagram.sbgn"); - } - - @Test - public void activatedStat1AlphaTest() throws Exception { - makeDbSerializationTest("activated_stat1alpha_induction_of_the_irf1_gene.sbgn"); - } - - @Test - public void adhTest() throws Exception { - makeDbSerializationTest("adh.sbgn"); - } - - @Test - public void cloneMarkerTest() throws Exception { - makeDbSerializationTest("clone-marker.sbgn"); - } - - @Test - public void glycolysisTest() throws Exception { - makeDbSerializationTest("glycolysis.sbgn"); - } - - @Test - public void insulinLikeGrowthFactorSignalingTest() throws Exception { - makeDbSerializationTest("insulin-like_growth_factor_signaling.sbgn"); - } - - @Test - public void neuronalMuscleSignallingTest() throws Exception { - makeDbSerializationTest("neuronal_muscle_signalling.sbgn"); - } - - @Test - public void phenotypeTest() throws Exception { - makeDbSerializationTest("phenotypeTest.sbgn"); - } - } diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporterTest.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporterTest.java index 6618aa6b87..e840c5e16d 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporterTest.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporterTest.java @@ -2,8 +2,7 @@ package lcsb.mapviewer.converter.model.sbgnml; import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.ArrayList; import java.util.Collection; @@ -23,10 +22,10 @@ public class SbgnmlXmlExporterTest extends SbgnmlTestFunctions { Logger logger = LogManager.getLogger(SbgnmlXmlExporterTest.class.getName()); - private String testName; + private Path filePath; - public SbgnmlXmlExporterTest(String testName) { - this.testName = testName; + public SbgnmlXmlExporterTest(Path filePath) { + this.filePath = filePath; } @Parameters(name = "{index} : {0}") @@ -34,25 +33,29 @@ public class SbgnmlXmlExporterTest extends SbgnmlTestFunctions { Collection<Object[]> data = new ArrayList<Object[]>(); Files.walk(Paths.get("testFiles/sbgnmlParserTestFiles/sbgnmlFiles")).forEach(fPath -> { if (Files.isRegularFile(fPath) && fPath.toString().endsWith(".sbgn")) { - String tName = fPath.getFileName().toString().substring(0, fPath.getFileName().toString().indexOf(".sbgn")); - data.add(new Object[] { tName }); + data.add(new Object[] { fPath}); + } + }); + Files.walk(Paths.get("testFiles/sbgnmlCellDesignerInompatible")).forEach(fPath -> { + if (Files.isRegularFile(fPath) && fPath.toString().endsWith(".sbgn")) { + data.add(new Object[] { fPath}); } }); return data; } - private void parseAndExport(String testName) throws Exception { + private void parseAndExport(Path filePath) throws Exception { Converter converter = new SbgnmlXmlConverter(); Model model = converter.createModel(new ConverterParams() - .filename("testFiles/sbgnmlParserTestFiles/sbgnmlFiles/".concat(testName).concat(".sbgn"))); + .filename(filePath.toAbsolutePath().toString())); converter.model2File(model, File.createTempFile("temp-sbgn-output", ".sbgn").getAbsolutePath()); } @Test public void test() throws Exception { - parseAndExport(testName); + parseAndExport(filePath); } } diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/insulin-like_growth_factor_signaling.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/insulin-like_growth_factor_signaling.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/insulin-like_growth_factor_signaling.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/insulin-like_growth_factor_signaling.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/mapk_cascade.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/mapk_cascade.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/mapk_cascade.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/mapk_cascade.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/neuronal_muscle_signalling.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/neuronal_muscle_signalling.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/neuronal_muscle_signalling.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/neuronal_muscle_signalling.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/neuronal_muscle_signalling_color.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/neuronal_muscle_signalling_color.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/neuronal_muscle_signalling_color.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/neuronal_muscle_signalling_color.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/states.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/states.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/states.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/states.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/submap.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/submap.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/submap.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/submap.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/theWeirdOne.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/theWeirdOne.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/theWeirdOne.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/theWeirdOne.sbgn diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/unitOfInformation.sbgn b/converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/unitOfInformation.sbgn similarity index 100% rename from converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/unitOfInformation.sbgn rename to converter-SBGNML/testFiles/sbgnmlCellDesignerInompatible/unitOfInformation.sbgn -- GitLab