Commit 1a9e9c07 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

render information for modification residues

parent 3e11e490
......@@ -54,6 +54,7 @@ public class SbmlExporter {
return stream.toString("UTF-8")
// COPASI does not accept double coordinates
.replace(".0\"", "\"")
.replace(".0+", "+")
.replace(".0%\"", "%\"");
} catch (UnsupportedEncodingException | XMLStreamException e) {
throw new InvalidStateException(e);
......
package lcsb.mapviewer.converter.model.sbml.species;
import java.awt.Color;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.*;
import org.sbml.jsbml.ext.render.*;
import lcsb.mapviewer.converter.model.sbml.SbmlModelUtils;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.ArrowType;
import lcsb.mapviewer.model.map.species.field.*;
import lcsb.mapviewer.modelutils.map.ElementUtils;
public class ModificationResidueExporter {
/**
* Default diameter of the modification residues.
*/
public static final int DEFAULT_MODIFICATION_DIAMETER = 15;
private static Logger logger = LogManager.getLogger();
private SbmlModelUtils sbmlModelUtils;
public ModificationResidueExporter(Model sbmlModel) {
......@@ -18,20 +32,143 @@ public class ModificationResidueExporter {
}
public LocalStyle createStyle(ModificationResidue element) {
return createStyle();
if (element instanceof Residue) {
return createEllipseStyle();
} else if (element instanceof ModificationSite) {
return createModificationSiteStyle((ModificationSite) element);
} else if (element instanceof TranscriptionSite) {
return createTranscriptionSiteStyle((TranscriptionSite) element);
} else if (element instanceof RegulatoryRegion) {
return createRectangleStyle();
} else if (element instanceof BindingRegion) {
return createRectangleStyle();
} else if (element instanceof CodingRegion) {
return createRectangleStyle();
} else if (element instanceof ProteinBindingDomain) {
return createRectangleStyle();
} else {
logger.warn(new LogMarker(ProjectLogEntryType.EXPORT_ISSUE, element.getSpecies()),
"Don't know how to render modification residue: " + new ElementUtils().getElementTag(element));
return createEllipseStyle();
}
}
public LocalStyle createStyle(StructuralState structuralState) {
return createStyle();
private LocalStyle createRectangleStyle() {
LocalStyle style = createGenericStyle();
Rectangle rectangle = new Rectangle();
rectangle.setRx(new RelAbsVector(0, 0));
rectangle.setRy(new RelAbsVector(0, 0));
rectangle.setX(new RelAbsVector(0, 0));
rectangle.setY(new RelAbsVector(0, 0));
rectangle.setWidth(new RelAbsVector(0, 100));
rectangle.setHeight(new RelAbsVector(0, 100));
style.getGroup().addElement(rectangle);
return style;
}
private LocalStyle createStyle() {
LocalStyle style = sbmlModelUtils.createStyle();
ColorDefinition color = sbmlModelUtils.getColorDefinition(Color.BLACK);
ColorDefinition background = sbmlModelUtils.getColorDefinition(Color.WHITE);
private LocalStyle createTranscriptionSiteStyle(TranscriptionSite transcriptionSite) {
LocalStyle style = createGenericStyle();
ColorDefinition color;
if (transcriptionSite.getActive()) {
color = sbmlModelUtils.getColorDefinition(Color.RED);
} else {
color = sbmlModelUtils.getColorDefinition(Color.BLACK);
}
if (transcriptionSite.getSpecies() != null && transcriptionSite.getSpecies().getFillColor().equals(Color.WHITE)) {
color = sbmlModelUtils.getColorDefinition(Color.BLACK);
}
style.getGroup().setStroke(color.getId());
style.getGroup().setStrokeWidth(1.0);
style.getGroup().setFill(background.getId());
style.getGroup().setFontSize((short) 10);
style.getGroup().setEndHead(ArrowType.FULL.name());
style.getGroup().setFill(color.getId());
double y = transcriptionSite.getPosition().getY();
double x = transcriptionSite.getPosition().getX();
if (Objects.equals(transcriptionSite.getDirection(), "RIGHT")) {
x += transcriptionSite.getWidth();
}
Polygon line = new Polygon();
RenderPoint p1 = line.createRenderPoint();
p1.setX(new RelAbsVector(Math.round(x - transcriptionSite.getPosition().getX()), 50));
p1.setY(new RelAbsVector(Math.round(y - transcriptionSite.getPosition().getY()), 50));
y -= DEFAULT_MODIFICATION_DIAMETER;
RenderPoint p2 = line.createRenderPoint();
p2.setX(new RelAbsVector(Math.round(x - transcriptionSite.getPosition().getX()), 50));
p2.setY(new RelAbsVector(Math.round(y - transcriptionSite.getPosition().getY()), 50));
double delta = 0;
if (Objects.equals(transcriptionSite.getDirection(), "RIGHT")) {
x -= transcriptionSite.getWidth();
delta = 6;
} else {
x += transcriptionSite.getWidth();
delta = -6;
}
RenderPoint p3 = line.createRenderPoint();
p3.setX(new RelAbsVector(Math.round(x - transcriptionSite.getPosition().getX()), 50));
p3.setY(new RelAbsVector(Math.round(y - transcriptionSite.getPosition().getY()), 50));
RenderPoint p4 = line.createRenderPoint();
p4.setX(new RelAbsVector(Math.round(x + delta - transcriptionSite.getPosition().getX()), 50));
p4.setY(new RelAbsVector(Math.round(y - 3 - transcriptionSite.getPosition().getY()), 50));
RenderPoint p5 = line.createRenderPoint();
p5.setX(new RelAbsVector(Math.round(x + delta - transcriptionSite.getPosition().getX()), 50));
p5.setY(new RelAbsVector(Math.round(y + 3 - transcriptionSite.getPosition().getY()), 50));
RenderPoint p6 = line.createRenderPoint();
p6.setX(new RelAbsVector(Math.round(x - transcriptionSite.getPosition().getX()), 50));
p6.setY(new RelAbsVector(Math.round(y - transcriptionSite.getPosition().getY()), 50));
RenderPoint p7 = line.createRenderPoint();
p7.setX(new RelAbsVector(p2.getX()));
p7.setY(new RelAbsVector(p2.getY()));
style.getGroup().addElement(line);
return style;
}
private LocalStyle createModificationSiteStyle(ModificationSite modificationSite) {
LocalStyle style = createGenericStyle();
double diameter = DEFAULT_MODIFICATION_DIAMETER;
Ellipse ellipse = new Ellipse();
ellipse.setCx(new RelAbsVector(0, 50));
ellipse.setCy(new RelAbsVector(Math.round(-diameter), 50));
ellipse.setRx(new RelAbsVector(Math.round(diameter / 2)));
ellipse.setRy(new RelAbsVector(Math.round(diameter / 2)));
style.getGroup().addElement(ellipse);
Polygon line = new Polygon();
RenderPoint p1 = line.createRenderPoint();
p1.setX(new RelAbsVector(0, 50));
p1.setY(new RelAbsVector(Math.round(-diameter / 2), 50));
RenderPoint p2 = line.createRenderPoint();
p2.setX(new RelAbsVector(0, 50));
p2.setY(new RelAbsVector(0, 50));
style.getGroup().addElement(line);
return style;
}
public LocalStyle createStyle(StructuralState structuralState) {
return createEllipseStyle();
}
private LocalStyle createEllipseStyle() {
LocalStyle style = createGenericStyle();
Ellipse ellipse = new Ellipse();
ellipse.setCx(new RelAbsVector(0, 50));
......@@ -49,6 +186,14 @@ public class ModificationResidueExporter {
}
private LocalStyle createTextStyle() {
LocalStyle style = createGenericStyle();
style.getGroup().setVTextAnchor(VTextAnchor.MIDDLE);
style.getGroup().setTextAnchor(HTextAnchor.MIDDLE);
return style;
}
private LocalStyle createGenericStyle() {
LocalStyle style = sbmlModelUtils.createStyle();
ColorDefinition color = sbmlModelUtils.getColorDefinition(Color.BLACK);
ColorDefinition background = sbmlModelUtils.getColorDefinition(Color.WHITE);
......@@ -56,9 +201,6 @@ public class ModificationResidueExporter {
style.getGroup().setStrokeWidth(1.0);
style.getGroup().setFill(background.getId());
style.getGroup().setFontSize((short) 10);
style.getGroup().setVTextAnchor(VTextAnchor.MIDDLE);
style.getGroup().setTextAnchor(HTextAnchor.MIDDLE);
return style;
}
......@@ -67,14 +209,8 @@ public class ModificationResidueExporter {
}
public BoundingBox createBoundingBoxForModification(ModificationResidue mr) {
double width, height;
if (mr instanceof AbstractRegionModification) {
width = ((AbstractRegionModification) mr).getWidth();
height = ((AbstractRegionModification) mr).getHeight();
} else {
width = 12;
height = 12;
}
double width = getModificationWidth(mr);
double height = getModificationHeight(mr);
double x = mr.getPosition().getX() - width / 2;
double y = mr.getPosition().getY() - height / 2;
BoundingBox boundingBox = new BoundingBox();
......@@ -86,13 +222,28 @@ public class ModificationResidueExporter {
return boundingBox;
}
private double getModificationHeight(ModificationResidue mr) {
if (mr instanceof AbstractRegionModification) {
return ((AbstractRegionModification) mr).getHeight();
} else {
return 12;
}
}
private double getModificationWidth(ModificationResidue mr) {
if (mr instanceof AbstractRegionModification) {
return ((AbstractRegionModification) mr).getWidth();
} else {
return 12;
}
}
public BoundingBox createBoundingBoxForModificationText(ModificationResidue mr) {
BoundingBox result = createBoundingBoxForModification(mr);
result.getPosition().setZ(result.getPosition().getZ() + 1);
return result;
}
public BoundingBox createBoundingBoxForStructuralState(StructuralState structuralState) {
double width = structuralState.getWidth();
double height = structuralState.getHeight();
......@@ -113,6 +264,4 @@ public class ModificationResidueExporter {
return result;
}
}
......@@ -6,9 +6,9 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ModificationResidueExporterTest.class,
SbmlSpeciesExporterRenderShapeTest.class,
SbmlSpeciesExporterTest.class,
SbmlSpeciesParserTest.class })
public class AllSbmlSpeciesTests {
......
package lcsb.mapviewer.converter.model.sbml.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.awt.geom.Point2D;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.reflections.Reflections;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.LayoutModelPlugin;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderLayoutPlugin;
import lcsb.mapviewer.converter.model.sbml.SbmlTestFunctions;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
@RunWith(Parameterized.class)
public class ModificationResidueExporterTest extends SbmlTestFunctions {
Logger logger = LogManager.getLogger();
private Model sbmlModel;
ModificationResidue mr;
public ModificationResidueExporterTest(String name, ModificationResidue mr) {
this.mr = mr;
}
@Before
public void setUp() {
SBMLDocument doc = new SBMLDocument(3, 1);
sbmlModel = doc.createModel();
LayoutModelPlugin plugin = new LayoutModelPlugin(sbmlModel);
sbmlModel.addExtension("layout", plugin);
Layout layout = new Layout();
plugin.addLayout(layout);
RenderLayoutPlugin renderPlugin = new RenderLayoutPlugin(layout);
layout.addExtension("render", renderPlugin);
}
@Parameters(name = "{index} : {0}")
public static Collection<Object[]> data() throws Exception {
Protein protein = createProtein();
Collection<Object[]> data = new ArrayList<Object[]>();
Reflections reflections = new Reflections("lcsb.mapviewer.model.map");
for (Class<? extends ModificationResidue> class1 : reflections.getSubTypesOf(ModificationResidue.class)) {
if (Modifier.isAbstract(class1.getModifiers())) {
continue;
}
ModificationResidue mr = class1.getConstructor().newInstance();
mr.setPosition(new Point2D.Double(10, 20));
mr.setSpecies(protein);
data.add(new Object[] { mr.getClass().getName(), mr });
}
return data;
}
@Test
public void testCreateStyle() throws Exception {
ModificationResidueExporter mre = new ModificationResidueExporter(sbmlModel);
LocalStyle style = mre.createStyle(mr);
assertNotNull(style);
assertEquals("Problem with creating style for: " + mr.getClass(), 0, super.getWarnings().size());
}
}
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