Commit 045ff5d7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

import/export of StructuralStat from sbgml uses new data structure

parent c6c59b8b
......@@ -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);
......
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
......
......@@ -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()));
}
}
......@@ -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");
}
}
......@@ -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);
}
}
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